0
0
AWScloud~30 mins

CloudWatch Events (EventBridge) in AWS - Mini Project: Build & Apply

Choose your learning style9 modes available
Create a CloudWatch EventBridge Rule to Trigger a Lambda Function
📖 Scenario: You are working as a cloud engineer for a company. They want to automatically run a Lambda function every day at 6 AM UTC to perform daily cleanup tasks.You will create an EventBridge rule that triggers the Lambda function on schedule.
🎯 Goal: Build an EventBridge rule with a cron schedule expression that triggers a Lambda function named DailyCleanupFunction every day at 6 AM UTC.
📋 What You'll Learn
Create an EventBridge rule named DailyCleanupRule with a cron schedule expression for 6 AM UTC daily
Set the rule's state to ENABLED
Add the Lambda function DailyCleanupFunction as the target of the rule
💡 Why This Matters
🌍 Real World
Automating tasks on a schedule is common in cloud environments. EventBridge rules help trigger Lambda functions or other services without manual intervention.
💼 Career
Cloud engineers and DevOps professionals often create scheduled events and connect them to serverless functions for automation and maintenance.
Progress0 / 4 steps
1
Create the EventBridge rule resource
Create an AWS CloudFormation resource of type AWS::Events::Rule named DailyCleanupRule with a ScheduleExpression set to cron(0 6 * * ? *) and State set to ENABLED.
AWS
Need a hint?

The cron expression cron(0 6 * * ? *) means 6 AM UTC every day.

2
Add the Lambda function target to the rule
Add a Targets property to the DailyCleanupRule resource. Set it to a list with one target object that has Arn set to !GetAtt DailyCleanupFunction.Arn and Id set to DailyCleanupTarget.
AWS
Need a hint?

The Targets property is a list of objects. Each target needs an Arn and an Id.

3
Define the Lambda function resource
Create an AWS CloudFormation resource named DailyCleanupFunction of type AWS::Lambda::Function. Set Handler to index.handler, Runtime to python3.12, and Role to arn:aws:iam::123456789012:role/lambda-execution-role. Set Code to an inline zip with a single file index.py containing a simple handler function.
AWS
Need a hint?

The Lambda function needs a role ARN for execution permissions.

4
Add permission for EventBridge to invoke the Lambda function
Add an AWS CloudFormation resource named AllowEventBridgeInvoke of type AWS::Lambda::Permission. Set FunctionName to !Ref DailyCleanupFunction, Action to lambda:InvokeFunction, Principal to events.amazonaws.com, and SourceArn to !GetAtt DailyCleanupRule.Arn.
AWS
Need a hint?

This permission allows EventBridge to call your Lambda function.