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, AWS
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 sample update policies for
rolling updates in Auto scaling template
snippets.
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
} }
YAML
Type: AWS::AutoScaling::ScheduledAction Properties: AutoScalingGroupName:
String
DesiredCapacity:Integer
EndTime:String
MaxSize:Integer
MinSize:Integer
Recurrence:String
StartTime:String
Properties
AutoScalingGroupName
-
The name or Amazon Resource Name (ARN) of the Auto Scaling group.
Required: Yes
Type: String
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.
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 in UTC for the recurring schedule to end. For example,
"2019-06-01T00:00:00Z"
.Required: No
Type: String
Update requires: No interruption
MaxSize
-
The maximum size of the Auto Scaling group.
You must specify at least one of the following properties:
MaxSize
,MinSize
, orDesiredCapacity
.Required: Conditional
Type: Integer
Update requires: No interruption
MinSize
-
The minimum size of the Auto Scaling group.
You must specify at least one of the following properties:
MaxSize
,MinSize
, orDesiredCapacity
.Required: Conditional
Type: Integer
Update requires: No interruption
Recurrence
-
The recurring schedule for this action, in Unix cron syntax format. For more information about cron syntax, see Crontab
. Specifying the
StartTime
andEndTime
properties withRecurrence
property forms the start and stop boundaries of the recurring action.Required: No
Type: String
Update requires: No interruption
StartTime
-
The date and time in UTC for this action to start. For example,
"2019-06-01T00:00:00Z"
.Required: No
Type: String
Update requires: No interruption
Return values
Ref
When the logical ID of this resource is provided to the Ref
intrinsic
function, Ref
returns the resource name. For example:
mystack-myscheduledaction-NT5EUXTNTXXD
.
For more information about using the Ref
function, see Ref.
Examples
The following example schedule scaling actions for an Auto Scaling group.
Scheduled scaling action
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.
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 * * *"