AWS Fundamentals Logo
AWS Fundamentals
L1 ConstructAWS::AutoScaling::LifecycleHook

CfnLifecycleHook

The `AWS::AutoScaling::LifecycleHook` resource specifies lifecycle hooks for an Auto Scaling group. These hooks let you create solutions that are aware of events in the Auto Scaling instance lifecycle, and then perform a custom action on instances when the corresponding lifecycle event occurs. A lifecycle hook provides a specified amount of time (one hour by default) to wait for the action to complete before the instance transitions to the next state. Use lifecycle hooks to prepare new instances for use or to delay them from being registered behind a load balancer before their configuration has been applied completely. You can also use lifecycle hooks to prepare running instances to be terminated by, for example, downloading logs or other data. For more information, see [Amazon EC2 Auto Scaling lifecycle hooks](https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html) in the *Amazon EC2 Auto Scaling User Guide* .

Import

import { CfnLifecycleHook } from 'aws-cdk-lib/aws-autoscaling';

Or use the module namespace:

import * as autoscaling from 'aws-cdk-lib/aws-autoscaling';
// autoscaling.CfnLifecycleHook

Properties

Configuration passed to the constructor as CfnLifecycleHookProps.

autoScalingGroupNameRequired
string | IAutoScalingGroupRef

The name of the Auto Scaling group.

lifecycleTransitionRequired
string

The lifecycle transition. For Auto Scaling groups, there are two major lifecycle transitions. - To create a lifecycle hook for scale-out events, specify `autoscaling:EC2_INSTANCE_LAUNCHING` . - To create a lifecycle hook for scale-in events, specify `autoscaling:EC2_INSTANCE_TERMINATING` .

defaultResultOptional
string

The action the Auto Scaling group takes when the lifecycle hook timeout elapses or if an unexpected failure occurs. The default value is `ABANDON` . Valid values: `CONTINUE` | `ABANDON`

heartbeatTimeoutOptional
number

The maximum time, in seconds, that can elapse before the lifecycle hook times out. The range is from `30` to `7200` seconds. The default value is `3600` seconds (1 hour).

lifecycleHookNameOptional
string

The name of the lifecycle hook.

notificationMetadataOptional
string

Additional information that you want to include any time Amazon EC2 Auto Scaling sends a message to the notification target.

notificationTargetArnOptional
string | ITopicRef | IQueueRef

The Amazon Resource Name (ARN) of the notification target that Amazon EC2 Auto Scaling sends notifications to when an instance is in a wait state for the lifecycle hook. You can specify an Amazon SNS topic or an Amazon SQS queue.

roleArnOptional
string | IRoleRef

The ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target. For information about creating this role, see [Prepare to add a lifecycle hook to your Auto Scaling group](https://docs.aws.amazon.com/autoscaling/ec2/userguide/prepare-for-lifecycle-notifications.html) in the *Amazon EC2 Auto Scaling User Guide* . Valid only if the notification target is an Amazon SNS topic or an Amazon SQS queue.

CloudFormation Resource

This L1 construct maps directly to the following CloudFormation resource type.

Learn AWS the Practical Way

Our bi-weekly newsletter teaches hands-on AWS fundamentals. No certification fluff - just practical knowledge.

Subscribe to Newsletter