π Repo: github.com/Push/terraform-aws-labs/day18
π― Goal: Build a fully automated image pipeline β upload β process β 5 variants β zero servers, zero manual steps.
β Youβll build:
- β Upload S3 bucket (source) + Processed S3 bucket (destination)
- β Lambda function (Python + Pillow) β compress, resize, convert formats
- β S3 event trigger β auto-invoke Lambda on
s3:ObjectCreated:*- β Least-privilege IAM roles β no
S3FullAccess!- β CloudWatch logging β track cold starts, errors, durations
| Traditional EC2 | Serverless Lambda |
|---|---|
| β Servers run 24/7 β pay even when idle | β Pay per millisecond of execution |
| β Manual scaling (ASG configs, ALB rules) | β Auto-scales to 1,000+ concurrent invocations |
| β OS patching, security updates | β AWS manages OS/runtime |
| β βIt works on my Macβ β breaks in prod | β β Docker-based layer builds (Day 18βs key fix!) |
π‘ Golden Rule:
βIf your workload is event-driven and <15 mins β Lambda is your friend.β
flowchart LR
A[Upload Image<br/>to S3] -->|s3:ObjectCreated:*| B[Lambda Trigger]
B --> C[Lambda Function<br/>(Python + Pillow)]
C --> D1[Compressed JPEG<br/>(85% quality)]
C --> D2[Low-Quality JPEG<br/>(60% quality)]
C --> D3[WebP<br/>(85% quality)]
C --> D4[PNG<br/>(lossless)]
C --> D5[Thumbnail<br/>(200x200)]
D1 --> E[Processed S3 Bucket]
D2 --> E
D3 --> E
D4 --> E
D5 --> E
C --> F[CloudWatch Logs]
β Critical Flow:
User uploads photo.jpg to upload-bucket-dev
S3 emits s3:ObjectCreated:Put event
Lambda invoked with event payload:
{"Records": [{"s3": {"bucket": {"name": "upload-bucket-dev"}, "object": {"key": "photo.jpg"}}}]}
Lambda:
photo.jpg from S3processed-bucket-devLogs duration/memory to CloudWatch
/day18/)