This project is a fully automated serverless architecture example that detects images uploaded to AWS S3 and automatically reduces their size by 50% using the Pillow library.
It demonstrates Infrastructure as Code (IaC) using Terraform and an event-driven workflow powered by AWS Lambda.
graph LR
User(["👤 User"])
subgraph AWS ["☁️ AWS Cloud"]
subgraph S3In ["S3 Source Bucket"]
Raw["proje-raw-images"]
end
subgraph Lambda ["AWS Lambda — Python 3.9"]
Trigger["S3 ObjectCreated\nEvent Trigger"]
Func["lambda_function.py\nImage Processing"]
Layer["Pillow Layer\n(Klayers)\nresize → 50%"]
end
subgraph S3Out ["S3 Destination Bucket"]
Opt["proje-optimized-images"]
end
CW["CloudWatch\nLogs"]
IAM["IAM Role\nS3 Read + Write"]
end
User -->|"upload image"| Raw
Raw -->|"ObjectCreated event"| Trigger
Trigger --> Func
Func --> Layer
Layer -->|"save optimized image"| Opt
Func -->|"execution logs"| CW
IAM -. "permissions" .-> Func
Infrastructure as Code (IaC): All AWS resources (S3, IAM, Lambda) are managed using Terraform.
Event-Driven: The system runs in real time using the S3 ObjectCreated trigger.
Serverless: No server management is required; you only pay when execution happens.
Scalable: Thanks to AWS Lambda, it can process hundreds of images simultaneously.
- Language: Python 3.9
- Infrastructure: Terraform
- AWS Services: Lambda, S3, IAM, CloudWatch
- Libraries: Pillow (PIL), Boto3
main.tf— Defines AWS resources such as S3 buckets, IAM roles, and Lambda configuration.lambda_function.py— Contains the image processing logic written in Python.- Layers (Klayers) — Lambda layer integration for the Pillow library.
Initialize Terraform:
terraform initCreate the infrastructure on AWS:
terraform applyUpload an image to the proje-raw-images bucket and check the proje-optimized-images bucket!