Create scheduled actions for Application Auto Scaling using the AWS CLI - Application Auto Scaling

Create scheduled actions for Application Auto Scaling using the AWS CLI

The following examples show how to create scheduled actions using the AWS CLI put-scheduled-action command. When you specify the new capacity, you can specify a minimum capacity, a maximum capacity, or both.

These examples use scalable targets for a few of the services that integrate with Application Auto Scaling. To use a different scalable target, specify its namespace in --service-namespace, its scalable dimension in --scalable-dimension, and its resource ID in --resource-id.

When using the AWS CLI, remember that your commands run in the AWS Region configured for your profile. If you want to run the commands in a different Region, either change the default Region for your profile, or use the --region parameter with the command.

Create a scheduled action that occurs only once

To automatically scale your scalable target one time only, at a specified date and time, use the --schedule "at(yyyy-mm-ddThh:mm:ss)" option.

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 (10:00 PM UTC on March 31, 2021), if the value specified for MinCapacity is above the current capacity, Application Auto Scaling scales out to MinCapacity.

Linux, macOS, or Unix

aws application-autoscaling put-scheduled-action --service-namespace custom-resource \ --scalable-dimension custom-resource:ResourceType:Property \ --resource-id file://~/custom-resource-id.txt \ --scheduled-action-name scale-out \ --schedule "at(2021-03-31T22:00:00)" \ --scalable-target-action MinCapacity=3

Windows

aws application-autoscaling put-scheduled-action --service-namespace custom-resource ^ --scalable-dimension custom-resource:ResourceType:Property ^ --resource-id file://~/custom-resource-id.txt ^ --scheduled-action-name scale-out ^ --schedule "at(2021-03-31T22:00:00)" ^ --scalable-target-action MinCapacity=3

When this scheduled action runs, if the maximum capacity is less than the value specified for minimum capacity, you must specify a new minimum and maximum capacity, and not just the minimum capacity.

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 (10:30 PM UTC on March 31, 2021), if the value specified for MaxCapacity is below the current capacity, Application Auto Scaling scales in to MaxCapacity.

Linux, macOS, or Unix

aws application-autoscaling put-scheduled-action --service-namespace custom-resource \ --scalable-dimension custom-resource:ResourceType:Property \ --resource-id file://~/custom-resource-id.txt \ --scheduled-action-name scale-in \ --schedule "at(2021-03-31T22:30:00)" \ --scalable-target-action MinCapacity=0,MaxCapacity=0

Windows

aws application-autoscaling put-scheduled-action --service-namespace custom-resource ^ --scalable-dimension custom-resource:ResourceType:Property ^ --resource-id file://~/custom-resource-id.txt ^ --scheduled-action-name scale-in ^ --schedule "at(2021-03-31T22:30:00)" ^ --scalable-target-action MinCapacity=0,MaxCapacity=0

Create a scheduled action that runs on a recurring interval

To schedule scaling at a recurring interval, use the --schedule "rate(value unit)" option. The value must be a positive integer. The unit can be minute, minutes, hour, hours, day, or days. For more information, see Rate expressions in the Amazon EventBridge User Guide.

The following is an example of a scheduled action that uses a rate expression.

