Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This AWS CloudFormation stack resizes EC2 instances on a schedule to optimize co
## 🔧 How It Works

- A Lambda function runs twice per day via EventBridge rules:
- **7 PM Pacific** — Scales down tagged instances to a smaller type (e.g. `t3.medium`)
- **7 PM Pacific (Mon–Fri only)** — Scales down tagged instances to a smaller type (e.g. `t3.medium`)
- **4 AM Pacific (Mon–Fri only)** — Scales them back up to the original size
- Instances are rebooted once per resize operation (stop → modify → start)
- This works even if you're using Compute Savings Plans
Expand Down Expand Up @@ -44,7 +44,8 @@ To deploy with AWS Console:
## 📝 Customization

- **Resize Target:** The off-hours instance type defaults to `t3.medium`. You can change this in the Lambda code.
- **Schedule:** Default schedule is hardcoded for Pacific Time. You can update the EventBridge cron rules if needed.
- **Schedule:** Default EventBridge cron rules are pinned to 4 AM and 7 PM Pacific (with automatic DST handling via `ScheduleExpressionTimezone: America/Los_Angeles`). Update the `LambdaScheduleUpTime`/`LambdaScheduleDownTime` parameters if you need different windows.
- **Redeployment:** Deploy or update the CloudFormation stack after changing schedule parameters so the EventBridge rules pick up the new cron expressions and timezone.
- **Logging:** CloudWatch Log Group is created with 14-day retention. Logs show success and error messages per instance.

## 🧪 Testing
Expand Down
6 changes: 4 additions & 2 deletions ec2-dynamic-scheduler.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Parameters:
Default: DynamicEC2Scheduler
LambdaScheduleUpTime:
Type: String
Default: "cron(0 11 ? * MON-FRI *)"
Default: "cron(0 4 ? * MON-FRI *)"
LambdaScheduleDownTime:
Type: String
Default: "cron(0 2 ? * MON-FRI *)"
Default: "cron(0 19 ? * MON-FRI *)"

Resources:

Expand Down Expand Up @@ -172,6 +172,7 @@ Resources:
Name: EC2ScalerScheduleDown
Description: Triggers Lambda to scale down EC2 instances at 7 PM Pacific, Monday through Friday
ScheduleExpression: !Ref LambdaScheduleDownTime
ScheduleExpressionTimezone: America/Los_Angeles
State: ENABLED
Targets:
- Arn: !GetAtt EC2ScalerFunction.Arn
Expand All @@ -185,6 +186,7 @@ Resources:
Name: EC2ScalerScheduleUp
Description: Triggers Lambda to scale up EC2 instances at 4 AM Pacific, Monday through Friday
ScheduleExpression: !Ref LambdaScheduleUpTime
ScheduleExpressionTimezone: America/Los_Angeles
State: ENABLED
Targets:
- Arn: !GetAtt EC2ScalerFunction.Arn
Expand Down