Easiest Way to use an Amazon S3 trigger to invoke a Lambda function – 2024

Hey guys, in today’s blog we will see how we can use an AWS S3 trigger to invoke a Lambda function. So without any further due, let’s dive into it…

Step 1 – Create an Amazon S3 Bucket.

  • Open your AWS Console and search for S3.
  • When you open S3, click on Create Bucket.
Amazon S3 trigger to invoke a Lambda function
  • In the next step, simply name your S3 bucket, scroll down and click on Create Bucket. Keep everything else on default.
  • As you can see below I named my S3 bucket demo-bucket-v3.
Amazon S3 trigger to invoke a Lambda function

Step 2 – Create a Lambda function.

  • Open your AWS Console and search for Lambda.
  • When you open Lambda, click on Create Function.
  • In the next step, name your Lambda, and choose a runtime (I selected Python 3.9).
  • Scroll down and click on Create function.
Amazon S3 trigger to invoke a Lambda function

Step 3 – Adding Amazon S3 trigger to invoke a Lambda function.

  • When you have successfully created a Lambda function, you will see a screen like this.
Amazon S3 trigger to invoke a Lambda function
  • Click on Add trigger.
  • On the next screen search for S3, and select the bucket you created in Step 1.
Amazon S3 trigger to invoke a Lambda function
  • Keep everything else on default, scroll down and click on Add.
Amazon S3 trigger to invoke a Lambda function

Step 4 – Give appropriate permissions to Lambda IAM Role.

Although this process is not mandatory but to be on the safer side, do this step.

  • On your Lambda page click on Configuration and then go to Permissions.
  • Then click on the Role name.
  • In my case it’s test-lambda-role-9etv0r1m.
Amazon S3 trigger to invoke a Lambda function
  • Click on Add Policies, and Attach Policies.
Amazon S3 trigger to invoke a Lambda function
  • On the next screen search for these 3 policies and attach them.
Amazon S3 trigger to invoke a Lambda function

Step 5 – Testing our Trigger.

  • Simply upload some files to your bucket.
  • Then open your Lambda function’s Cloudwatch logs (Monitor -> View Logs in Cloudwatch) and see if logs are created.
Amazon S3 trigger to invoke a Lambda function
  • And here’s my log file.
image 13
  • And when I open it I see my logs.
  • As I had uploaded 3 images to my bucket, I can see 3 runtimes.
Amazon S3 trigger to invoke a Lambda function

And this is how you use Amazon S3 trigger to invoke a Lambda function

Do let me know if there’s any query using the Amazon S3 trigger to invoke a Lambda function by contacting me via email or LinkedIn.

So this is all for this blog folks, thanks for reading it and I hope you are taking something with you after reading this and till the next time ?…

Read my previous post: How to Deploy a Lambda function as a Component on an Edge Machine using AWS Greengrass v2

Check out my other machine learning projectsdeep learning projectscomputer vision projectsNLP projectsFlask projects at machinelearningprojects.net

Leave a Reply

Your email address will not be published. Required fields are marked *