Skip to content

Commit aad204d

Browse files
authored
Merge branch 'main' into SUP-4693-cpu-credits-parameter
2 parents 52eeb92 + 4320575 commit aad204d

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,60 @@ To enable resource limits with custom values, include these parameters in your C
9292
- Resource limits are disabled by default
9393
- Values can be specified as percentages or absolute values (for memory-related parameters)
9494

95+
## Scheduled Scaling
96+
97+
The Elastic CI Stack supports time-based scaling to automatically adjust the minimum number of instances based on your team's working hours. This feature helps optimize costs by scaling down during off-hours while allowing users the ability to proactively scale up capacity ahead of expected increasing capacity requirements.
98+
99+
### Configuration Parameters
100+
101+
| Parameter | Description | Default |
102+
|--------------------------|------------------------------------------------------|----------------------|
103+
| `EnableScheduledScaling` | Enable scheduled scaling actions | `false` |
104+
| `ScheduleTimezone` | Timezone for scheduled actions | `UTC` |
105+
| `ScaleUpSchedule` | Cron expression for scaling up | `0 8 * * MON-FRI` |
106+
| `ScaleUpMinSize` | MinSize when scaling up | `1` |
107+
| `ScaleDownSchedule` | Cron expression for scaling down | `0 18 * * MON-FRI` |
108+
| `ScaleDownMinSize` | MinSize when scaling down | `0` |
109+
110+
### Example Configuration
111+
112+
To enable scheduled scaling that maintains a minimum of 10 ASG instances during business hours (8 AM - 6 PM, Eastern Time) and 2 ASG instances during off-hours:
113+
114+
```json
115+
{
116+
"Parameters": {
117+
"EnableScheduledScaling": "true",
118+
"ScheduleTimezone": "America/New_York",
119+
"ScaleUpSchedule": "0 8 * * MON-FRI",
120+
"ScaleUpMinSize": "10",
121+
"ScaleDownSchedule": "0 18 * * MON-FRI",
122+
"ScaleDownMinSize": "2"
123+
}
124+
}
125+
```
126+
127+
### Schedule Format
128+
129+
Scheduled scaling uses [AWS Auto Scaling cron expressions](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html#scheduled-scaling-cron) with the format:
130+
```
131+
minute hour day-of-month month day-of-week
132+
```
133+
134+
Common examples:
135+
- `0 8 * * MON-FRI` - 8:00 AM on weekdays
136+
- `0 18 * * MON-FRI` - 6:00 PM on weekdays
137+
- `0 9 * * SAT` - 9:00 AM on Saturdays
138+
- `30 7 * * 1-5` - 7:30 AM Monday through Friday (using numbers)
139+
140+
### Timezone Support
141+
142+
The `ScheduleTimezone` parameter supports [IANA timezone names](https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html#scheduled-scaling-timezone) such as:
143+
- `America/New_York` (Eastern Time)
144+
- `America/Los_Angeles` (Pacific Time)
145+
- `Europe/London` (Greenwich Mean Time)
146+
- `Asia/Tokyo` (Japan Standard Time)
147+
- `UTC` (Coordinated Universal Time)
148+
95149
## Development
96150

97151
To get started with customizing your own stack, or contributing fixes and features:

templates/aws-stack.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ Metadata:
130130
- ScalerEventSchedulePeriod
131131
- ScalerMinPollInterval
132132
- ScalerEnableExperimentalElasticCIMode
133+
- EnableScheduledScaling
134+
- ScheduleTimezone
135+
- ScaleUpSchedule
136+
- ScaleUpMinSize
137+
- ScaleDownSchedule
138+
- ScaleDownMinSize
133139

134140
- Label:
135141
default: Cost Allocation Configuration
@@ -231,6 +237,45 @@ Parameters:
231237
- "false"
232238
Default: "false"
233239

240+
EnableScheduledScaling:
241+
Description: Enable scheduled scaling to automatically adjust MinSize based on time-based schedules
242+
Type: String
243+
AllowedValues:
244+
- "true"
245+
- "false"
246+
Default: "false"
247+
248+
ScheduleTimezone:
249+
Description: "Timezone for scheduled scaling actions (only used when EnableScheduledScaling is true). See AWS documentation for supported formats: https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html#scheduled-scaling-timezone (America/New_York, UTC, Europe/London, etc.)"
250+
Type: String
251+
Default: "UTC"
252+
253+
ScaleUpSchedule:
254+
Description: "Cron expression for when to scale up (only used when EnableScheduledScaling is true). See AWS documentation for format details: https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html#scheduled-scaling-cron (\"0 8 * * MON-FRI\" for 8 AM weekdays)"
255+
Type: String
256+
Default: "0 8 * * MON-FRI"
257+
AllowedPattern: '^[0-9*,-/]+ [0-9*,-/]+ [0-9*,-/]+ [0-9*,-/]+ [0-9A-Za-z*,-/]+$'
258+
ConstraintDescription: "Must be a valid cron expression (5 fields: minute hour day-of-month month day-of-week)"
259+
260+
ScaleUpMinSize:
261+
Description: MinSize to set when the ScaleUpSchedule is triggered (applied at the time specified in ScaleUpSchedule, only used when EnableScheduledScaling is true). Cannot exceed MaxSize.
262+
Type: Number
263+
Default: 1
264+
MinValue: 0
265+
266+
ScaleDownSchedule:
267+
Description: "Cron expression for when to scale down (only used when EnableScheduledScaling is true). See AWS documentation for format details: https://docs.aws.amazon.com/autoscaling/ec2/userguide/ec2-auto-scaling-scheduled-scaling.html#scheduled-scaling-cron (\"0 18 * * MON-FRI\" for 6 PM weekdays)"
268+
Type: String
269+
Default: "0 18 * * MON-FRI"
270+
AllowedPattern: '^[0-9*,-/]+ [0-9*,-/]+ [0-9*,-/]+ [0-9*,-/]+ [0-9A-Za-z*,-/]+$'
271+
ConstraintDescription: "Must be a valid cron expression (5 fields: minute hour day-of-month month day-of-week)"
272+
273+
ScaleDownMinSize:
274+
Description: MinSize to set when the ScaleDownSchedule is triggered (applied at the time specified in ScaleDownSchedule, only used when EnableScheduledScaling is true)
275+
Type: Number
276+
Default: 0
277+
MinValue: 0
278+
234279
ScaleOutCooldownPeriod:
235280
Description: Cooldown period in seconds before allowing another scale-out event
236281
Type: Number
@@ -1146,6 +1191,9 @@ Conditions:
11461191
- !Equals [ !Ref RootVolumeType, "io2" ]
11471192
- !Equals [ !Ref RootVolumeType, "gp3" ]
11481193

1194+
EnableScheduledScaling:
1195+
!Equals [ !Ref EnableScheduledScaling, "true" ]
1196+
11491197
Mappings:
11501198
ECRManagedPolicy:
11511199
none : { Policy: '' }
@@ -2012,6 +2060,26 @@ Resources:
20122060
AutoScalingReplacingUpdate:
20132061
WillReplace: true
20142062

2063+
ScheduledScaleUpAction:
2064+
Condition: EnableScheduledScaling
2065+
Type: AWS::AutoScaling::ScheduledAction
2066+
Properties:
2067+
AutoScalingGroupName: !Ref AgentAutoScaleGroup
2068+
ScheduledActionName: !Sub "${AWS::StackName}-ScaleUp"
2069+
Recurrence: !Ref ScaleUpSchedule
2070+
MinSize: !Ref ScaleUpMinSize
2071+
TimeZone: !Ref ScheduleTimezone
2072+
2073+
ScheduledScaleDownAction:
2074+
Condition: EnableScheduledScaling
2075+
Type: AWS::AutoScaling::ScheduledAction
2076+
Properties:
2077+
AutoScalingGroupName: !Ref AgentAutoScaleGroup
2078+
ScheduledActionName: !Sub "${AWS::StackName}-ScaleDown"
2079+
Recurrence: !Ref ScaleDownSchedule
2080+
MinSize: !Ref ScaleDownMinSize
2081+
TimeZone: !Ref ScheduleTimezone
2082+
20152083
AsgProcessSuspenderRole:
20162084
Type: AWS::IAM::Role
20172085
Properties:

0 commit comments

Comments
 (0)