On the specified schedule (every 5 hours starting on January 30, 2021 at 12:00 PM UTC and ending on January 31, 2021 at 10:00 PM 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.

Linux, macOS, or Unix

aws application-autoscaling put-scheduled-action --service-namespace ecs \ --scalable-dimension ecs:service:DesiredCount \ --resource-id service/my-cluster/my-service \ --scheduled-action-name my-recurring-action \ --schedule "rate(5 hours)" \ --start-time 2021-01-30T12:00:00 \ --end-time 2021-01-31T22:00:00 \ --scalable-target-action MinCapacity=3,MaxCapacity=10

Windows

aws application-autoscaling put-scheduled-action --service-namespace ecs ^ --scalable-dimension ecs:service:DesiredCount ^ --resource-id service/my-cluster/my-service ^ --scheduled-action-name my-recurring-action ^ --schedule "rate(5 hours)" ^ --start-time 2021-01-30T12:00:00 ^ --end-time 2021-01-31T22:00:00 ^ --scalable-target-action MinCapacity=3,MaxCapacity=10

Create a scheduled action that runs on a recurring schedule

To schedule scaling on a recurring schedule, use the --schedule "cron(fields)" option. For more information, see Schedule recurring scaling actions using Application Auto Scaling.

The following is an example of a scheduled action that uses 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.

Linux, macOS, or Unix

aws application-autoscaling put-scheduled-action --service-namespace appstream \ --scalable-dimension appstream:fleet:DesiredCapacity \ --resource-id fleet/sample-fleet \ --scheduled-action-name my-recurring-action \ --schedule "cron(0 9 * * ? *)" \ --scalable-target-action MinCapacity=10,MaxCapacity=50

Windows

aws application-autoscaling put-scheduled-action --service-namespace appstream ^ --scalable-dimension appstream:fleet:DesiredCapacity ^ --resource-id fleet/sample-fleet ^ --scheduled-action-name my-recurring-action ^ --schedule "cron(0 9 * * ? *)" ^ --scalable-target-action MinCapacity=10,MaxCapacity=50

Create a one-time scheduled action that specifies a time zone

Scheduled actions are set to the UTC time zone by default. To specify a different time zone, include the --timezone option and specify the canonical name for the time zone (America/New_York, for example). For more information, see https://www.joda.org/joda-time/timezones.html, which provides information about the IANA time zones that are supported when calling put-scheduled-action.

The following is an example that uses the --timezone option when creating a scheduled action to scale capacity at a specific date and time.

At the date and time specified for --schedule (5:00 PM local time on January 31, 2021), 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.

Linux, macOS, or Unix

aws application-autoscaling put-scheduled-action --service-namespace comprehend \ --scalable-dimension comprehend:document-classifier-endpoint:DesiredInferenceUnits \ --resource-id arn:aws:comprehend:us-west-2:123456789012:document-classifier-endpoint/EXAMPLE \ --scheduled-action-name my-one-time-action \ --schedule "at(2021-01-31T17:00:00)" --timezone "America/New_York" \ --scalable-target-action MinCapacity=1,MaxCapacity=3

Windows

aws application-autoscaling put-scheduled-action --service-namespace comprehend ^ --scalable-dimension comprehend:document-classifier-endpoint:DesiredInferenceUnits ^ --resource-id arn:aws:comprehend:us-west-2:123456789012:document-classifier-endpoint/EXAMPLE ^ --scheduled-action-name my-one-time-action ^ --schedule "at(2021-01-31T17:00:00)" --timezone "America/New_York" ^ --scalable-target-action MinCapacity=1,MaxCapacity=3

Create a recurring scheduled action that specifies a time zone

The following is an example that uses the --timezone option when creating a recurring scheduled action to scale capacity. For more information, see Schedule recurring scaling actions using Application Auto Scaling.

On the specified schedule (every Monday through Friday at 6:00 PM local time), 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.

Linux, macOS, or Unix

aws application-autoscaling put-scheduled-action --service-namespace lambda \ --scalable-dimension lambda:function:ProvisionedConcurrency \ --resource-id function:my-function:BLUE \ --scheduled-action-name my-recurring-action \ --schedule "cron(0 18 ? * MON-FRI *)" --timezone "Etc/GMT+9" \ --scalable-target-action MinCapacity=10,MaxCapacity=50

Windows

aws application-autoscaling put-scheduled-action --service-namespace lambda ^ --scalable-dimension lambda:function:ProvisionedConcurrency ^ --resource-id function:my-function:BLUE ^ --scheduled-action-name my-recurring-action ^ --schedule "cron(0 18 ? * MON-FRI *)" --timezone "Etc/GMT+9" ^ --scalable-target-action MinCapacity=10,MaxCapacity=50