Updated: Apr 7, 2022
Event-driven architecture using AWS Lambda & Amazon S3.
1. Learn to create Lambda using AWS Management Console.
2. Learn to implement event-driven architecture using S3 as event source to invoke Lambda function
Step 1: In Lambda service console, go to Function in the left navigation panel.
Click on Create Function.
Select Author from Scratch to create a Function.
Function Name: create-thumbnail
Runtime: Python 3.7
Expand Change default execution role.
Execution Role: Create a new role with basic Lambda permissions.
Click Create Function.
Click on Configuration. In the left side panel, Click on Permissions.
Click on the role name which appears.
This will redirect you to IAM console.
Click on Attach policies.
Select Policy Name: AmazonS3FullAccess and Click Attach policy.
Step 2: Click on the following https://s3-us-west-2.amazonaws.com/us-west-2-aws-training/awsu-spl/spl-88/2.3.15.prod/scripts/CreateThumbnail.zip
This will download the CreateThumbnail.zip file on your local machine
Go back to Lambda console.
Click on Code and at the right corner upload from .zip file
Select CreateThumbnail file and Click Save.
Click on Code.
In Runtime settings Click on Edit.
The zip file we have downloaded has a python program with the name CreateThumbnail.py.
This code has a function called handler.
Thus the handler name is CreateThumbnail.handler
Step 3: Open the new AWS tab and go to S3 console.
Create two buckets in the same region as of Lambda Function i.e. Sydney here.
Create first bucket.
Click on Create bucket.
Bucket name: mybucket4533
AWS region should be same.
Public Access should be blocked.
Click Create bucket.
Similarly, follow the same above step for creating a second bucket
Bucket Name: Paste the name of the previous bucket you have created and append -resized at the end of the name i.e. (mybucket4533-resized)
Now you have the buckets named as
Step 4: Go to Lambda Function.
Click Add Trigger.
Select S3 Trigger.
Select Bucket: mybucket4533
Click on I Acknowledge and click Add.
Step 5: Go to S3 console.
Go to Source bucket and upload any image file with no space in the file name.
Size of the file here is 73.4 KB.
Now Go to Resized bucket and check the resized image.
So the size of newly resized file is 2 KB.
NOTE: Empty S3 buckets and delete buckets. Delete Lambda function.
Was this document helpful? How can we make this document better? Please provide your insights. You can download PDF version for reference.
We provide best AWS trainings from Pune, India.
For aws certification contact us now.