Skip to content

not-shivansh/Serverless-Image-Resizer-Cloud-Computing-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ–ผ๏ธ Serverless Image Resizer

A production-grade cloud-based image resizing system built with AWS serverless architecture. Upload images and instantly generate optimized variants at multiple sizes and formats.


โœจ Features

Core

  • Image upload with drag-and-drop or file picker
  • AI Image Detection โ€” Automatically analyzes EXIF metadata and structural signatures to determine if an uploaded image is AI-generated (e.g., Midjourney, DALL-E) and flags it in the UI with a confidence score.
  • Automatic resizing into preset sizes:
    • ๐Ÿ”น Thumbnail: 100ร—100
    • ๐Ÿ”น Medium: 300ร—300
    • ๐Ÿ”น Large: 800ร—800
  • Format conversion (JPEG, PNG, WebP) with compression optimization
  • Dynamic resizing via API โ€” custom width, height, and format

Production

  • Pre-signed S3 upload URLs for secure direct-to-S3 uploads
  • CloudFront CDN delivery for fast global access
  • S3 event-driven processing via AWS Lambda
  • Dual-mode architecture โ€” works locally and on AWS with a single env toggle
  • Upload progress tracking with visual progress bar
  • Image history with recent uploads gallery
  • Image history with recent uploads gallery (optimized thumbnails)
  • Copy-to-clipboard for all variant URLs
  • Structured logging and request metadata (ID, timing)

๐Ÿ—๏ธ Architecture

                                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  Browser / Client โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ   โ”‚  API Gateway  โ”‚
          โ”‚                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
          โ”‚                             โ”‚
          โ”‚  (pre-signed URL)           โ–ผ
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บ   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                 โ”‚    S3 Input   โ”‚
                                 โ”‚    Bucket     โ”‚
                                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                        โ”‚ (S3 event trigger)
                                        โ–ผ
                                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                 โ”‚   Lambda      โ”‚
                                 โ”‚   (Pillow)    โ”‚
                                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                        โ”‚
                                        โ–ผ
                                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                 โ”‚  S3 Output    โ”‚
                                 โ”‚  Bucket       โ”‚
                                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                        โ”‚
                                        โ–ผ
                                 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                 โ”‚  CloudFront   โ”‚
                                 โ”‚  CDN          โ”‚
                                 โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

AWS Services Used

Service Purpose
Amazon S3 Image storage (input + output buckets)
AWS Lambda Event-driven image processing
API Gateway REST API with validation and throttling
CloudFront CDN for fast global image delivery
CloudWatch Monitoring, logging, and alerting

๐Ÿ“ Project Structure

โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ app/
โ”‚   โ”‚   โ”œโ”€โ”€ main.py              # FastAPI application with all endpoints
โ”‚   โ”‚   โ”œโ”€โ”€ config.py            # Configuration with dual-mode (local/S3)
โ”‚   โ”‚   โ”œโ”€โ”€ schemas.py           # Pydantic request/response models
โ”‚   โ”‚   โ”œโ”€โ”€ lambda_handler.py    # AWS Lambda S3 event handler
โ”‚   โ”‚   โ””โ”€โ”€ services/
โ”‚   โ”‚       โ”œโ”€โ”€ image_service.py  # Core image processing
โ”‚   โ”‚       โ”œโ”€โ”€ s3_service.py     # S3 operations wrapper
โ”‚   โ”‚       โ””โ”€โ”€ metadata_service.py # JSON metadata persistence
โ”‚   โ”œโ”€โ”€ requirements.txt
โ”‚   โ”œโ”€โ”€ lambda_requirements.txt
โ”‚   โ”œโ”€โ”€ .env                     # Environment configuration (ignored in VCS)
โ”‚   โ””โ”€โ”€ .env.example             # Template (safe for VCS)
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ App.jsx              # React UI with glassmorphism theme
โ”‚   โ”‚   โ”œโ”€โ”€ api.js               # API client with progress tracking
โ”‚   โ”‚   โ”œโ”€โ”€ styles.css           # Dark glassmorphism design system
โ”‚   โ”‚   โ””โ”€โ”€ main.jsx             # Entry point
โ”‚   โ”œโ”€โ”€ index.html
โ”‚   โ””โ”€โ”€ package.json
โ”œโ”€โ”€ deploy/
โ”‚   โ”œโ”€โ”€ aws-setup.md             # Step-by-step AWS deployment guide
โ”‚   โ””โ”€โ”€ iam-policy.json          # Least-privilege Lambda IAM policy
โ””โ”€โ”€ README.md

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • (Optional) AWS CLI configured with credentials

