Automate Amazon EC2 and Amazon RDS rightsizing using EventBridge Scheduler, AWS Lambda and Terraform.
Not every workload requires the same capacity 24/7. This solution automatically upgrades or downgrades EC2 instances and RDS databases based on scheduled dates and times, helping reduce AWS costs while ensuring sufficient capacity when needed.
- Scheduled EC2 instance upgrades
- Scheduled EC2 instance downgrades
- Multiple EC2 instance support
- Recurring schedules
- One-time event schedules
- Date-range schedules
- Automated stop, resize and start workflow
- Scheduled RDS database upgrades
- Scheduled RDS database downgrades
- Multiple database support
- Recurring schedules
- One-time event schedules
- Date-range schedules
- Automated database class modification
- Event-driven architecture
- Serverless automation
- Terraform Infrastructure as Code
- CloudWatch logging
- SNS notifications
- Configuration-driven deployment
The following examples use the configured schedule_timezone.
| Time | Action |
|---|---|
| 08:00 AM | Upgrade |
| 07:00 PM | Downgrade |
| Schedule | Action |
|---|---|
| Every Wednesday 08:00 AM | Upgrade |
| Every Wednesday 06:00 PM | Downgrade |
| Date | Action |
|---|---|
| 2026-11-25 | Upgrade |
| 2026-12-01 | Downgrade |
| Configuration | Value |
|---|---|
| Start Date | 2026-06-01 |
| End Date | 2026-11-30 |
| Upgrade | Every Wednesday 08:00 AM |
| Downgrade | Every Wednesday 06:00 PM |
| Date | Action |
|---|---|
| November 1 | Increase Capacity |
| January 5 | Restore Normal Capacity |
- AWS Account
- Terraform >= 1.10, < 2.0
- AWS CLI configured
automated-ec2-rds-rightsizing/
├── terraform/
│
│ ├── modules/
│ │ ├── naming/
│ │ ├── iam/
│ │ ├── sns/
│ │ ├── lambda/
│ │ └── eventbridge/
│ │
│ ├── main.tf
│ ├── variables.tf
│ ├── outputs.tf
│ ├── providers.tf
│ ├── versions.tf
│ └── terraform.tfvars.example
│
├── lambda/
│ ├── ec2_resizer.py
│ └── rds_resizer.py
│
├── diagrams/
│ └── architecture.png
│
└── README.md
mobile_app_server = {
instance_id = "i-0123456789abcdef0"
upgrade_type = "t3.large"
downgrade_type = "t3.small"
upgrade_schedule = {
expression = "cron(0 8 ? * WED *)"
start_date = "2026-06-01T00:00:00Z"
end_date = "2026-11-30T23:59:59Z"
}
downgrade_schedule = {
expression = "cron(0 18 ? * WED *)"
start_date = "2026-06-01T00:00:00Z"
end_date = "2026-11-30T23:59:59Z"
}
}mobile_app_server = {
instance_id = "i-0abcdef1234567890"
upgrade_type = "c6i.2xlarge"
downgrade_type = "t3.medium"
upgrade_schedule = {
expression = "at(2026-11-25T06:00:00)"
}
downgrade_schedule = {
expression = "at(2026-12-01T00:00:00)"
}
}mobile_app_database = {
db_identifier = "mobile-app-mysql"
upgrade_class = "db.r6g.xlarge"
downgrade_class = "db.t3.medium"
upgrade_schedule = {
expression = "at(2026-07-15T00:00:00)"
}
downgrade_schedule = {
expression = "at(2026-07-16T00:00:00)"
}
}The solution supports configurable EventBridge Scheduler timezones.
Example:
schedule_timezone = "Asia/Singapore"Schedules run according to the configured timezone allowing automation to align with local business hours.
Initialize Terraform:
terraform initValidate configuration:
terraform validateReview planned changes:
terraform planDeploy infrastructure:
terraform applyRemove infrastructure:
terraform destroyMIT License
