2
votes

I am trying to integrate an API Gateway WebSocket Route with SQS.

I have configured the SQS Integration with below properties

AWS Region: ap-southeast-1 AWS Service: SQS HTTP Method : POST Path override: 111111110111/my-queue

Configured Request Template as

"Action=SendMessage&MessageBody=$util.urlEncode($input.body)##

set($context.requestOverride.header.Content-Type="application/x-www-form-urlencoded")##"

When I try to send the data to SQS it is failing with below error

Error:

(VK1mEHZSyQ0FlZg=) Endpoint request body after transformations: Action=SendMessage&MessageBody=foobar (VK1mEHZSyQ0FlZg=) Sending request to https://sqs.ap-southeast-1.amazonaws.com/111111110111/my-queue (VK1mEHZSyQ0FlZg=) Received response. Integration latency: 16 ms (VK1mEHZSyQ0FlZg=) Endpoint response body before transformations: Unable to determine service/operation name to be authorized

1
I believe you want to set the path to / and put the QueueUrl in the body mapping template, as I did in stackoverflow.com/a/49566676/1695906. - Michael - sqlbot
Tried that didn't work. With REST API it's working as expected, the issue seems to be with 'WebSocket' - Gopal
WebSocket API with SQS/SNS ( not sure whether other AWS services are supported ) is not supported at this moment of time. got a confirmation from AWS Support team. Currently, there is no way to map/add HTTP headers as part of WebSocket API Integration requests. - Gopal

1 Answers

4
votes

Almost a year late, but I figured out a way to do this. You can't do it from the console itself, but you can get it to work via the CLI.

Most of the steps are covered in this guide, but make it a WS api instead of REST api.

You'll notice that it isn't possible to specify HTTP header, nor is it possible to specify the mapping template. For some reason, this isn't available on the console. You'll have to do this via the CLI instead. Save the following as a JSON file.

{
  "PassthroughBehavior": "NEVER",
  "RequestParameters": {
    "integration.request.header.Content-Type": "'application/x-www-form-urlencoded'"
  },
  "RequestTemplates": {
    "application/json": "Action=SendMessage&MessageBody=$util.urlEncode($input.body)"
  }
}

And update the integration like so:

aws apigatewayv2 update-integration \ 
--api-id API_ID \
--integration-id INTEGRATION_ID \
--cli-input-json file://update.json

You'll see the API id on the console on the API overview, but the integration ID you'll have to find via the CLI, like so:

aws apigatewayv2 get-integrations --api-id API_ID

This results in the body itself being sent as plaintext to the SQS queue.

Note: You can forego all of this if you create the API with CloudFormation/SAM, as that enables you to set RequestParameters and RequestTemplates directly.