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

764 Views Asked by At

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 plugin - serverless-apigateway-service-proxy. Unfortunately this sets up the proxy through a REST API. I don't need all the features from a REST API, so I'm looking at setting up a HTTP API Proxy to SQS.

I've used these resources to help me set up:

But I'm consistently getting a 400 error

Operation: SQS-SendMessage is not supported. (Service: AmazonApiGatewayV2; Status Code: 400;

Here's the snippet for the Integration.

    Integration:
      Type: AWS::ApiGatewayV2::Integration
      Properties:
        ApiId: ${param:HttpAPIRef}
        IntegrationSubtype: SQS-SendMessage
        IntegrationType: AWS_PROXY
        ConnectionType: INTERNET
        PayloadFormatVersion: 1.0
        CredentialsArn: !GetAtt HttpApiRole.Arn
        RequestParameters:
          QueueUrl: !Ref Queue
          MessageBody: random+text

I successfully created an Integration through the AWS Console and the aws cli. This is the only workaround. But it's a pain to maintain as you might see

  1. Create the integration on the Console or CLI
  2. Reference the integration id through custom parameters

A pain when referencing across different environments Any idea why I would get this error through Cloudfromation?

Also, any way I can debug this further? I'm fairly new to AWS, so I'm learning as I'm going :)

Here's a screenshot of the error on AWS Console:

enter image description here

2

There are 2 best solutions below

1
Warren Parad On

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

0
howdy_miguel On

Found my issue!

PayloadFormatVersion should be a string.

PayloadFormatVersion: 1.0 -> PayloadFormatVersion: "1.0"