0
0
AWScloud~30 mins

Event triggers for Lambda in AWS - Mini Project: Build & Apply

Choose your learning style9 modes available
Event triggers for Lambda
📖 Scenario: You are setting up a simple AWS Lambda function that runs automatically when a new file is uploaded to an S3 bucket. This helps automate tasks like image processing or data analysis without manual intervention.
🎯 Goal: Create an AWS Lambda function and configure an S3 bucket event trigger so the Lambda runs whenever a new object is created in the bucket.
📋 What You'll Learn
Create an AWS Lambda function named ProcessNewFile
Create an S3 bucket named my-upload-bucket
Configure the S3 bucket to trigger the Lambda function on ObjectCreated events
Use AWS CloudFormation YAML syntax for the infrastructure as code
💡 Why This Matters
🌍 Real World
Automating workflows by running code automatically when files are uploaded to cloud storage is common in data processing, image handling, and backups.
💼 Career
Understanding how to connect AWS Lambda with event sources like S3 is essential for cloud engineers and developers building serverless applications.
Progress0 / 4 steps
1
Create the AWS Lambda function resource
Write a CloudFormation resource named ProcessNewFile of type AWS::Lambda::Function with the following properties: FunctionName set to ProcessNewFile, Runtime set to python3.12, Handler set to index.handler, and Role set to arn:aws:iam::123456789012:role/lambda-execution-role.
AWS
Need a hint?

Define the Lambda function resource with the exact properties given.

2
Create the S3 bucket resource
Add a CloudFormation resource named MyUploadBucket of type AWS::S3::Bucket with the BucketName set to my-upload-bucket.
AWS
Need a hint?

Define the S3 bucket resource with the exact bucket name.

3
Add permission for S3 to invoke Lambda
Add a CloudFormation resource named LambdaInvokePermission of type AWS::Lambda::Permission with these properties: FunctionName set to !Ref ProcessNewFile, Action set to lambda:InvokeFunction, Principal set to s3.amazonaws.com, and SourceArn set to !GetAtt MyUploadBucket.Arn.
AWS
Need a hint?

Grant S3 permission to invoke the Lambda function using the exact properties.

4
Configure S3 bucket notification to trigger Lambda
Add a NotificationConfiguration property to the MyUploadBucket resource. Inside it, add a LambdaConfigurations list with one item that has Event set to s3:ObjectCreated:* and Function set to !GetAtt ProcessNewFile.Arn.
AWS
Need a hint?

Add the notification configuration exactly as described to trigger Lambda on new S3 objects.