How to integrate API Gateway with SQS

前端 未结 2 529
抹茶落季
抹茶落季 2021-01-01 19:02

Just like in the title. I try to integrate API Gateway method with a SQS using cloud formation. What I am missing is the correct URI for the SQS. If any of you already did t

2条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 19:18

    To answer my own question. Here is how you integrate SQS as a Service Proxy in API Gateway:

    PostMethod:
        Type: "AWS::ApiGateway::Method"
        Properties:
          AuthorizationType: "NONE"
          ApiKeyRequired: "true"
          HttpMethod: "POST"
          ResourceId: !Ref "SomeResource"
          RestApiId: !Ref "RestApi"
          MethodResponses:
          - StatusCode: 200
          Integration:
            Credentials: !GetAtt "RestApiRole.Arn"
            IntegrationHttpMethod: "POST"
            IntegrationResponses:
            - StatusCode: 200
            Type: "AWS"
            Uri: !Sub "arn:aws:apigateway:${AWS::Region}:sqs:action/SendMessage"
            RequestParameters:
              integration.request.querystring.QueueUrl: !Sub "'${SomeQueue}'"
              integration.request.querystring.MessageBody: "method.request.body"
    

    I've finally found all answers to my questions in various documentation. RTFM I guess.

    EDIT:

    and here the code for RestApiRole:

    RestApiRole:
        Type: "AWS::IAM::Role"
        Properties:
          AssumeRolePolicyDocument:
            Version: "2012-10-17"
            Statement:
            - Action:
              - "sts:AssumeRole"
              Principal:
                Service:
                - "apigateway.amazonaws.com"
              Effect: "Allow"
          Policies:
          - PolicyName: "InvokeLambda"
            PolicyDocument:
              Version: "2012-10-17"
              Statement:
              - Action:
                - "lambda:InvokeFunction"
                Resource: !GetAtt "LambdaFunction.Arn"
                Effect: "Allow"
    

提交回复
热议问题