Amazon S3 to Amazon SNS to Amazon SQS to AWS Lambda

Amazon S3 → Amazon SNS → Amazon SQS → AWS Lambda

Sends notifications from S3 to SNS to SQS to Lambda when an object is created.

This SAM template creates one S3 bucket, one SNS topic, one SQS queue and one Lambda function.
The SAM template contains all the information to deploy AWS resources(one S3 bucket, one SQS queue and one Lambda function) and also the permission required by these service to communicate.
You will be able to create and delete the CloudFormation stack using the CLI commands.
The S3 will send notifications to an SNS topic whenever an .png object is deleted. SNS has two subscribers, one SQS queue and one Lambda function. The Lambda function will be triggered whenever a new file is deleted in the S3 bucket. The SQS will also receive the deleted object event from the SNS topic.
This is fully functional example implemented in Java 11.

< 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/s3-sns-sqs-lambda-sam-java

Deploy

sam deploy --guided --capabilities CAPABILITY_IAM


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

1. Delete the stack: sam delete --stack-name STACK_NAME.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"

Created by:

Razvan Minciuna

Razvan Minciuna

Software Architect.

Follow on LinkedIn