How do I cloudform an API gateway resource with a lambda proxy integration

后端 未结 3 952
一整个雨季
一整个雨季 2021-02-07 04:05

I\'ve been trying to work out how to express (in cloudformation) an API Gateway Resource that has a Lambda function integration type using the Lambda Proxy integration.

3条回答
  •  说谎
    说谎 (楼主)
    2021-02-07 04:23

    The Integration type should be set to AWS_PROXY. An example snippet of a method from a working YAML CloudFormation template is below.

    ProxyResourceAny:
      Type: AWS::ApiGateway::Method
      Properties:
        AuthorizationType: NONE
        HttpMethod: ANY
        ResourceId:
          Ref: ProxyResource
        RestApiId:
          Ref: API
        Integration:
          Type: AWS_PROXY
          IntegrationHttpMethod: POST
          Uri: !Sub
            - arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Arn}/invocations
            - Arn:
                Fn::GetAtt:
                - RestorerLambda
                - Arn
    

    It's worth saying how a I figured this out...

    After scratching my head for a while I examined the output of the aws apigateway get-method CLI command for a method that was configured this way using the console. That gave me the following JSON and I realised that the checkbox might be encoded into the type. I tested my assumption and came up with the CloudFormation above.

    {
        "apiKeyRequired": false,
        "httpMethod": "ANY",
        "methodIntegration": {
            "integrationResponses": {
                "200": {
                    "responseTemplates": {
                        "application/json": null
                    },
                    "statusCode": "200"
                }
            },
            "passthroughBehavior": "WHEN_NO_MATCH",
            "cacheKeyParameters": [],
            "uri": "arn:aws:apigateway:eu-west-1:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-1:XXXXXXXXX:function:Shildrew-Restorer-Play-Lambda/invocations",
            "httpMethod": "POST",
            "cacheNamespace": "64bl3tgw4g",
            "type": "AWS_PROXY"
        },
        "requestParameters": {},
        "authorizationType": "NONE"
    }
    

提交回复
热议问题