This project is an AWS Lambda function written in Go that automatically:
Fetches images from an S3 bucket.
Optimizes (resizes & compresses) images using imaging.
Uploads optimized images to another S3 bucket.
Uses a worker pool for efficient parallel processing.
Infrastructure is deployed using Terraform, ensuring:
- IAM roles & permissions for Lambda & S3.
- Automatic S3 event triggers (optional) to process new uploads.
- Go (AWS Lambda runtime)
- AWS SDK for Go v2
- Disintegration/imaging (Image processing)
- Terraform (Infrastructure as Code)
- AWS Lambda (Serverless compute)
- Amazon S3 (Storage for images)
- IAM (Permissions & security)
Ensure you have Go installed, then build and zip the Lambda function:
GOOS=linux GOARCH=amd64 go build -o bootstrap main.go
zip lambda.zip bootstrapterraform init
terraform apply -auto-approveaws s3 cp image.jpg s3://my-source-bucket/uuid/image.jpgaws s3 ls s3://my-destination-bucket/optimized/uuid/Modify environment variables in Terraform (main.tf):
environment {
variables = {
SOURCE_BUCKET = "my-source-bucket"
DESTINATION_BUCKET = "my-destination-bucket"
}
}- Check CloudWatch logs for errors:
aws logs tail /aws/lambda/ImageOptimizerLambda --follow
- Ensure IAM permissions allow S3 read/write access.
This project is licensed under the MIT License.