Amazon S3 to Amazon SQS to AWS Lambda

Amazon S3 → SQS → AWS Lambda

Create a Lambda function that resizes images uploaded to S3 via SQS.

The SAM template deploys a Lambda function, an SQS queue, 2 S3 buckets and the IAM resources required to run the application.
An SQS queue consumes ObjectCreated events from an Amazon S3 bucket if the file has .jpg extension. The SQS triggers a Lambda function.
The Lambda code checks the uploaded file is an image and creates a thumbnail version of the image in another bucket.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Launch Stack

Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/s3-sqs-lambda

Deploy

npm --prefix ./src install ./srcsam buildsam deploy --guided


Testing

1. Run the following S3 CLI command to upload an image to the S3 bucket. Note, you must edit the {SourceBucketName} placeholder with the name of the source S3 Bucket. This is provided in the stack outputs.
aws s3 cp './events/exampleImage.png' s3://{SourceBucketName}
2. Run the following command to check that a new version of the image has been created in the destination bucket.
aws s3 ls s3://{DestinationBucketName}

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:

Ahmed Mohamed

Ahmed Mohamed

I am a Principal Software Engineer, Solutions Architect and Serverless Enthusiast. I spend my time learning new stuff and building large scale clinical solutions in the cloud.