Amazon EC2 Auto Scaling AutoScalingGroup LifecycleHookSpecification
The
LifecycleHookSpecification property type defines lifecycle hooks for an Amazon EC2 Auto Scaling group,
which specify actions to perform when Amazon EC2 Auto Scaling launches or terminates
instances.
For more information, see
Amazon EC2 Auto Scaling Lifecycle Hooks in the Amazon EC2 Auto Scaling User Guide.
The LifecycleHookSpecificationList property of the AWS::AutoScaling::AutoScalingGroup resource contains a list of LifecycleHookSpecification property types.
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
JSON
{ "DefaultResult" :String, "HeartbeatTimeout" :Integer, "LifecycleHookName" :String, "LifecycleTransition" :String, "NotificationMetadata" :String, "NotificationTargetARN" :String, "RoleARN" :String}
YAML
DefaultResult:StringHeartbeatTimeout:IntegerLifecycleHookName:StringLifecycleTransition:StringNotificationMetadata:StringNotificationTargetARN:StringRoleARN:String
Properties
For more information about each property, including constraints, see PutLifecycleHook in the Amazon EC2 Auto Scaling API Reference.
DefaultResult-
The action that the Auto Scaling group should take when the lifecycle hook timeout elapses or if an unexpected failure occurs.
Valid values:
CONTINUE,ABANDON(default)Required: No
Type: String
Update requires: No interruption
HeartbeatTimeout-
The maximum time, in seconds, that can elapse before the lifecycle hook times out. If the lifecycle hook times out, Auto Scaling performs the default action.
Required: No
Type: Integer
Update requires: No interruption
LifecycleHookName-
The name of the lifecycle hook. For constraints, see PutLifecycleHook in the Amazon EC2 Auto Scaling API Reference.
Required: Yes
Type: String
Update requires: No interruption
LifecycleTransition-
The state of the EC2 instance to attach the lifecycle hook to. For a list of lifecycle hook types, see DescribeLifecycleHookTypes in the Amazon EC2 Auto Scaling API Reference.
Required: Yes
Type: String
Update requires: No interruption
NotificationMetadata-
Additional information to include when Amazon EC2 Auto Scaling sends a message to the notification target. For constraints, see PutLifecycleHook in the Amazon EC2 Auto Scaling API Reference.
Required: No
Type: String
Update requires: No interruption
NotificationTargetARN-
The Amazon Resource Name (ARN) of the target that Amazon EC2 Auto Scaling sends notifications to when an instance is in the transition state for the lifecycle hook. The notification target can be either an Amazon SQS queue or an Amazon SNS topic.
Required: No
Type: String
Update requires: No interruption
RoleARN-
The ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target.
Required: No
Type: String
Update requires: No interruption
Examples
The following snippet specifies a lifecycle hook for an AWS::AutoScaling::AutoScalingGroup resource.
JSON
{ "Resources": { "ASG": { "Type": "AWS::AutoScaling::AutoScalingGroup", "Properties": { "AvailabilityZones": [ { "Ref": "AZParameter" } ], "VPCZoneIdentifier": { "Ref": "Subnets" }, "DesiredCapacity": "0", "MaxSize": "0", "MinSize": "0", "LaunchConfigurationName": { "Ref": "LC" }, "LifecycleHookSpecificationList": [ { "LifecycleTransition": "autoscaling: EC2_INSTANCE_LAUNCHING", "LifecycleHookName": "myFirstLifecycleHook", "HeartbeatTimeout": 4800, "NotificationTargetARN": { "Fn::GetAtt": [ "SQS", "Arn" ] } } ] } }, "SQS": { "Type": "AWS::SQS::Queue" } } }
YAML
Resources: ASG: Type: 'AWS::AutoScaling::AutoScalingGroup' Properties: AvailabilityZones: - !Ref AZParameter VPCZoneIdentifier: !Ref Subnets DesiredCapacity: '0' MaxSize: '0' MinSize: '0' LaunchConfigurationName: !Ref LC LifecycleHookSpecificationList: - LifecycleTransition: 'autoscaling:EC2_INSTANCE_LAUNCHING' LifecycleHookName: 'myFirstLifecycleHook' HeartbeatTimeout: 4800 NotificationTargetARN: !GetAtt SQS.Arn SQS: Type: 'AWS::SQS::Queue'
See Also
-
Amazon EC2 Auto Scaling Lifecycle Hooks in the Amazon EC2 Auto Scaling User Guide
-
PutLifecycleHook in the Amazon EC2 Auto Scaling API Reference
