2 Answers
- Newest
- Most votes
- Most comments
1
Not knowing your cloud formation is difficult, anyway the article that you linked is talking about the integration between API gateway and Lambda, it's not talking about the method that you expose from the API gateway
To give you one example, you can see there is "HttpMethod" and "IntegrationHttpMethod" HttpMethod can be any of the API gateway methods allowed, but the IntegrationHttpMethod needs to be POST
apiGatewayRootMethod:
Type: AWS::ApiGateway::Method
Properties:
AuthorizationType: NONE
HttpMethod: GET
Integration:
IntegrationHttpMethod: POST
Type: AWS_PROXY
Uri: !Sub
- arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${lambdaArn}/invocations
- lambdaArn: !GetAtt lambdaFunction.Arn
ResourceId: !GetAtt apiGateway.RootResourceId
RestApiId: !Ref apiGateway
0
Another example with AWS::ApiGatewayV2::Api
Reference: AWS::ApiGatewayV2::Api
You will have to define:
- An API
- A Stage, is a deployment of your API, you can have several per API, use Stages to deploy to your environments (Development, QA, Production)
- An Integration with your Lambda Function, you can have several of this. Remember to integrate with a Lambda Function Alias, not with the function itself, to make easier the handling of the version of the lambda function per environment. You also specify here the HTTP Method.
- A route, representing the web resource and HTTP Method you will use to expose the Lambda Function, you can have several of this
- Remember, each Lambda Function you define will require an Alias to handle the environments correctly (Development, QA, Production).
ReceiveCallbackApi:
Type: AWS::ApiGatewayV2::Api
Properties:
Name: ReceiveCallbackApi
ProtocolType: HTTP
CorsConfiguration:
AllowOrigins:
- '*'
AllowMethods:
- OPTIONS
- GET
ReceiveCallbackApiStage:
Type: AWS::ApiGatewayV2::Stage
Properties:
ApiId: !Ref ReceiveCallbackApi
AutoDeploy: true
StageName: !Ref EnvironmentPrm # This is a parameter you can define
ReceiveCallbackApiNotificationIntegration:
Type: AWS::ApiGatewayV2::Integration
DependsOn:
- YourLambdaFunctionAlias # You have to define an Alias for the Lambda Function
Properties:
ApiId: !Ref ReceiveCallbackApi
IntegrationType: AWS_PROXY
IntegrationUri: !Join [ '', ['arn:', !Ref 'AWS::Partition', ':apigateway:', !Ref 'AWS::Region', ':lambda:path/2015-03-31/functions/', !Join [ ':', [!GetAtt YourLambdaFunction.Arn, !Ref EnvironmentPrm]], '/invocations' ] ]
IntegrationMethod: GET
PayloadFormatVersion: '2.0'
ReceiveCallbackApiNotificationRoute:
Type: AWS::ApiGatewayV2::Route
Properties:
ApiId: !Ref ReceiveCallbackApi
RouteKey: 'GET /receive_callback'
Target: !Join [ "/", [integrations, !Ref ReceiveCallbackApiNotificationIntegration] ]
answered 4 years ago
