Amazon API Gateway to Amazon SQS with message filtering

Client → Amazon API Gateway REST API → Amazon SQS Queue

An Amazon API Gateway REST API sends messages straight to an Amazon SQS queue and uses a VTL mapping template to remove part of the message body first.

An Amazon API Gateway REST API has a POST /sqs method with a direct AWS service integration to Amazon SQS SendMessage. There is no AWS Lambda function in the request path.
A VTL mapping template on the integration request removes the notNeededElement object from the message body before it reaches the queue. It also passes through optional delaySeconds and messageAttributes. Use this when other parties call your API, for example as a webhook, and you want to keep message size under the SQS limit.
The API uses no authorization, so anyone with the URL can send messages. Add IAM authorization, an API key or a Lambda authorizer before you use it for real traffic.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/apigw-sqs-msg-filtering/typescript/cdk

Deploy

npm installnpm run buildcdk deploy


Testing

See the README in the GitHub repo for detailed testing instructions.

Cleanup

cdk destroy

Created by:

André Stoll

André Stoll

André is a Solutions Architect at Amazon Web Services based in Switzerland.