π
π§ͺ HANDS-ON 2
Event-Driven Processing
(Amazon S3 β AWS Lambda)
This lab teaches you true serverless behavior: π code runs automatically when something happens.
1οΈβ£ What You Are Building (Big Picture)
You are building an automatic system where:
Whenever a file is uploaded to S3, a Lambda function runs automatically.
No API call. No button click. No server running.
π Architecture
User / Application
β (Upload file)
Amazon S3 Bucket
β (Event notification)
AWS Lambda
β
Process / Validate / Transform
2οΈβ£ Why This Lab Is VERY Important
This lab teaches:
β Event-driven architecture β Asynchronous serverless execution β Automation without APIs β Real production use cases β How AWS services talk to each other
This pattern is used everywhere in AWS.
3οΈβ£ Real-World Use Cases (Very Practical)
Youβll see this in real systems:
- Image resize after upload
- PDF validation
- Virus scanning
- Log processing
- Data ingestion pipelines
- File format conversion
4οΈβ£ Services Used & WHY
πΉ Amazon S3
- Stores files (objects)
- Triggers events automatically
πΉ AWS Lambda
- Runs code when event occurs
- No polling, no server
πΉ IAM
- Allows S3 to invoke Lambda
- Allows Lambda to read/write S3
5οΈβ£ Key Concept: Event-Driven β API-Driven
API-Driven
Client β API β Lambda
Event-Driven
Event happens β Lambda runs
No client waits for response.
π This is asynchronous processing.
6οΈβ£ Step-by-Step Flow (CRITICAL)
Letβs walk through the exact packet / event flow.
π’ Step 1: File Upload to S3
A file is uploaded:
- Via AWS Console
- CLI
- Application
- Lambda / EC2 / user
Example:
s3://my-bucket/uploads/image.jpg
π’ Step 2: S3 Event Is Generated
S3 detects:
- ObjectCreated event
Examples:
- PUT
- POST
- Multipart upload
S3 creates an event message.
π’ Step 3: S3 Triggers Lambda
S3:
- Sends event to Lambda
- Lambda is invoked asynchronously
π No retries from client π S3 β Lambda is internal AWS call
π’ Step 4: Lambda Receives Event Object
Lambda receives:
- Bucket name
- Object key (file path)
- File size
- Event type
- Timestamp
Lambda now knows:
βWhich file was uploaded, and where.β
π’ Step 5: Lambda Processes the File
Lambda may:
- Read file from S3
- Validate content
- Resize image
- Rename file
- Store output in another bucket
π’ Step 6: Lambda Finishes & Stops
- No server remains running
- No idle cost
- Execution ends
7οΈβ£ Lambda Event Object (Conceptual)
Lambda does NOT receive raw file.
It receives metadata like:
- Bucket name
- Object key
Lambda then:
- Uses AWS SDK
- Fetches file from S3 if needed
π Important exam point.
8οΈβ£ IAM Permissions (VERY IMPORTANT)
This lab teaches service-to-service IAM.
Who needs permission to do what?
πΉ S3 β Lambda
- S3 needs permission to invoke Lambda
πΉ Lambda β S3
-
Lambda needs permission to:
- Read object
- Write object
IAM Role Flow
Lambda
β assumes
IAM Role
β allows
S3 access
Without IAM: β Event fails β Lambda errors
9οΈβ£ Stateless Nature (Reinforced)
Each file upload:
- Triggers a new Lambda execution
- No memory of previous files
State (if needed) stored in:
- S3
- DynamoDB
π Scaling Behavior (Automatic & Powerful)
If:
- 1 file uploaded β 1 Lambda execution
- 1000 files uploaded β 1000 Lambda executions
AWS: β Automatically scales β No config needed
π This is why serverless is powerful.
1οΈβ£1οΈβ£ Error Handling (Important Concept)
What if Lambda fails?
- S3 does NOT retry forever
- Lambda retries automatically (limited)
- Errors go to CloudWatch Logs
Best practice:
- Use DLQ (SQS or SNS)
- Add idempotent logic
1οΈβ£2οΈβ£ Cost Model (Why This Is Cheap)
You pay for:
- S3 storage
- Lambda execution time
You do NOT pay for:
- Idle compute
- Polling services
Event-driven systems are: β Highly cost-efficient β Scalable
1οΈβ£3οΈβ£ Common Mistakes (VERY IMPORTANT)
β Expecting Lambda to get file directly β Forgetting IAM permission β Processing very large files (> memory) β Infinite loops (Lambda writes back to same bucket)
π Avoid triggering Lambda from the same bucket path it writes to.
1οΈβ£4οΈβ£ AWS Exam Points (MUST REMEMBER)
- S3 can trigger Lambda
- Event-driven architecture
- Asynchronous invocation
- Lambda receives metadata, not file
- IAM role required
- Auto scaling built-in
1οΈβ£5οΈβ£ Mental Model (REMEMBER FOREVER)
S3 = Event source
Lambda = Worker
Whenever S3 says:
βSomething happenedβ
Lambda replies:
βIβll handle it.β
1οΈβ£6οΈβ£ Why This Lab Is Essential
This lab teaches: β Automation β Event-driven thinking β Real cloud workflows β No API required
Many AWS systems are built like this.