Automated AWS Cost Optimization using AWS Lambda, EventBridge, CloudWatch, SNS, Terraform, and GitHub Actions.
AWS Cloud Cost Guardian is a serverless automation project that helps reduce unnecessary AWS storage costs by identifying and deleting unused EBS snapshots.
The solution runs automatically on a schedule, publishes CloudWatch metrics, sends email reports using SNS, and is deployed through a GitHub Actions CI/CD pipeline. Infrastructure is managed with Terraform.
Important
Project Status
This project has been successfully completed and validated. To prevent ongoing AWS costs, all cloud resources (Lambda, IAM Roles, EventBridge Scheduler, SNS Topic, CloudWatch resources, and test infrastructure) were removed after testing.
The repository remains fully reproducible using the included Terraform configuration and deployment guide.
- Automated EBS snapshot cleanup
- Dry Run mode
- Keep=True tag protection
- CloudWatch Metrics & Dashboard
- CloudWatch Alarms
- SNS Email Notifications
- EventBridge Scheduling
- Terraform Infrastructure as Code
- GitHub Actions CI/CD
GitHub
│
GitHub Actions
│
AWS Lambda
│
EC2 / EBS
├── Delete Unused Snapshots
├── CloudWatch Metrics
└── SNS Email
| Service | Purpose |
|---|---|
| Lambda | Automation |
| EC2 | Volume discovery |
| EBS | Snapshot cleanup |
| EventBridge | Scheduling |
| SNS | |
| CloudWatch | Monitoring |
| IAM | Permissions |
| Terraform | IaC |
| GitHub Actions | CI/CD |
aws-cloud-cost-guardian/
├── .github/workflows/deploy.yml
├── architecture/
├── docs/
├── lambda/
├── screenshots/
├── terraform/
└── README.md
Follow these steps to deploy the AWS Cloud Cost Guardian project from scratch.
Navigate to:
AWS Console → IAM → Policies → Create Policy
- Amazon EC2
- Amazon SNS
- Amazon CloudWatch
- Amazon CloudWatch Logs
- ec2:DescribeSnapshots
- ec2:DeleteSnapshot
- ec2:DescribeInstances
- cloudwatch:PutMetricData
- sns:Publish
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Save the policy as:
CloudCostGuardianPolicy
Navigate to:
AWS Console → IAM → Roles → Create Role
Choose
Trusted Entity:
AWS Service
Use Case:
Lambda
Attach the following policies
- AWSLambdaBasicExecutionRole
- CloudCostGuardianPolicy
Role Name
CloudCostGuardianRole
Navigate to
AWS Console → Lambda → Create Function
Configuration
Function Name
aws-cost-optimization-toolkit
Runtime
Python 3.13
Architecture
x86_64
Execution Role
Use Existing Role
CloudCostGuardianRole
Click
Create Function
Open
lambda/
Copy the contents of
lambda_function.py
Paste into the Lambda editor
Click
Deploy
Lambda
Configuration
↓
Environment Variables
Add
| Key | Value |
|---|---|
| DRY_RUN | False |
| KEEP_TAG_KEY | Keep |
| KEEP_TAG_VALUE | True |
| SNS_TOPIC_ARN | Your SNS Topic ARN |
Save
Navigate to
AWS Console
↓
Amazon SNS
↓
Create Topic
Configuration
Type
Standard
Name
cloud-cost-guardian-topic
Click
Create Topic
Inside the SNS Topic
Click
Create Subscription
Protocol
Email
Endpoint
your-email@example.com
Click
Create Subscription
Open your inbox
Click
Confirm Subscription
Copy
Topic ARN
Example
arn:aws:sns:us-east-1:123456789012:cloud-cost-guardian-topic
Paste it into
Lambda
↓
Environment Variables
↓
SNS_TOPIC_ARN
Save
Deploy
Lambda
↓
Test
↓
Create New Test Event
Name
TestCleanup
Event JSON
{}Click
Test
Verify
✅ Lambda executes successfully
✅ CloudWatch Logs generated
✅ Email report received
Run the Lambda once.
Navigate to
AWS Console
↓
CloudWatch
↓
Metrics
↓
CloudCostGuardian
Verify these metrics exist
- SnapshotsScanned
- SnapshotsDeleted
- SnapshotsSkipped
- CleanupErrors
Navigate to
CloudWatch
↓
Alarms
↓
Create Alarm
Metric
CleanupErrors
Condition
Greater Than
Threshold = 0
Notification
SNS Topic
cloud-cost-guardian-topic
Alarm Name
CloudCostGuardian-CleanupErrors
Create Alarm
Navigate to
AWS Console
↓
Amazon EventBridge
↓
Scheduler
↓
Create Schedule
Configuration
Name
CloudCostGuardianScheduler
Schedule
Rate
Every 5 Minutes (Testing)
or
Daily (Production)
Target
AWS Lambda
aws-cost-optimization-toolkit
Execution Role
Auto Create Role
Create Schedule
Wait for the scheduled execution.
Verify
✅ Lambda Invocations
✅ CloudWatch Logs
✅ CloudWatch Metrics
✅ SNS Email Notifications
✅ Snapshot Cleanup
Terraform Folder
terraform/
├── provider.tf
├── versions.tf
├── variables.tf
├── terraform.tfvars
├── iam.tf
├── lambda.tf
├── sns.tf
├── cloudwatch.tf
├── eventbridge.tf
└── outputs.tf
Initialize
terraform initFormat
terraform fmtValidate
terraform validateDeploy
terraform applyRepository Structure
.github/
└── workflows
└── deploy.yml
Required GitHub Secrets
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_REGION
Workflow
Developer
↓
Git Push
↓
GitHub Actions
↓
Create Deployment Package
↓
Deploy Lambda
↓
Wait for Deployment
↓
Deployment Successful
Every push to the main branch automatically deploys the latest Lambda code.
Developer
│
▼
GitHub Repository
│
▼
GitHub Actions CI/CD
│
▼
Deploy Lambda Function
│
▼
Amazon EventBridge Scheduler
│
▼
AWS Lambda Cost Guardian
│
┌──────────────┴──────────────┐
│ │
▼ ▼
Amazon EC2 / EBS Amazon CloudWatch
Discover Snapshots Custom Metrics & Logs
│
▼
Delete Unused Snapshots
│
▼
Amazon SNS
│
▼
Email Notification
To avoid unnecessary AWS charges after testing, delete the following resources:
- EventBridge Scheduler
- Lambda Function
- IAM Role
- Custom IAM Policy
- SNS Topic
- CloudWatch Alarm
- CloudWatch Log Group
- CloudWatch Custom Metrics (optional)
- EC2 Test Instance
- EBS Volume
- Test Snapshots
- Automated EBS snapshot cleanup
- Email notification after every execution
- CloudWatch metrics published
- CloudWatch alarm on cleanup failures
- EventBridge scheduled execution
- Infrastructure managed with Terraform
- Automatic deployment through GitHub Actions
Replace the placeholders below with your screenshots.
- Lambda Function
- IAM Role
- SNS Topic
- EventBridge Scheduler
- CloudWatch Dashboard
- CloudWatch Alarm
- GitHub Actions Success
Developer
│
Git Push
│
GitHub Actions
│
Package Lambda
│
Deploy Lambda
- Lambda Test Event
- EventBridge Trigger
- CloudWatch Metrics
- SNS Email
- GitHub Actions Deployment
- Multi-region support
- Slack notifications
- AWS Cost Explorer integration
- AWS Organizations support
Revanth B L
GitHub: https://github.com/revanth-bl
