通过http请求从api网关导出swagger api定义?

时间:2016-06-16 09:41:57

标签: swagger aws-api-gateway

我正在尝试使用AWS的文档之后使用以下http请求从api网关导出api定义。知道为什么它不起作用吗?

curl -i -X GET -H "Accept: application/json" "https://apigateway.ap-northeast-1.amazonaws.com/restapis/<api-id>/stages/<stage-name>/exports/swagger"

错误: HTTP/1.1 403 Forbidden {"message":"Missing Authentication Token"}

1 个答案:

答案 0 :(得分:4)

我建议您使用aws cli来导出swagger(http://docs.aws.amazon.com/cli/latest/reference/apigateway/get-export.html)。

如果要使用curl命令导出swagger,则需要使用SigV4(http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html?shortFooter=true)对请求进行签名。我可以使用以下命令成功导出一个招摇

curl -X GET -H "Accept: application/json" -H "Host: apigateway.us-east-1.amazonaws.com" -H "Authorization: AWS4-HMAC-SHA256 Credential=<ACCESS_ID>/20160616/us-east-1/apigateway/aws4_request, SignedHeaders=accept;content-type;host;x-amz-date, Signature=<SIG_V4_SIGNATURE>" -H "Content-Type: application/x-www-form-urlencoded" -H "X-Amz-Date: 20160616T173231Z" -H "Cache-Control: no-cache" "https://apigateway.us-east-1.amazonaws.com/restapis/<REST_API_ID>/stages/<STAGE_NAME>/exports/swagger"