Trigger the Lambda function using S3:

Anu Chundawat
3 min readMay 19, 2021

S3 will trigger the lambda function:

We can set trigger. So that any event happen then our that will trigger our function. For s3 if any action happen in s3 then lambda will run our function.

Follow the following Steps :

  1. Go to s3 and create a bucket in same region where lambda service is running our function.
  2. Go to properties section of bucket and scroll down then click on create event notification.
  3. give a name for event and then select for which event we want to trigger function.

4. Then select destination as lambda function and name of function and then click on save changes .

5. Then upload a object in these bucket after upload we can see that out function is automatically invoked due to trigger.

We can see it in logs.

In some code if lambda requires some permission to access S3 then we have to attach a role to lambda.

Eg.

  1. Let create a new function and upload code from given github URL:

aws_s3_lambda_json_transaction/s3_trigger_to_lambda.py at master · vimallinuxworld13/aws_s3_lambda_json_transaction (github.com).

2. Then create an event notification in s3 for above function for put event.

3. Then upload these file

https://github.com/vimallinuxworld13/aws_s3_lambda_json_transaction

4. Then go to logs we can see function runs but it is giving error because Lamda requires a permission to read S3.

So we have to attach a role for giving permission .

5. Go to permission section and click on edit of role execution option.

6. click on create a new role and then give role name and attach a policy:

6. Now, upload again that json file in s3 bucket then see the logs:

Now we can see that our lambda function is triggered.

Thank you for Reading.

--

--