How to send a message to an SQS queue using Lambda when a file is uploaded to an S3 bucket

In this post I’ll show you how to send a message to an SQS queue when a new file is uploaded to an S3 bucket. I have an S3 bucket named ‘awsbytes’ and an SQS queue named ‘test’. I will create a lambda function to send the message.

Login to the AWS Management console and navigate to Lambda service. Choose ‘Create Function’ on the Lambda Dashboard.


On the next screen, provide a name for the function and choose the routine. I named my function as ‘send_msg’ and chose ‘Python 3.8’ for the routine. Select the option ‘Create a new role with basic Lambda permissions’ and choose ‘Create function’.


The function ‘send_msg’ is created. Now expand the ‘Designer’ option and choose ‘+ Add trigger’.


In the ‘Add trigger’ window, choose ‘S3’ and choose the bucket name that you want. Under the ‘Event type’ choose ‘All object create events’.


You may optionally add the values for Prefix and Suffix. Choose ‘Enable trigger’ and acknowledge the ‘Recursive invocation’ message and choose ‘Add’.

On the lambda function page, choose ‘Add destination’


On the ‘Add destination’ window, choose Source as ‘Asynchronous invocation’ and Condition as ‘On success’ . Select the Destination type as ‘SQS queue’ and choose the queue that you would like the send the message to. Choose ‘Save’.

You will see the lambda function with both trigger and destination as below:


To test the lambda function, I’ve uploaded 3 files to the awsbytes S3 bucket.



SQS Queue has received the 3 messages, 1 for each of the files uploaded as seen below: