How aws7908/image-resizing-project-on-aws works
Purpose and entry points
This is Terraform infrastructure for an event-driven AWS image-thumbnail pipeline. The deployment entry point is the root Terraform module: providers.tf, backend.tf, and the resource definitions applied through Terraform. Runtime processing enters through an S3 object-upload event and invokes the packaged Lambda handler CreateThumbnail.handler in CreateThumbnail.zip.
1. Terraform deployment and shared naming
The root module configures AWS provider/backend concerns, input variables, and derived resource names. Bucket names are intended to be account-suffixed, avoiding globally unique-name collisions.
• providers.tf
• backend.tf
• variables.tf
• locals.tf
2. Source and destination object-storage boundary
Two S3 buckets separate unprocessed uploads from generated thumbnails. The source bucket is the external ingestion boundary; the destination bucket receives Lambda output and is not described as a trigger source, preventing recursive processing.
• s3-bucket.tf
• locals.tf
3. Event-to-compute integration
S3 upload notifications invoke the image-resizing Lambda. Terraform must establish both the bucket notification/event configuration and permission for S3 to invoke the Lambda; this is the central asynchronous handoff.
• s3-bucket.tf
• lambda-function.tf
4. Lambda image-processing runtime
The Lambda deployment consumes CreateThumbnail.zip, uses Python 3.9, and executes CreateThumbnail.handler. It is configured for 256 MB memory and a 60-second timeout. Pillow is supplied through the Klayers Python 3.9 Pillow layer, keeping native image-processing dependencies outside the application ZIP.
• lambda-function.tf
• CreateThumbnail.zip
5. Processing flow
For each qualifying S3 event, the handler reads the uploaded object from the source bucket, resizes it into a thumbnail, writes the result into the destination bucket, then emits a completion notification. Bucket names and SNS topic identity are expected to be passed to the function through Terraform-managed configuration.
• CreateThumbnail.zip
• lambda-function.tf
• s3-bucket.tf
6. IAM authorization boundary
A dedicated Lambda execution role grants only the cross-service actions needed for the pipeline: source-object reads, destination-object writes, and SNS publishing. Role trust and permission policies are split into Terraform resources and policy documents.
• iam-role.tf
• iam-policy.tf
• lambda_policy.json
• lambda_role.json
7. Notification delivery
An SNS topic decouples successful processing from email delivery. Terraform creates the topic and an email subscription using the configured recipient; delivery requires the recipient to confirm the SNS subscription.
• sns-topic.tf
• variables.tf
Operational dependencies
The system runs entirely on AWS managed services: Amazon S3, AWS Lambda, Amazon SNS, IAM, and CloudWatch Logs for Lambda observability. Terraform requires AWS credentials and an initialized backend/provider configuration. The principal failure boundaries are S3 event delivery, Lambda execution/dependency availability, IAM access, destination writes, and SNS subscription confirmation.
Main entry points: lambda-function.tf CreateThumbnail Lambda · s3-bucket.tf Source uploads bucket · locals.tf Inputs and bucket names · providers.tf Root Terraform module
Components 15
Terraform deployment
- Root Terraform module · Applies the AWS infrastructure.
providers.tf - Provider and backend
backend.tf - Inputs and bucket names · Derives account-suffixed resource names.
locals.tf
Storage and events
- Source uploads bucket · External ingestion boundary.
s3-bucket.tf - Upload notification · Qualifying object uploads invoke the function.
s3-bucket.tf - S3 invoke permission
lambda-function.tf - Thumbnail bucket · Receives generated thumbnails and does not trigger processing.
s3-bucket.tf
Image processing
- CreateThumbnail Lambda · Python 3.9 handler with 256 MB and 60-second timeout.
lambda-function.tf - CreateThumbnail package · Contains CreateThumbnail.handler.
CreateThumbnail.zip - Klayers Pillow layer · Supplies native Pillow dependencies.
lambda-function.tf - Lambda execution role · Trusted by Lambda.
iam-role.tf - Pipeline access policy · Allows source reads, destination writes, and SNS publishing.
iam-policy.tf - Lambda logs
Notification delivery
- Completion topic · Decouples processing completion from email delivery.
sns-topic.tf - Recipient email subscription · Requires recipient confirmation.
sns-topic.tf
Connections 17
- Root Terraform module → Provider and backend: configures
- Root Terraform module → Inputs and bucket names: uses
- Inputs and bucket names → Source uploads bucket: names
- Inputs and bucket names → Thumbnail bucket: names
- Source uploads bucket → Upload notification: emits uploads
- Upload notification → CreateThumbnail Lambda: invokes
- S3 invoke permission → CreateThumbnail Lambda: permits S3 invocation
- Source uploads bucket → S3 invoke permission: authorized caller
- CreateThumbnail package → CreateThumbnail Lambda: deployed as
- Klayers Pillow layer → CreateThumbnail Lambda: attached to
- Lambda execution role → CreateThumbnail Lambda: executes as
- Pipeline access policy → Lambda execution role: attached to
- CreateThumbnail Lambda → Source uploads bucket: reads uploaded object
- CreateThumbnail Lambda → Thumbnail bucket: writes thumbnail
- CreateThumbnail Lambda → Completion topic: publishes completion
- Completion topic → Recipient email subscription: delivers notification
- CreateThumbnail Lambda → Lambda logs: writes logs