I looked though the documentation but didn't find a way to do this. I have a API Gateway method that has a Body Mapping Template, as in the picture attached.
How do I map this template in CloudFormation? (I'm using JSON). I added "PassthroughBehavior": "WHEN_NO_TEMPLATES", but haven't found a way to add the Content-Type mapping.
Thank you.
You can do something like this:
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
You can do this as part of the RequestTemplates
property described here.
It should look something like this:
"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"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With