AWS Fargate to Amazon SNS to Amazon SQS

AWS Fargate → SNS → SQS

Create an AWS Fargate service that sends to SNS then SQS

This project contains a sample AWS Cloud Development Kit (AWS CDK) template for deploying an AWS Fargate service running on an Amazon Elastic Container Service (ECS) cluster with an Application Load Balancer in-front. The AWS Fargate service makes publish call to an Amazon Simple Notification Service (SNS) and receiveMessage call to an Amazon Simple Queue Service (SQS) queue which is subscribed to the SNS topic that the template creates. This template uses a custom image without having to pre-push the image to Amazon Elastic Container Registry (ECR) or another container library. This makes use of the in-built ecs.ContainerImage.fromAsset method. The custom image has a base route / for health checks, /publishmessage for adding to the queue and /readmessage for reading messages from the queue. Environment variables like the SQS Queue URL, SNS Topic ARN and AWS region are passed to the image to enable it to perform actions on the SNS Topic and SQS Queue.
This project also shows how to set up an SNS and SQS Interface Endpoint to the VPC. A VPC Endpoint policy is created to only allow the Fargate task definition to perform actions through the VPC endpoint. In addition, an access policy is set on the SNS topic and SQS queue to deny requests that are not from the created Interface Endpoint.

< 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/fargate-sns-sqs-cdk

Deploy

cdk deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

1. Delete the stack: npx cdk destroy.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus".
3. You see a message confirming DELETE_COMPLETE.

Created by:

Arun Thangaraj

Arun Thangaraj

Arun is a Cloud Application Architect at AWS Professional Services based out of Dallas, TX.