api gateway invoke lambda cloudformation

1

pls how can i achieve or make api gateway method to invoke lambda cloudformation Please Share sample code Thank You.

1개 답변
5
수락된 답변

Please refer AWS Resource API Gateway Method documentation for examples.

Cloudformation template should look like somethings as below, it may require additional tweaks based on your use cace exactly:

    apiGatewayMethod:
    Type: AWS::ApiGateway::Method
    Properties:
        AuthorizationType: NONE
        HttpMethod: !Ref apiGatewayHTTPMethod
        Integration:
        IntegrationHttpMethod: POST
        Type: AWS_PROXY
        Uri: !Sub
            - arn:aws:apigateway:${AWS::Region}:lambda:path/.../functions/${lambdaArn}/invocations
            - lambdaArn: !GetAtt lambdaFunction.Arn
        ResourceId: !GetAtt apiGateway.RootResourceId
        RestApiId: !Ref apiGateway

    lambdaApiGatewayInvoke:
        Type: AWS::Lambda::Permission
        Properties:
        Action: lambda:InvokeFunction
        FunctionName: !GetAtt lambdaFunction.Arn
        Principal: apigateway.amazonaws.com
        SourceArn: !Sub arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${apiGateway}/<APIGatewayStageName>/<apiGatewayHTTPMethod>/

Hope you find this useful.

Comment here if you have additional questions, happy to help.

Abhishek

profile pictureAWS
전문가
답변함 9달 전
profile pictureAWS
전문가
iBehr
검토됨 9달 전
  • Hi Abhishek Thank You, Please i it possible to invoke the lambda aliases to different stages of the API Gateway

    devaliases - devstage testaliases - teststage

  • This AWS documentation Working with stages for HTTP APIs talks about that, though I'm not sure if that is what you are looking for.

  • Your solution is reasonable according to the documentation. The gateway API has to set up permission to execute a lambda function. In the administer panel it suggests setting up the execution role. It is convenient because I do it in most cases. But here there is a solution with permission. How does it look in an admin panel? Using AWS Lambda with Amazon API Gateway

  • Why not? SourceArn: !GetAtt DataExportMethod.Arn

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인