Scheduled scaling for Application Auto Scaling
Scaling based on a schedule allows you to set your own scaling schedule for predictable load changes. For example, every week the traffic to your web application starts to increase on Wednesday, remains high on Thursday, and starts to decrease on Friday. You can configure Application Auto Scaling to increase capacity on Wednesday and decrease capacity on Friday.
To use scheduled scaling, create scheduled actions, which tell Application Auto Scaling to perform scaling activities at specific times. When you create a scheduled action, you specify the scalable target, when the scaling activity should occur, and the minimum and maximum capacity.
At the specified time, Application Auto Scaling scales based on the new capacity values, by comparing current capacity to the specified minimum and maximum capacity.
-
If current capacity is less than the specified minimum capacity, Application Auto Scaling scales out (increases capacity) to the minimum capacity.
-
If current capacity is greater than the specified maximum capacity, Application Auto Scaling scales in (decreases capacity) to the maximum capacity.
After the scheduled action runs, the scaling policy (if any) can continue to make decisions about whether to further scale capacity. This helps you ensure that you have sufficient capacity to handle the load for your application. While your application scales to match demand, current capacity must fall within the minimum and maximum capacity that your scheduled action allows.
For a detailed example of using scheduled scaling, see the blog post Scheduling AWS Lambda Provisioned Concurrency for recurring peak usage
Limits
-
Application Auto Scaling does not provide second-level precision in schedule expressions.
-
Scheduled scaling is not supported for Amazon MSK.
Considerations
When you create a scheduled action, keep the following in mind:
-
A scheduled action sets the
MinCapacity
andMaxCapacity
to what is specified by the scheduled action at the time specified by the scheduled action. It does not keep track of old values and return to the older values after the end time. -
A scheduled action may take a few moments to execute. Because scheduled actions are executed in the order that they are specified, scheduled actions with scheduled start times close to each other can take longer to execute.
-
Application Auto Scaling guarantees the order of execution for scheduled actions for the same scalable target but not for scheduled actions across scalable targets.
-
The name of the scheduled action must be unique among all other scheduled actions on the specified scalable target.
-
You can temporarily disable scheduled scaling without deleting your scheduled actions. For more information, see Suspending and resuming scaling for Application Auto Scaling.
-
If you specify a recurring schedule, you can specify a date and time for the start time, the end time, or both.
-
If you specify a recurring schedule and a start time, Application Auto Scaling performs the action at this time, and then performs the action based on the specified recurrence.
-
If you specify an end time, the action stops repeating after this time.
-
For brevity, the examples in this topic illustrate CLI commands for a few of the
services that integrate with Application Auto Scaling. To specify a different scalable
target, specify its
namespace in --service-namespace
, its scalable dimension in
--scalable-dimension
, and its resource ID in --resource-id
.
Register scalable target
Before you can create a scheduled action, you must register the scalable target. Use
the
register-scalable-target command to register a new scalable
target. The following example registers the provisioned concurrency for an alias called
BLUE
for the Lambda function called my-function
.
On local Linux, macOS, or Unix machines:
aws application-autoscaling register-scalable-target --service-namespace
lambda
\ --scalable-dimensionlambda:function:ProvisionedConcurrency
\ --resource-idfunction:my-function:BLUE
\ --min-capacity10
--max-capacity50
On local Windows machines:
aws application-autoscaling register-scalable-target --service-namespace
lambda
--scalable-dimensionlambda:function:ProvisionedConcurrency
--resource-idfunction:my-function:BLUE
--min-capacity10
--max-capacity50
Using the AWS CLI to create or update a scheduled action
You can create and update scheduled actions that scale one time only or that scale on a recurring schedule using the put-scheduled-action command. When you specify the new capacity, you can specify a minimum capacity, a maximum capacity, or both.
Schedule actions for a one-time schedule
You can specify a one-time schedule to automatically scale your scalable target at a certain date and time, in UTC.
Example: To scale out one time only
The following is an example of creating a scheduled action to scale out capacity at a specific date and time.
At the date and time specified for --schedule
, if the value specified for
MinCapacity
is above the current capacity, Application Auto Scaling scales out to
MinCapacity
.
On local Linux, macOS, or Unix machines:
aws application-autoscaling put-scheduled-action --service-namespace
custom-resource
\ --scalable-dimensioncustom-resource:ResourceType:Property
\ --resource-idfile://~/custom-resource-id.txt
\ --scheduled-action-namescale-out
\ --schedule "at(2021-03-31T22:00:00
)" \ --scalable-target-action MinCapacity=3
On local Windows machines:
aws application-autoscaling put-scheduled-action --service-namespace
custom-resource
--scalable-dimensioncustom-resource:ResourceType:Property
--resource-idfile://~/custom-resource-id.txt
--scheduled-action-namescale-out
--schedule "at(2021-03-31T22:00:00
)" --scalable-target-action MinCapacity=3
When you specify a custom resource, the custom-resource-id.txt
file
specifies the API Gateway endpoint for your custom resource. For more information
about
configuring a custom resource, see our GitHub repository
https://example.execute-api.region.amazonaws.com/prod/scalableTargetDimensions/1-23456789
Example: To scale in one time only
The following is an example of creating a scheduled action to scale in capacity at a specific date and time.
At the date and time specified for --schedule
, if the value specified for
MaxCapacity
is below the current capacity, Application Auto Scaling scales in to
MaxCapacity
.
On local Linux, macOS, or Unix machines:
aws application-autoscaling put-scheduled-action --service-namespace
ecs
\ --scalable-dimensionecs:service:DesiredCount
\ --resource-idservice/default/web-app
\ --scheduled-action-namescale-in
\ --schedule "at(2021-01-31T17:00:00
)" \ --scalable-target-action MaxCapacity=1
On local Windows machines:
aws application-autoscaling put-scheduled-action --service-namespace
ecs
--scalable-dimensionecs:service:DesiredCount
--resource-idservice/default/web-app
--scheduled-action-namescale-in
--schedule "at(2021-01-31T17:00:00
)" --scalable-target-action MaxCapacity=1
Recurring schedules using cron or rate expressions
You can set up a recurring schedule for a scheduled action using schedule expressions. Application Auto Scaling supports cron and rate formats for schedule expressions.
Example: To scale on a recurring schedule using a cron expression
You can specify a recurrence schedule, in UTC, using a cron expression. Call the
put-scheduled-action command against the scalable target.
Include the --schedule "cron(
option. The cron format that's supported by Application Auto Scaling consists of six
fields separated by
white spaces: [Minutes] [Hours] [Day_of_Month] [Month] [Day_of_Week] [Year]. For more
information, see Cron
expressions in the Amazon CloudWatch Events User Guide.
cron expression
)"
Here are some examples of cron expressions to help.
Minutes | Hours | Day of month | Month | Day of week | Year | Meaning |
---|---|---|---|---|---|---|
0 |
10 |
* |
* |
? |
* |
Run at 10:00 am (UTC) every day |
15 |
12 |
* |
* |
? |
* |
Run at 12:15 pm (UTC) every day |
0 |
18 |
? |
* |
MON-FRI |
* |
Run at 6:00 pm (UTC) every Monday through Friday |
0 |
8 |
1 |
* |
? |
* |
Run at 8:00 am (UTC) every 1st day of the month |
0/15 |
* |
* |
* |
? |
* |
Run every 15 minutes |
0/10 |
* |
? |
* |
MON-FRI |
* |
Run every 10 minutes Monday through Friday |
0/5 |
8-17 |
? |
* |
MON-FRI |
* |
Run every 5 minutes Monday through Friday between 8:00 am and 5:55 pm (UTC) |
The following is an example of adding a recurring schedule for a scheduled action using a cron expression.
On the specified schedule (every day at 9:00 AM UTC), if the value specified for
MinCapacity
is above the current capacity, Application Auto Scaling scales out to
MinCapacity
. If the value specified for MaxCapacity
is below
the current capacity, Application Auto Scaling scales in to MaxCapacity
.
On local Linux, macOS, or Unix machines:
aws application-autoscaling put-scheduled-action --service-namespace
appstream
\ --scalable-dimensionappstream:fleet:DesiredCapacity
\ --resource-idfleet/sample-fleet
\ --scheduled-action-namemy-recurring-action
\ --schedule "cron(0 9 * * ? *
)" \ --scalable-target-action MinCapacity=10
,MaxCapacity=50
On local Windows machines:
aws application-autoscaling put-scheduled-action --service-namespace
appstream
--scalable-dimensionappstream:fleet:DesiredCapacity
--resource-idfleet/sample-fleet
--scheduled-action-namemy-recurring-action
--schedule "cron(0 9 * * ? *
)" --scalable-target-action MinCapacity=10
,MaxCapacity=50
Example: To scale on a recurring schedule using a rate expression
Rate expressions schedule scaling at a regular rate. Call the put-scheduled-action command against the scalable target.
Include the --schedule "rate(
option.
The value must be a positive integer. The unit can be value unit
)"minute
,
minutes
, hour
, hours
, day
, or
days
. For more information, see Rate expressions in the
Amazon CloudWatch Events User Guide.
The following is an example of adding a recurring schedule for a scheduled action using a rate expression.
On the specified schedule (every 5 hours), if the value specified for
MinCapacity
is above the current capacity, Application Auto Scaling scales out to
MinCapacity
. If the value specified for MaxCapacity
is below
the current capacity, Application Auto Scaling scales in to MaxCapacity
.
On local Linux, macOS, or Unix machines:
aws application-autoscaling put-scheduled-action --service-namespace
dynamodb
\ --scalable-dimensiondynamodb:table:WriteCapacityUnits
\ --resource-idtable/my-table
\ --scheduled-action-namemy-recurring-action
\ --schedule "rate(5 hours
)" \ --start-time2021-01-30T12:00:00
\ --end-time2021-01-31T22:00:00
\ --scalable-target-action MinCapacity=30
,MaxCapacity=100
On local Windows machines:
aws application-autoscaling put-scheduled-action --service-namespace
dynamodb
--scalable-dimensiondynamodb:table:WriteCapacityUnits
--resource-idtable/my-table
--scheduled-action-namemy-recurring-action
--schedule "rate(5 hours
)" --start-time2021-01-30T12:00:00
--end-time2021-01-31T22:00:00
--scalable-target-action MinCapacity=30
,MaxCapacity=100
Describe scheduled actions
You can describe all scheduled actions for the specified service namespace using the following describe-scheduled-actions command.
aws application-autoscaling describe-scheduled-actions --service-namespace
ecs
The following is example output.
{
"ScheduledActions": [
{
"ScheduledActionARN": "<arn>",
"ServiceNamespace": "ecs",
"CreationTime": 1596319455.951,
"ScalableDimension": "ecs:service:DesiredCount",
"Schedule": "at(2021-01-31T17:00:00)",
"ScalableTargetAction": {
"MaxCapacity": 1
},
"ScheduledActionName": "scale-in",
"ResourceId": "service/default/web-app"
}
]
}
Delete a scheduled action
When you are finished with a scheduled action, you can delete it using the delete-scheduled-action command.
On local Linux, macOS, or Unix machines:
aws application-autoscaling delete-scheduled-action --service-namespace
ec2
\ --scalable-dimensionec2:spot-fleet-request:TargetCapacity
\ --resource-idspot-fleet-request/sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE
\ --scheduled-action-namemy-spot-fleet-action
On local Windows machines:
aws application-autoscaling delete-scheduled-action --service-namespace
ec2
--scalable-dimensionec2:spot-fleet-request:TargetCapacity
--resource-idspot-fleet-request/sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE
--scheduled-action-namemy-spot-fleet-action