Trigger AWS Lambda Function Based on an Event

Trigger AWS Lambda Function Based on an Event

There are multiple use cases for the AWS Lambda function. This AWS service enables you to run custom code without having to provision or manage servers. Which is great when you have a limited number of calls or don’t want to manage the servers. The AWS lambda function allows you to add custom logic to AWS resources such as Amazon S3 buckets and Amazon DynamoDb Tables etc

Here are some use cases:

● Use case 1: Trigger Lambda function to perform specific a task when an object is uploaded to an S3 bucket. For example, when a new video is uploaded to the bucket, the Lambda function can be configured to automatically compress the video or change its orientation from portrait to landscape. This usecase we discussed in one of our earlier post https://speckyfox.com/post/building-scalable-social-media-applications-by-leveraging-aws-services

● Use case 2: Another common use case of AWS is to back up and store data securely using the Amazon Simple Storage Service (S3). For example, suppose you have a website that generates critical data such as user data, logs, and configurations. In that case, you can configure an S3 bucket to automatically back up this data periodically using the AWS Lambda function. The Lambda function can be triggered on a schedule, such as every day or every week, and can automatically back up the data to the S3 bucket. 

Steps to set up the AWS Lambda function

● Step 1: We go to AWS Console and search Lambda

● Step 2: Then we click on Create function 

● Step 3:  Then we fill in the following properties:

● Step 4: After Creating the function our screen looks like the below:

○ Screen Part 1 - we add a trigger for the s3 bucket if the lambda function is not connected with any s3 bucket. We can even connect multiple existing s3 buckets with a single lambda function. In our case, we have to create a new AWS S3 bucket.

○ Screen Part 2 - we can write the code for whatever operation we want to perform 

● Step 5: 

○ Goto search and type s3 and click on the S3