Skip to content

CloudFormation and GET requests

0

I have a cloudformation template that does a lot of things, plus deploying an API Gateway GET route integrated with a lambda function. The result is:

(80390c37-5d4a-46cb-b7f0-e38684943499) Execution failed due to configuration error: 
2022-02-09T12:19:34.819+00:00
(80390c37-5d4a-46cb-b7f0-e38684943499) Method completed with status: 500

Then, after googling this, i stumble on this article and just cannot believe what i read:

https://aws.amazon.com/premiumsupport/knowledge-center/api-gateway-lambda-template-invoke-error/

Is this correct???????? How can i then integrate a get request with cloudformation? It does work manually

2 Answers
1
Accepted Answer

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
answered 4 years ago
EXPERT
reviewed a year ago
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

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.