Skip to content

This project implements an event-driven, serverless image processing pipeline on AWS. Images uploaded to Amazon S3 are automatically resized using AWS Lambda and Pillow, stored in a destination bucket, and followed by an email notification using Amazon SNS.

Notifications You must be signed in to change notification settings

aksingh4545/image_resize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🖼️ Serverless Image Resizing with AWS Lambda, Pillow, and SNS

This project implements an event-driven, serverless image processing pipeline on AWS. Images uploaded to Amazon S3 are automatically resized using AWS Lambda and Pillow, stored in a destination bucket, and followed by an email notification using Amazon SNS.


📌 Problem Statement

Applications that accept user-uploaded images often need standardized image sizes for thumbnails, profile photos, or product listings. Handling this on traditional servers increases operational overhead and cost.

This project solves the problem using a fully serverless approach:

  • Automatic image resizing on upload
  • No servers or background workers to manage
  • Instant notification once processing is complete

🧠 High-Level Architecture

  1. User uploads an image to an S3 bucket
  2. S3 triggers an AWS Lambda function
  3. Lambda resizes the image using Pillow (via a Lambda Layer)
  4. Resized image is saved to a destination S3 bucket
  5. Lambda publishes a notification to an SNS topic

This design follows an event-driven, cloud-native architecture.


🧰 Tech Stack

  • AWS S3 – Image storage and event source
  • AWS Lambda – Serverless compute
  • Python 3.10 / 3.11 – Runtime
  • Pillow (PIL) – Image processing
  • Lambda Layer – Dependency packaging
  • AWS SNS – Email notifications

📁 S3 Buckets

Purpose Bucket Name
Input images image-resize-input45
Resized images image-resize-result45
Backup originals image-resize-backup45

❓ Why Pillow and Lambda Layers

AWS Lambda does not include Pillow by default. Since Pillow depends on native system libraries, it must be packaged separately.

A Lambda Layer is used to:

  • Package Pillow correctly for Amazon Linux
  • Keep Lambda function code clean
  • Reuse the dependency across functions

Lambda automatically mounts layers at:

/opt/python/

🛠️ Creating the Pillow Layer (AWS CloudShell)

Pillow must be built on Amazon Linux. Use AWS CloudShell:


mkdir pillow-layer
cd pillow-layer
mkdir python
pip3 install pillow==10.2.0 -t python/
zip -r pillow-layer.zip python

Upload pillow-layer.zip as a Lambda Layer and attach it to your function.


🧪 Lambda Function Overview

The Lambda function performs the following steps:

  • Reads the uploaded image from S3
  • Backs up the original image
  • Resizes the image using Pillow
  • Saves the resized image to a destination bucket
  • Sends a notification using SNS

🔍 Key Concepts Used

  • Event-driven architecture
  • Serverless compute
  • In-memory file processing
  • Native dependency packaging
  • Asynchronous notifications with SNS

⚙️ Lambda Configuration

Setting Recommended Value
Runtime Python 3.10 / 3.11
Memory 512 MB
Timeout 15 seconds

🔐 IAM Permissions

The Lambda execution role requires the following permissions:


{
  "Effect": "Allow",
  "Action": [
    "s3:GetObject",
    "s3:PutObject",
    "sns:Publish"
  ],
  "Resource": [
    "arn:aws:s3:::image-resize-input45/*",
    "arn:aws:s3:::image-resize-result45/*",
    "arn:aws:s3:::image-resize-backup45/*",
    "arn:aws:sns:ap-south-1:ACCOUNT_ID:image-resize-notification"
  ]
}

🚨 Common Issues

  • No module named PIL – Pillow layer not attached
  • _imaging import error – Layer built for wrong Python version
  • Lambda not triggered – S3 event notification missing
  • SNS publish denied – Missing sns:Publish permission

🚀 Real-World Use Cases

  • User profile photo processing
  • E-commerce product image resizing
  • CMS image optimization pipelines
  • Media processing workflows with alerts

📈 Possible Enhancements

  • Multiple output sizes
  • Preserve original image format
  • Watermarking
  • EXIF auto-rotation
  • CloudFront CDN integration

✅ Summary

This project demonstrates a clean, production-ready approach to serverless image processing on AWS. It combines S3, Lambda, Pillow, and SNS into a scalable, low-maintenance pipeline suitable for real systems.

Built as a learning-focused yet production-aligned implementation.

About

This project implements an event-driven, serverless image processing pipeline on AWS. Images uploaded to Amazon S3 are automatically resized using AWS Lambda and Pillow, stored in a destination bucket, and followed by an email notification using Amazon SNS.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages