具有Lambda Proxy和MethodResponse标头的API网关的CloudFormation模板

问题描述 投票:3回答:1

这是一个CloudFormation难题,我想如果没有你的帮助我无法解决。我正在尝试使用CloudFormation(YAML)为REST API创建模板。 API具有Lambda代理,并且必须具有MethodResponse,如附图中所示。

MethodResponse

到目前为止,这是我的模板,在构建堆栈时会产生以下错误:

PostMethod:属性的值ResponseParameters必须是一个对象

      ApiGatewayAccount: 
        Type: "AWS::ApiGateway::Account"
        Properties: 
            CloudWatchRoleArn: "some role"
      RestApi:
          Type: "AWS::ApiGateway::RestApi"
          Properties:
            Description: "some rest api"
            EndpointConfiguration:
              Types:
                - REGIONAL
            Name: RestApi

      SomeResource:
        Type: "AWS::ApiGateway::Resource"
        Properties:
          ParentId: 
            Fn::GetAtt: 
              - "RestApi"
              - "RootResourceId"
          PathPart: part
          RestApiId: 
            Ref: "RestApi"

      SomeSubResource:
        Type: "AWS::ApiGateway::Resource"
        Properties:
          ParentId: 
            Ref: "SomeResource"
          PathPart: count
          RestApiId: 
            Ref: "RestApi"

      SomeResponseModel:
        Type: "AWS::ApiGateway::Model"
        Properties:
          ContentType: "text/html"
          Description: "Empty text/html response."
          Name: someresponse
          RestApiId: 
            !Ref RestApi
          Schema: {}

      PostMethod:
        Type: "AWS::ApiGateway::Method"
        Properties:
          HttpMethod: POST
          Integration:
            IntegrationHttpMethod: POST
            Type: AWS_PROXY
            Uri: 
              Fn::Join:
                - ""
                - - "arn:aws:apigateway:"
                  - "some-region"
                  - ":lambda:path/2015-03-31/functions/"
                  - "some-arn-of-lambda-function"
          MethodResponses:
            -
              ResponseModels:
                Key: "application/x-www.form-urlencoded"
                Value: 
                  !Ref SomeResponse
              ResponseParameters:
                  - method.response.header.Content-Length: true
                  - method.response.header.Content-Type: true
                  - method.response.header.Connection: true
              StatusCode: 200
          OperationName: SomeName
          ResourceId:
            !Ref "SomeSubResource"
          RestApiId: 
            !Ref "RestApi"
amazon-web-services amazon-cloudformation aws-api-gateway
1个回答
0
投票

根据documentation,似乎这不应该是键值对的列表,而是仅仅是一个对象,其中每个条目只是另一个键/值。

我希望以下方法有效:

ResponseParameters:
  method.response.header.Content-Length: true
  method.response.header.Content-Type: true
  method.response.header.Connection: true
© www.soinside.com 2019 - 2024. All rights reserved.