This project automatically resizes images uploaded to an S3 bucket using AWS Lambda, and sends notifications via SNS when the resizing is complete.
This Terraform project sets up a serverless image resizing pipeline that:
- Monitors an S3 bucket for new image uploads
- Triggers an AWS Lambda function automatically when images are uploaded
- Resizes images using the Pillow library
- Stores resized images in a separate S3 bucket
- Notifies users via email when the resizing is complete
Two S3 buckets are created:
-
Source Bucket (
image-need-to-resize): Where users upload original images -
Destination Bucket (
image-resized): Where resized images are stored
The Lambda function performs the image resizing:
- Runtime: Python 3.9
- Memory: 256 MB
- Timeout: 60 seconds
- Layer: Klayers-p39-pillow for image processing
- Handler:
CreateThumbnail.handler
Email notifications are sent when images are successfully resized:
- Protocol: Email
- Subscriber: Configured in
terraform.tfvars
Lambda execution role with policies to:
- Read from source S3 bucket
- Write to destination S3 bucket
- Publish to SNS topic
- AWS Account with appropriate credentials
- Terraform installed (v1.0+)
- Python 3.9+ (for local testing)
- AWS CLI configured
.
├── providers.tf # AWS provider configuration
├── variables.tf # Variable definitions
├── terraform.tfvars # Terraform variable values
├── locals.tf # Local values
├── s3-bucket.tf # S3 bucket resources
├── iam-role.tf # IAM role definitions
├── iam-policy.tf # IAM policy definitions
├── lambda-function.tf # Lambda function resources
├── sns-topic.tf # SNS topic and subscription
├── backend.tf # Terraform backend configuration
├── CreateThumbnail.zip # Lambda function code (zipped)
├── README.md # This file
└── assets/ # Architecture diagrams and screenshots
aws_access_key = "YOUR_AWS_ACCESS_KEY"
aws_secret_key = "YOUR_AWS_SECRET_KEY"
aws_region = "us-east-1"
mail-id = "your-email@example.com"s3-bucket-lambda-code: Source bucket for original images (auto-suffixed with account ID)s3-bucket-dest: Destination bucket for resized images (auto-suffixed with account ID)sns-name: SNS topic namemail-id: Email address for notifications
terraform initterraform planterraform applyWhen prompted, type yes to confirm.
-
Upload an image to the source S3 bucket (
non-resized-image-[account-id]) -
Lambda automatically triggers and resizes the image
-
Receive an email notification with a link to the resized image in the destination bucket
-
Access the resized image from the destination bucket (
resized-images-[account-id])
The CreateThumbnail.handler function:
- Receives S3 event when image is uploaded
- Downloads the original image from source bucket
- Resizes the image to a thumbnail
- Uploads the thumbnail to destination bucket
- Publishes a message to SNS topic with the result
To remove all resources created by this project:
terraform destroyType yes when prompted to confirm deletion.
- Store AWS credentials securely (use AWS IAM roles when possible)
- Restrict S3 bucket access to Lambda function only
- Use encryption for sensitive data in environment variables
- Monitor Lambda execution logs in CloudWatch
Check CloudWatch Logs:
aws logs tail /aws/lambda/Image-Resizing-Lambda --follow- Confirm SNS subscription by clicking the link in the confirmation email
- Check spam/junk folder
- Verify the email address in
terraform.tfvars
The bucket names are auto-suffixed with your AWS account ID. If you still get conflicts, modify the locals.tf file to add a random suffix.
- Lambda: ~$0.20 per 1 million requests
- S3: ~$0.023 per GB stored
- SNS: ~$0.50 per 1 million notifications
- Data Transfer: Varies by region
This project is provided as-is for educational and demonstration purposes.
For issues or questions, please refer to the AWS documentation:




