π
π§ͺ HANDS-ON 4
Scheduled & Rule-Based Serverless Jobs
(Amazon EventBridge β AWS Lambda)
This lab shows how Lambda runs automatically on a schedule or event rule, without any server running.
1οΈβ£ What You Are Building (Big Picture)
You are building a serverless scheduled job.
Lambda runs automatically at a fixed time or interval.
No EC2 No cron server No background process
π Architecture
Amazon EventBridge (Rule / Schedule)
β
AWS Lambda
β
Perform Task (cleanup, report, notification)
2οΈβ£ Why This Lab Is VERY Important
This lab teaches:
β Time-based execution β Rule-based execution β Automation without servers β Cost-effective cron replacement β Real operational use cases
Almost every production system needs scheduled jobs.
3οΈβ£ Real-World Use Cases (Very Practical)
Youβll see this pattern in:
- Daily report generation
- Database cleanup
- Log archival
- Sending reminders
- Monitoring & alerts
- Cost optimization jobs
4οΈβ£ What Is Amazon EventBridge?
Amazon EventBridge is a serverless event bus service.
It:
- Receives events
- Matches them against rules
- Sends them to targets (Lambda, SQS, SNS)
5οΈβ£ Two Ways EventBridge Triggers Lambda
1οΈβ£ Scheduled Rules (Cron / Rate)
Example:
- Every day at 9 AM
- Every 5 minutes
2οΈβ£ Event-Based Rules
Example:
- EC2 state change
- S3 event
- AWS service event
π In this lab, we focus on Scheduled Rules.
6οΈβ£ Step-by-Step Flow (VERY IMPORTANT)
Letβs walk through exact execution flow.
π’ Step 1: EventBridge Schedule Triggers
EventBridge rule:
Rate(5 minutes)
or
Cron(0 9 * * ? *)
At the scheduled time:
- EventBridge creates an event
π’ Step 2: EventBridge Sends Event to Lambda
EventBridge:
- Invokes Lambda asynchronously
- No client involved
π’ Step 3: Lambda Receives Event
Lambda receives:
- Event metadata
- Schedule information
- Timestamp
Lambda does not care who triggered it.
π’ Step 4: Lambda Executes Task
Lambda performs task:
- Cleanup old data
- Generate report
- Send notification
- Call APIs
π’ Step 5: Lambda Stops
Execution finishes. No idle compute. No waiting.
7οΈβ£ Key Concept: Asynchronous Invocation
EventBridge invokes Lambda:
- Asynchronously
- With retries on failure
Client does NOT wait for response.
8οΈβ£ Cron vs Rate Expressions (Exam Important)
πΉ Rate Expression
Example:
rate(10 minutes)
- Simple
- Repeating interval
πΉ Cron Expression
Example:
cron(0 2 * * ? *)
- Complex schedules
- Specific time/date
π EventBridge cron is different from Linux cron (6 fields).
9οΈβ£ IAM Permissions (Very Important)
Who needs permission?
πΉ EventBridge
- Permission to invoke Lambda
πΉ Lambda
- Permission to access resources it uses
IAM is handled automatically in most cases, but conceptually:
- Service-to-service trust is required
π Failure Handling & Retries
If Lambda fails:
- EventBridge retries automatically
- Retries are limited
Best practice:
- Use DLQ (SQS)
- Add idempotent logic
1οΈβ£1οΈβ£ Scaling Behavior
If:
- Rule triggers once β 1 Lambda execution
- Multiple rules β multiple executions
No scaling configuration needed.
1οΈβ£2οΈβ£ Cost Model (Why This Is Cheap)
You pay for:
- Lambda execution time
- EventBridge rule (very cheap)
You do NOT pay for:
- Running cron servers
- Idle EC2
Perfect for: β Automation β Maintenance jobs
1οΈβ£3οΈβ£ EventBridge vs CloudWatch Events
π Important exam point:
- CloudWatch Events = Old name
- EventBridge = New service
They are functionally similar, but:
EventBridge is the modern, recommended service.
1οΈβ£4οΈβ£ Common Mistakes (VERY IMPORTANT)
β Thinking Lambda runs continuously β Using EC2 for cron jobs β Wrong cron expression β No DLQ for failures β Hardcoding time logic in Lambda
1οΈβ£5οΈβ£ AWS Exam Points (MUST REMEMBER)
- EventBridge triggers Lambda
- Supports cron & rate
- Serverless scheduler
- Asynchronous invocation
- Cost-effective automation
1οΈβ£6οΈβ£ Mental Model (REMEMBER FOREVER)
EventBridge = Alarm clock
Lambda = Worker
When alarm rings β Lambda wakes up.
1οΈβ£7οΈβ£ Why This Lab Matters
This lab teaches: β Automation β Time-based execution β Zero-server scheduling β Operational excellence