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.
- 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.
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.
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.
- Click on Add trigger.
- On the next screen search for S3, and select the bucket you created in Step 1.
- Keep everything else on default, scroll down and click on Add.
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.
- Click on Add Policies, and Attach Policies.
- On the next screen search for these 3 policies and attach them.
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.
- And here’s my log file.
- And when I open it I see my logs.
- As I had uploaded 3 images to my bucket, I can see 3 runtimes.
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 projects, deep learning projects, computer vision projects, NLP projects, Flask projects at machinelearningprojects.net