Trigger AWS lambda function with s3 update !

Shekhar Khandelwal
3 min readJan 16, 2022

AWS Lambda functions can be triggered through s3 updates. For instance, you can trigger the lambda function with every upload of a file on a specified s3 bucket.

Create a lambda function using this tutorial — Build your first AWS Lambda function and attach an endpoint using AWS Api-gateway ! | by Shekhar Khandelwal | Jan, 2022 | Medium

Create a s3 bucket using this tutorial — Read and write to/from s3 using python — boto3 and pandas (s3fs)! | by Shekhar Khandelwal | Jan, 2022 | Medium

Let’s create a trigger in lambda function to get invoked with s3 update. Click on “Add trigger”.

Select s3.

There are many ways s3 updates can trigger lambda functions. For this demonstration, lets select PUT. That means with every PUT request on the specified bucket in s3, a trigger will be generated in lambda.

We can also provide prefix and suffix to the file/file extension to ensure right triggers are generated, since s3 buckets may have many transactions happening from various applications. But to limit the triggers, such triggering rules can be implemented.

Click on Add.

A new trigger has been created for the lambda function. Now, lets test the functionality, lets upload a file on s3 bucket.

But before that, lets check the last invocation of the lambda function, to validate s3 update has indeed invoked the lambda function.

Now, lets send aput request on s3.

Check the file upload on s3.

And check the recent invocations of the lambda function.

Bingo ! A new invocation entry can be observed in the list.

Happy Learning !

--

--

Shekhar Khandelwal

Data Scientist with a majors in Computer Vision. Love to blog and share the knowledge with the data community.