Home > Mobile >  Creating an ApiGatewayV2 HTTP API Integration with Subtype SQS-SendMessage Fails with 400
Creating an ApiGatewayV2 HTTP API Integration with Subtype SQS-SendMessage Fails with 400

Time:11-01

I'm using [email protected] to deploy my services, and I'm looking at setting up an HTTP API Proxy to an SQS Service.

I've handled this previously through this enter image description here

CodePudding user response:

Your error message doesn't match your Resource configuration. The stack from the second link actually works, so you must be creating a problem in some other way, or aren't looking at the latest error for the stack.

I just tried this stack and it 100% works:

Resources:
  ApiGateway:
    Type: AWS::ApiGatewayV2::Api
    Properties:
      ProtocolType: HTTP
      Name: sqsdemo

  Stage:
    Type: AWS::ApiGatewayV2::Stage
    Properties:
      ApiId: !Ref ApiGateway
      StageName: $default
      AutoDeploy: true

  Queue:
    Type: AWS::SQS::Queue

  Role:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: 2012-10-17
        Statement:
          - Effect: Allow
            Action: sts:AssumeRole
            Principal:
              Service: apigateway.amazonaws.com
      Policies:
        - PolicyName: sqssend
          PolicyDocument:
            Version: 2012-10-17
            Statement:
              - Effect: Allow
                Action: sqs:SendMessage
                Resource: !GetAtt Queue.Arn

  Integration:
    Type: AWS::ApiGatewayV2::Integration
    Properties:
      ApiId: !Ref ApiGateway
      CredentialsArn: !GetAtt Role.Arn
      PayloadFormatVersion: "1.0"
      IntegrationType: AWS_PROXY
      IntegrationSubtype: SQS-SendMessage
      RequestParameters:
        QueueUrl: !Ref Queue
        MessageBody: $request.body
        MessageAttributes: >-
          {
            "UserAgent": {
              "DataType": "String",
              "StringValue": "${request.header.user-agent}"
            }
          }

  Route:
    Type: AWS::ApiGatewayV2::Route
    Properties:
      ApiId: !Ref ApiGateway
      RouteKey: $default
      Target: !Sub integrations/${Integration}

Success deployment

CodePudding user response:

Found my issue!

PayloadFormatVersion should be a string.

PayloadFormatVersion: 1.0 -> PayloadFormatVersion: "1.0"
  • Related