描述 CloudFormation 中的 AWS API 网关 Body 映射模板

Describe AWS API Gateway Body Mapping Templates in CloudFormation

我查看了文档,但没有找到执行此操作的方法。我有一个 API 网关方法,它有一个 Body 映射模板,如附图所示。

如何在 CloudFormation 中映射此模板? (我正在使用 JSON)。我添加了 "PassthroughBehavior": "WHEN_NO_TEMPLATES",但还没有找到添加 Content-Type 映射的方法。

谢谢。

您可以将此作为 RequestTemplates 属性 描述的一部分 here

它应该看起来像这样:

"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"
}
}

你可以这样做:

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