Drop a 4MB photo in. Get a 80KB WebP out. Automatically. In under a second.
Modern apps are drowning in raw images. Users upload massive smartphone photos — 3 to 8 MB each. Serving those originals to mobile users means:
- 🐢 Slow load times → higher bounce rates
- 💸 Expensive bandwidth bills at scale
- 📱 Terrible experience on 4G/5G networks
- 🔧 Developers manually compressing assets
A fully serverless, event-driven pipeline that intercepts every upload, optimizes it, and stores a mobile-ready version — with zero human involvement.
Upload JPEG/PNG → S3 Trigger → Lambda (Pillow) → Optimized WebP
4 MB → instant → resize + convert → ~80 KB
┌─────────────┐ s3:ObjectCreated ┌──────────────────┐
│ Developer │ ──── raw-uploads/ ──────▶ │ AWS Lambda │
│ / App │ │ Python 3.13 │
└─────────────┘ │ + Pillow │
└────────┬─────────┘
│
resize + convert
to WebP (quality 80)
│
▼
┌──────────────────────────┐
│ S3: optimized-delivery/ │
│ filename.webp (~80KB) │
└──────────────────────────┘
| Layer | Service | Purpose |
|---|---|---|
| Storage | Amazon S3 | Receives uploads, stores output |
| Compute | AWS Lambda | Runs image processing code |
| Trigger | S3 Event Notification | Fires Lambda on every upload |
| IaC | AWS SAM + CloudFormation | Deploys entire stack in one command |
| Permissions | AWS IAM | Least-privilege read/write access |
| Image Engine | Pillow (PIL) | Resize, convert, compress |
- 🚀 Zero infrastructure — fully serverless, scales automatically
- 🔁 Event-driven — triggers instantly on every S3 upload
- 📐 Smart resizing — max 400px width, aspect ratio preserved
- 🖼️ WebP conversion — 25–34% smaller than JPEG at same quality
- 🔒 Secure by default — private bucket, least-privilege IAM
- ♾️ Infinite loop safe — skips already-optimized files
- 📊 Observable — full CloudWatch logging on every invocation
mobile-image-optimizer/
│
├── template.yaml # SAM/CloudFormation — all AWS resources
│
├── image_processor/
│ ├── app.py # Lambda handler — core processing logic
│ └── requirements.txt # Python dependencies (Pillow)
│
└── Serverless_Image_Optimization_Pipeline.pdf # Full technical documentation
- AWS CLI configured (
aws configure) - AWS SAM CLI
- Python 3.13
sam build
sam deploy --guidedThat's it. SAM provisions the S3 bucket, Lambda function, IAM roles, and event wiring automatically.
# Upload any image to the raw-uploads/ prefix
aws s3 cp your-photo.jpg s3://<your-bucket>/raw-uploads/your-photo.jpg
# Watch the Lambda logs live
aws logs tail /aws/lambda/sam-app-image-optimizer --followCheck your S3 bucket for the optimized-delivery/ folder — your .webp file will be there within seconds.
| Metric | Before | After |
|---|---|---|
| File Size | ~4,000 KB | ~80 KB |
| Format | JPEG / PNG | WebP |
| Width | Full resolution | Max 400px |
| Processing Time | — | < 1 second |
| Human Effort | Manual | Zero |
- CloudFront CDN for global edge delivery
- Generate multiple sizes (thumbnail / mobile / desktop)
- SQS Dead-Letter Queue for failed retries
- SNS notifications on completion
- EXIF metadata extraction to DynamoDB
Nearly free for most workloads.
- Lambda — first 1M requests/month are free
- S3 — ~$0.023/GB/month storage
- Example: 100,000 images/month ≈ under $0.25
A full technical PDF is included in this repo covering architecture, IAM design, data flow, test results, and real-world use cases.
👉 Serverless_Image_Optimization_Pipeline.pdf
Built with ❤️ using AWS SAM · Lambda · S3 · Python · Pillow