How to vest API gateway resource with lambda proxy integration

I was trying to figure out how to express (in cloudformation) an API gateway resource that has a Lambda function integration type using Lambda Proxy integration.

This is easy to do in the AWS console, as there is a checkbox that you can select: API Gateway Console showing the Use Integration with Lambda Proxy checkbox

However, there is no corresponding field in the AWS :: ApiGateway :: Method CloudFormation resource (it must be in the Integration property ).

How can I set this up in cloudformation?

+7
amazon-cloudformation aws-lambda aws-api-gateway
source share
2 answers

The type of integration must be set to AWS_PROXY . The following is an example of a method fragment from the CloudMormation YAML working template.

 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, as I understand it ...

While 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. This gave me the following JSON, and I realized that the flag could be encoded into a type. I tested my assumption and came up with 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" } 
+7
source share

I solved the same problem by simply changing

 Integration: Type: AWS_PROXY 

For

 Integration: Type: AWS 

Currently, the documentation on cloud formation is not enough, and the documentation on cloud policies of the API gateway does not match what can be seen on the console, which prevents anyone who is trying to solve the problem.

Hope this helps!

+1
source share

All Articles