Capture S3 events using Lambda Function and send status mail using SES

Posted on by Sumit Kumar

Capture S3 Events Using Lambda Function And Send Status Mail Using SES

 

Dear Reader,

In this blog, I will tell you how to capture S3 events using Lambda function and send status mail to the required recipient using SES.

We will do it in three steps.

So let’s start……

Step:-1)

Create IAM Roles for Lambda Function so that the Lambda function can call AWS services.

create IAM roles for lamda function

select type of trusted entity

create role

Please remember Role Name(S3_Lambda), we are going to use it while creating the Lambda function.

One after creating the Role we will move to step 2 and let’s create the Lambda function.

Step:-2) Search for Lambda service and create Lambd Function.

create lamda function

 

After creating function go to Configuration Tab and write Lambda function to capture event occurs on S3 and send

mail to the required recipient.

lamda s3 event capture

s3 event capture

 

then Save the Lambda Function.

Now, we will move to step 3 and create S3 Bucket and assign event notification using the Lambda function.

Step:-3) Create S3 Bucket:-

Search for S3 Service and follow the below screenshots.

 

 

create bucket

Save S3 event

 

save event notification

then saveĀ  Event notification.

we have selected two events, Post and All object delete events, that will call Lambda function whenever we will upload files into the bucket and delete the file from the bucket.

Lambda function will send mail to the mentioned recipient.

After uploading go to Lambda function monitoring Tab and View logs in cloudWatch.

In logs, you will find success and you will get mail notification for uploading the file.

Same way if you will delete the file you will get mail notification.

Note:- If you are using a free account you must have to verify your email ID using SES

logs

 

If your mail ID is not verified you will get below error.

Email verification error on AWS

In this case, follow the below screenshots and verified your email address using SES.

need to verify your email

verifing your email ID via SES

After verifying your email ID via SES you will start receiving mail.

Hope this blog will be helpful for you.

Thank you!

 

Reference:-

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ses.html#SES.Client.send_email

Leave a Reply

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

*

*