How srinivasshirure/image-resizing-project-on-aws works
Purpose and entry points
This is Terraform-managed AWS infrastructure for an event-driven image-thumbnail pipeline. The operational entry point is an object upload to the source S3 bucket; the infrastructure entry point is Terraform deployment through the root .tf files. Lambda implementation is packaged as CreateThumbnail.zip, with handler CreateThumbnail.handler.
Provisioning and configuration
Terraform defines the AWS provider, remote/state backend, inputs, and derived naming values. Bucket and service names are parameterized and account-suffixed through locals; deployment credentials, region, and notification email are external inputs.
• providers.tf
• backend.tf
• variables.tf
• locals.tf
Ingestion boundary: source S3
A source S3 bucket accepts original image uploads. Its object-created event configuration is the event boundary that invokes Lambda. This separates untrusted uploaded image data from processing execution.
• s3-bucket.tf
• lambda-function.tf
Compute stage: Lambda thumbnail processor
AWS Lambda runs Python 3.9 with 256 MB memory and a 60-second timeout. It loads Pillow through the configured Klayers Python 3.9 layer, receives the S3 event, downloads the uploaded object, creates a thumbnail, and writes output. The deployment artifact is prebuilt rather than generated by Terraform.
• lambda-function.tf
• CreateThumbnail.zip
Output boundary: destination S3
A separate destination bucket stores resized images. Lambda is the intended writer, keeping originals and generated artifacts in distinct storage domains and avoiding source-trigger recursion.
• s3-bucket.tf
• iam-policy.tf
Notification stage: SNS email
After successful processing, Lambda publishes completion information—expected to include the resized image result—to an SNS topic. SNS delivers it to an email subscription whose address is supplied as Terraform input and requires recipient confirmation.
• sns-topic.tf
• lambda-function.tf
• variables.tf
Authorization and invocation control
A Lambda execution role and attached policies grant the minimum architectural capabilities: read source objects, write destination objects, and publish to SNS. Lambda resource configuration also permits S3 to invoke the function; these are distinct trust/control paths.
• iam-role.tf
• iam-policy.tf
• lambda_policy.json
• lambda_role.json
Primary flow and runtime dependencies
1. Client uploads an image to the source bucket.
2. S3 emits an object-created event to Lambda.
3. Lambda uses AWS S3 APIs and Pillow to fetch and resize the image.
4. Lambda writes the thumbnail to destination S3.
5. Lambda publishes status/result to Amazon SNS; SNS sends email.
Material external services are AWS S3, Lambda, IAM, SNS, CloudWatch Logs (Lambda observability), and the third-party Klayers Pillow Lambda layer.
Main entry points: lambda-function.tf Thumbnail Lambda · providers.tf Terraform root · iam-role.tf Lambda execution role · s3-bucket.tf Source S3 bucket
Components 14
Terraform provisioning
Root Terraform defines and deploys the AWS resources.
- Terraform root · Provider, backend, inputs, and derived resource names.
providers.tf
Image storage
Originals and generated thumbnails remain separated.
- Source S3 bucket · Accepts uploaded original images and emits object-created events.
s3-bucket.tf - Destination S3 bucket · Stores generated thumbnails.
s3-bucket.tf - Object-created event · Invocation boundary for uploaded objects.
lambda-function.tf
Thumbnail processing
Event-driven Lambda runtime and dependencies.
- Thumbnail Lambda · Python 3.9 handler CreateThumbnail.handler; 256 MB and 60-second timeout.
lambda-function.tf - CreateThumbnail.zip · Prebuilt deployment package containing thumbnail logic.
CreateThumbnail.zip - Klayers Pillow layer · Provides Pillow for Python 3.9 image resizing.
lambda-function.tf - Lambda execution role · Runtime identity assumed by the thumbnail function.
iam-role.tf - S3 access policy · Allows source reads and destination writes.
iam-policy.tf - SNS publish policy · Allows Lambda to publish completion messages.
iam-policy.tf - CloudWatch Logs · Receives Lambda execution logs.
lambda-function.tf - S3 invoke permission · Permits the source bucket to invoke Lambda.
lambda-function.tf
Notification
Completion delivery through SNS email.
- Completion SNS topic · Receives processing status and result notifications.
sns-topic.tf - Email subscription · Recipient must confirm the subscription.
sns-topic.tf
Connections 17
- Terraform root → Source S3 bucket: provisions
- Terraform root → Destination S3 bucket: provisions
- Terraform root → Thumbnail Lambda: deploys
- Terraform root → Completion SNS topic: provisions
- Source S3 bucket → Object-created event: object upload
- Object-created event → Thumbnail Lambda: invokes
- S3 invoke permission → Thumbnail Lambda: authorizes S3 invocation
- Thumbnail Lambda → CreateThumbnail.zip: runs
- Thumbnail Lambda → Klayers Pillow layer: uses
- Thumbnail Lambda → Lambda execution role: assumes
- Lambda execution role → S3 access policy: attaches
- Lambda execution role → SNS publish policy: attaches
- Thumbnail Lambda → Source S3 bucket: reads original
- Thumbnail Lambda → Destination S3 bucket: writes thumbnail
- Thumbnail Lambda → Completion SNS topic: publishes completion
- Completion SNS topic → Email subscription: delivers email
- Thumbnail Lambda → CloudWatch Logs: writes logs