API Gateway統合レスポンスのヘッダーのマッピングで固定値を設定

2020-11-02

CloudFormation(.yaml)で、API Gatewayの統合レスポンスのヘッダーのマッピングで固定値を指定したい場合は、次のように書くとよい。

SomeMethod:
  Type: AWS::ApiGateway::Method
  Properties:
    HttpMethod: POST
    ...
    Integration:
      Type: AWS
      IntegrationHttpMethod: POST
      ...
      IntegrationResponses:
        - StatusCode: 200
          SelectionPattern: "status:200"
          ResponseParameters:
            # OK
            method.response.header.X-STATIC-HEADER: "'1'"
            # NG
            method.response.header.X-STATIC-HEADER: 1
            # NG
            method.response.header.X-STATIC-HEADER: "1"

Reference

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apitgateway-method-integration-integrationresponse.html#cfn-apigateway-method-integration-integrationresponse-responseparameters