Jun*_*une 4 amazon-web-services aws-cloudformation aws-api-gateway
我查看了文档,但没有找到解决方法。我有一个具有主体映射模板的API网关方法,如上图所示。
如何在CloudFormation中映射此模板?(我正在使用JSON)。我添加了“ PassthroughBehavior”:“ WHEN_NO_TEMPLATES”,但是还没有找到添加Content-Type映射的方法。
谢谢。
小智 5
您可以执行以下操作:
GETMethodRequest:
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
Run Code Online (Sandbox Code Playgroud)
您可以将其作为此处RequestTemplates描述的属性的一部分来执行。
它应该看起来像这样:
"APIMethodGet": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"RequestTemplates": {
"application/json": {
"Fn::Join": [
"",
[
"{\n \"StreamName\": \"my-kinesis\"\n",
"\n \"Data\": \"$util.base64encode($input.body)\"\n",
"\n \"PartitionKey\": \"1\"\n}"
]
]
}
},
"PassthroughBehavior": "WHEN_NO_TEMPLATES"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1468 次 |
| 最近记录: |