AWS::AutoScaling::ScheduledAction
The AWS::AutoScaling::ScheduledAction
resource specifies an Amazon EC2 Auto
Scaling scheduled action so that the Auto Scaling group can change the number of instances
available for your application in response to predictable load changes.
When you update a stack with an Auto Scaling group and scheduled action, CloudFormation
always sets the min size, max size, and desired capacity properties of your group to the
values that are defined in the AWS::AutoScaling::AutoScalingGroup
section of your
template. However, you might not want CloudFormation to do that when you have a scheduled
action in effect. You can use an UpdatePolicy
attribute to prevent CloudFormation from changing the min size, max size, or desired
capacity property values during a stack update unless you modified the individual values in
your template. If you have rolling updates enabled, before you can update the Auto Scaling
group, you must suspend scheduled actions by specifying an UpdatePolicy
attribute for the Auto Scaling group. You can find a sample update policy for
rolling updates in Configure Amazon EC2
Auto Scaling resources.
For more information, see Scheduled scaling and Suspending and resuming scaling processes in the Amazon EC2 Auto Scaling User Guide.
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::AutoScaling::ScheduledAction", "Properties" : { "AutoScalingGroupName" :
String
, "DesiredCapacity" :Integer
, "EndTime" :String
, "MaxSize" :Integer
, "MinSize" :Integer
, "Recurrence" :String
, "StartTime" :String
, "TimeZone" :String
} }
YAML
Type: AWS::AutoScaling::ScheduledAction Properties: AutoScalingGroupName:
String
DesiredCapacity:Integer
EndTime:String
MaxSize:Integer
MinSize:Integer
Recurrence:String
StartTime:String
TimeZone:String
Properties
AutoScalingGroupName
-
The name of the Auto Scaling group.
Required: Yes
Type: String
Pattern:
[\u0020-\uD7FF\uE000-\uFFFD\uD800\uDC00-\uDBFF\uDFFF\r\n\t]*
Minimum:
1
Maximum:
255
Update requires: Replacement
DesiredCapacity
-
The desired capacity is the initial capacity of the Auto Scaling group after the scheduled action runs and the capacity it attempts to maintain. It can scale beyond this capacity if you add more scaling conditions.
Note
You must specify at least one of the following properties:
MaxSize
,MinSize
, orDesiredCapacity
.Required: Conditional
Type: Integer
Update requires: No interruption
EndTime
-
The date and time for the recurring schedule to end, in UTC. For example,
"2021-06-01T00:00:00Z"
.Required: No
Type: String
Update requires: No interruption
MaxSize
-
The maximum size of the Auto Scaling group.
Required: Conditional
Type: Integer
Update requires: No interruption
MinSize
-
The minimum size of the Auto Scaling group.
Required: Conditional
Type: Integer
Update requires: No interruption
Recurrence
-
The recurring schedule for this action. This format consists of five fields separated by white spaces: [Minute] [Hour] [Day_of_Month] [Month_of_Year] [Day_of_Week]. The value must be in quotes (for example,
"30 0 1 1,6,12 *"
). For more information about this format, see Crontab. When
StartTime
andEndTime
are specified withRecurrence
, they form the boundaries of when the recurring action starts and stops.Cron expressions use Universal Coordinated Time (UTC) by default.
Required: No
Type: String
Update requires: No interruption
StartTime
-
The date and time for this action to start, in YYYY-MM-DDThh:mm:ssZ format in UTC/GMT only and in quotes (for example,
"2021-06-01T00:00:00Z"
).If you specify
Recurrence
andStartTime
, Amazon EC2 Auto Scaling performs the action at this time, and then performs the action based on the specified recurrence.Required: No
Type: String
Update requires: No interruption
TimeZone
-
Specifies the time zone for a cron expression. If a time zone is not provided, UTC is used by default.
Valid values are the canonical names of the IANA time zones, derived from the IANA Time Zone Database (such as
Etc/GMT+9
orPacific/Tahiti
). For more information, see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones. Required: No
Type: String
Update requires: No interruption
Return values
Ref
When you pass the logical ID of this resource to the intrinsic Ref
function, Ref
returns the resource name. For example:
mystack-myscheduledaction-NT5EUXTNTXXD
.
For more information about using the Ref
function, see Ref
.
Fn::GetAtt
The Fn::GetAtt
intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.
For more information about using the Fn::GetAtt
intrinsic function, see Fn::GetAtt
.
ScheduledActionName
-
Returns the name of a scheduled action.
Examples
The following examples schedule scaling actions for an Auto Scaling group.
Scheduled actions that run on a recurring schedule
The following template snippet includes two scheduled actions that scale the number of
instances in an Auto Scaling group. The ScheduledActionOut
action starts at 7
AM every day and sets the Auto Scaling group to a minimum of five Amazon EC2 instances
with a maximum of 10. The ScheduledActionIn
action starts at 7 PM every day
and sets the Auto Scaling group to a minimum and maximum of one Amazon EC2 instance. The
time zone is not provided. As a result, these scheduled actions will recur in UTC time.
JSON
{ "Resources":{ "ScheduledActionOut":{ "Type":"AWS::AutoScaling::ScheduledAction", "Properties":{ "AutoScalingGroupName":{ "Ref":"myASG" }, "MaxSize":"10", "MinSize":"5", "Recurrence":"0 7 * * *" } }, "ScheduledActionIn":{ "Type":"AWS::AutoScaling::ScheduledAction", "Properties":{ "AutoScalingGroupName":{ "Ref":"myASG" }, "MaxSize":"1", "MinSize":"1", "Recurrence":"0 19 * * *" } } } }
YAML
--- Resources: ScheduledActionOut: Type: AWS::AutoScaling::ScheduledAction Properties: AutoScalingGroupName: !Ref myASG MaxSize: '10' MinSize: '5' Recurrence: "0 7 * * *" ScheduledActionIn: Type: AWS::AutoScaling::ScheduledAction Properties: AutoScalingGroupName: !Ref myASG MaxSize: '1' MinSize: '1' Recurrence: "0 19 * * *"
Scheduled scaling action that occurs only once
The following template snippet includes a one-time scheduled action. At the date and
time specified for StartTime
(4:00 PM UTC on March 31, 2021), if the group
currently has more than 1 instance, it scales in to 1 instance. If the group currently has
no instances, it scales out to 1 instance.
JSON
{ "Resources":{ "OneTimeScheduledAction":{ "Type":"AWS::AutoScaling::ScheduledAction", "Properties":{ "AutoScalingGroupName":{ "Ref":"myASG" }, "DesiredCapacity":"1", "StartTime":"2021-03-31T16:00:00Z" } } } }
YAML
--- Resources: OneTimeScheduledAction: Type: AWS::AutoScaling::ScheduledAction Properties: AutoScalingGroupName: !Ref myASG DesiredCapacity: '1' StartTime: '2021-03-31T16:00:00Z'
See also
-
You can find additional useful snippets in the following sections of the AWS CloudFormation User Guide:
-
For examples of Auto Scaling groups, see Configure Amazon EC2 Auto Scaling resources.
-
For examples of launch templates, see Create launch templates.
-
-
PutScheduledUpdateGroupAction in the Amazon EC2 Auto Scaling API Reference