How afsar-0007/aws-costoptimization works
This repository automates cleanup of orphaned EBS snapshots: a schedule invokes Lambda, which checks snapshots against their volumes, deletes orphaned snapshots, logs activity, and can notify by email. Terraform defines the AWS infrastructure, including monitoring and access control. The Lambda behavior is supported by source; infrastructure relationships are based on the README because the Terraform files were not sampled.
Main entry points: lambda_function.py Cleanup Lambda · main.tf Terraform infrastructure · sns.tf SNS notifications · eventbridge.tf EventBridge schedule
Components 13
Snapshot cleanup
- Cleanup Lambda
terraform/lambda/lambda_function.py - Snapshot discovery
terraform/lambda/lambda_function.py - Volume existence check
terraform/lambda/lambda_function.py - Orphan deletion
terraform/lambda/lambda_function.py
AWS services
- EventBridge schedule
terraform/eventbridge.tf - EC2 / EBS
- SNS notifications
terraform/sns.tf - Email subscriber
Infrastructure and operations
- CloudWatch logs
terraform/cloudwatch.tf - Throttling alarm
terraform/cloudwatch.tf - IAM permissions
terraform/iam.tf - Terraform infrastructure
terraform/main.tf
Terraform state
- Remote state
terraform/backend.tf
Connections 18
- EventBridge schedule → Cleanup Lambda: triggers
README.md - Cleanup Lambda → Snapshot discovery: runs
terraform/lambda/lambda_function.py - Snapshot discovery → EC2 / EBS: lists snapshots
terraform/lambda/lambda_function.py - Cleanup Lambda → Volume existence check: checks volumes
terraform/lambda/lambda_function.py - Volume existence check → EC2 / EBS: describes volumes
terraform/lambda/lambda_function.py - Cleanup Lambda → Orphan deletion: deletes orphans
terraform/lambda/lambda_function.py - Orphan deletion → EC2 / EBS: deletes snapshots
terraform/lambda/lambda_function.py - Cleanup Lambda → CloudWatch logs: writes activity
README.md - Cleanup Lambda → SNS notifications: publishes report
terraform/lambda/lambda_function.py - SNS notifications → Email subscriber: delivers email
README.md - Throttling alarm → SNS notifications: sends alert
README.md - IAM permissions → Cleanup Lambda: grants permissions
README.md - Terraform infrastructure → EventBridge schedule: provisions
README.md - Terraform infrastructure → Cleanup Lambda: provisions
README.md - Terraform infrastructure → CloudWatch logs: configures monitoring
README.md - Terraform infrastructure → SNS notifications: provisions
README.md - Terraform infrastructure → IAM permissions: configures access
README.md - Terraform infrastructure → Remote state: stores state
README.md