Backend

cd backend
python -m venv .venv
.venv\Scripts\activate        # Windows
# source .venv/bin/activate   # macOS/Linux
pip install -r requirements.txt
uvicorn app.main:app --reload

API runs at http://127.0.0.1:8000 โ€” Docs at /docs

Frontend

cd frontend
npm install
npm run dev

Frontend runs at http://localhost:5173


โš™๏ธ Configuration

All settings use the IMAGE_RESIZER_ prefix and load from backend/.env:

# Storage mode: "local" (development) or "s3" (production)
IMAGE_RESIZER_STORAGE_BACKEND=local

# AWS
IMAGE_RESIZER_AWS_REGION=ap-south-1
IMAGE_RESIZER_AWS_ACCESS_KEY_ID=your-key
IMAGE_RESIZER_AWS_SECRET_ACCESS_KEY=your-secret

# S3 Buckets
IMAGE_RESIZER_S3_INPUT_BUCKET=serverless-image-resizer-buckets-input
IMAGE_RESIZER_S3_OUTPUT_BUCKET=serverless-image-resizer-buckets-output

# CloudFront
IMAGE_RESIZER_CLOUDFRONT_DOMAIN=d1234abcdef.cloudfront.net

Switch from local to AWS by changing IMAGE_RESIZER_STORAGE_BACKEND=s3.


๐ŸŒ API Endpoints

Method Endpoint Description
GET /health Health check with version and storage backend
POST /upload Upload image, run AI detection, and generate preset variants
GET /image/{image_id} Fetch image metadata by ID
GET /images?limit=20&offset=0 List recent images with pagination
GET /resize?image_id=...&width=...&height=...&format=... Create custom-sized variant
GET /presign?filename=...&content_type=... Get pre-signed S3 upload URL
POST /confirm-upload Confirm S3 upload and trigger processing

โ˜๏ธ AWS Deployment

See deploy/aws-setup.md for the complete step-by-step guide with AWS CLI commands to set up:

  1. S3 input/output buckets with CORS
  2. Lambda function with IAM role
  3. S3 โ†’ Lambda event trigger
  4. API Gateway REST API
  5. CloudFront CDN distribution
  6. CloudWatch monitoring alarms

๐Ÿ”’ Security

  • IAM roles with least-privilege access (policy)
  • File type validation โ€” only JPG, PNG, WebP allowed
  • Max file size limit โ€” 5 MB
  • Pre-signed upload URLs โ€” expire after 5 minutes
  • CORS configured for known origins
  • Request IDs and timing headers on all responses

๐Ÿ“Š Monitoring

  • CloudWatch Logs โ€” structured Lambda execution logs
  • CloudWatch Alarms โ€” error rate and latency alerts
  • Request metadata โ€” every response includes X-Request-Id and X-Process-Time-Ms headers

๐Ÿ Success Metrics

Metric Target
Processing time < 2 seconds per image
CDN latency < 200 ms
Error rate < 1%
Availability 99.9%

๐Ÿ”ฎ Future Enhancements

  • AI-based auto-cropping and face detection
  • Watermarking
  • Batch processing
  • Dashboard analytics
  • DynamoDB metadata storage

๐Ÿ’ผ Author

Shivansh Thakur Aditya Manhas

About

Serverless image processing system using AWS (S3, Lambda, CloudFront) that supports dynamic resizing, format conversion, and CDN delivery with pre-signed uploads and event-driven architecture.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors