Skip to content

Dynamic Path Integration for API Gateway and SQS

0

API Gateway <> SQS

I'm seeking help with dynamically overriding the path on API Gateway to connect to different SQS queues on demand.

If I use the URL of an existing SQS Queue, everything works fine (roles and permissions are in place), and I'm logging API Gateway activity to Cloudwatch. Here's what I've done so far:

  • Using VTL: I assigned a dynamic value to QueueUrl. Cloudwatch logs show the correct dynamic value (constructed from query strings), but the request is sent to the "path override" parameter configured on API Gateway.

  • Using VTL: I tried to override the path using $context.requestoverride object but encountered an error, unable to modify the request.

Is there a way to make this parameter dynamic? Creating an endpoint for each SQS queue (potentially thousands) isn't practical, and I want to avoid using a single SQS queue with client-side filtering.

Any suggestions?

2 Answers
2
Accepted Answer

Yes you can do it in this way.

  • Configure the Path Override parameter: While configuring the integration on Path Override, you need to define it like 12345678/{queueId} where 12345678 is your account id.
  • Define URL PATH Parameters: You need to define URL PATH Parameters. Name queueId, Mapped from method.request.path.queueId1.
  • Add HTTP headers: Expand HTTP headers and add a new Header with Name Content-Type, Mapped from 'application/x-www-form-urlencoded'.
  • Add a Mapping Template: Add a Mapping Template as Content-Type application/json and template body as Action=SendMessage&MessageBody=$input.body.

Here you can find an old post about it: https://stackoverflow.com/questions/75197213/routing-message-from-aws-api-gateway-to-sqs-regarding-url-path

EXPERT
answered a year ago
EXPERT
reviewed a year ago
EXPERT
reviewed a year ago
EXPERT
reviewed a year ago
  • Oh, it’s working now! I was starting to think it wasn’t possible. It seems the issue was using a query string instead of a path parameter.

    Thank you very much for your help!

1

Hi,

A solution is also to use EventBridge to dynamically route to different queues as a second stage.

See https://medium.com/@pubudusj/split-messages-from-single-sqs-queue-into-multiple-sqs-queues-using-eventbridge-728809342352

Best,

Didier

EXPERT
answered a year ago
EXPERT
reviewed a year ago
  • I was able to solve it directly through API Gateway, but I appreciate learning about your approach. I'll definitely keep it in mind for future endeavors. Thank you!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.