我查看了文档,但没有找到执行此操作的方法。我有一个 API 网关方法,它有一个正文映射模板,如附图所示。
如何在 CloudFormation 中映射此模板? (我使用的是 JSON)。我添加了 "PassthroughBehavior": "WHEN_NO_TEMPLATES",但尚未找到添加内容类型映射的方法。
谢谢。
最佳答案
你可以这样做:
GET方法请求:
Type: "AWS::ApiGateway::Method"
DependsOn: ePlanningLambdaPermission
Properties:
RestApiId: !Ref YourAPI
AuthorizationType: NONE
HttpMethod: GET
RequestParameters:
method.request.querystring.name: true
MethodResponses:
- StatusCode: 200
ResourceId: !Ref ePlanningGISLocalitymapResource
Integration:
Type: AWS
IntegrationHttpMethod: POST
RequestTemplates:
"application/json": "{
\"body\" : $input.json('$'),
\"headers\": {
#foreach($header in $input.params().header.keySet())
\"$header\": \"$util.escapeJavaScript($input.params().header.get($header))\" #if($foreach.hasNext),#end
#end
},
\"method\": \"$context.httpMethod\",
\"params\": {
#foreach($param in $input.params().path.keySet())
\"$param\": \"$util.escapeJavaScript($input.params().path.get($param))\" #if($foreach.hasNext),#end
#end
},
\"query\": {
#foreach($queryParam in $input.params().querystring.keySet())
\"$queryParam\": \"$util.escapeJavaScript($input.params().querystring.get($queryParam))\" #if($foreach.hasNext),#end
#end
}
}"
IntegrationResponses:
- StatusCode: 302
关于amazon-web-services - 描述 CloudFormation 中的 AWS API Gateway 正文映射模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45882203/