aws-cdk-lib.aws_autoscaling.LifecycleHook

class LifecycleHook (construct)

LanguageType name
.NETAmazon.CDK.AWS.AutoScaling.LifecycleHook
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsautoscaling#LifecycleHook
Javasoftware.amazon.awscdk.services.autoscaling.LifecycleHook
Pythonaws_cdk.aws_autoscaling.LifecycleHook
TypeScript (source)aws-cdk-lib » aws_autoscaling » LifecycleHook

Implements IConstruct, IDependable, IResource, ILifecycleHook

Define a life cycle hook.

Example

// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from 'aws-cdk-lib';
import { aws_autoscaling as autoscaling } from 'aws-cdk-lib';
import { aws_iam as iam } from 'aws-cdk-lib';

declare const autoScalingGroup: autoscaling.AutoScalingGroup;
declare const lifecycleHookTarget: autoscaling.ILifecycleHookTarget;
declare const role: iam.Role;
const lifecycleHook = new autoscaling.LifecycleHook(this, 'MyLifecycleHook', {
  autoScalingGroup: autoScalingGroup,
  lifecycleTransition: autoscaling.LifecycleTransition.INSTANCE_LAUNCHING,

  // the properties below are optional
  defaultResult: autoscaling.DefaultResult.CONTINUE,
  heartbeatTimeout: cdk.Duration.minutes(30),
  lifecycleHookName: 'lifecycleHookName',
  notificationMetadata: 'notificationMetadata',
  notificationTarget: lifecycleHookTarget,
  role: role,
});

Initializer

new LifecycleHook(scope: Construct, id: string, props: LifecycleHookProps)

Parameters

  • scope Construct
  • id string
  • props LifecycleHookProps

Construct Props

NameTypeDescription
autoScalingGroupIAutoScalingGroupThe AutoScalingGroup to add the lifecycle hook to.
lifecycleTransitionLifecycleTransitionThe state of the Amazon EC2 instance to which you want to attach the lifecycle hook.
defaultResult?DefaultResultThe action the Auto Scaling group takes when the lifecycle hook timeout elapses or if an unexpected failure occurs.
heartbeatTimeout?DurationMaximum time between calls to RecordLifecycleActionHeartbeat for the hook.
lifecycleHookName?stringName of the lifecycle hook.
notificationMetadata?stringAdditional data to pass to the lifecycle hook target.
notificationTarget?ILifecycleHookTargetThe target of the lifecycle hook.
role?IRoleThe role that allows publishing to the notification target.

autoScalingGroup

Type: IAutoScalingGroup

The AutoScalingGroup to add the lifecycle hook to.


lifecycleTransition

Type: LifecycleTransition

The state of the Amazon EC2 instance to which you want to attach the lifecycle hook.


defaultResult?

Type: DefaultResult (optional, default: Continue)

The action the Auto Scaling group takes when the lifecycle hook timeout elapses or if an unexpected failure occurs.


heartbeatTimeout?

Type: Duration (optional, default: No heartbeat timeout.)

Maximum time between calls to RecordLifecycleActionHeartbeat for the hook.

If the lifecycle hook times out, perform the action in DefaultResult.


lifecycleHookName?

Type: string (optional, default: Automatically generated name.)

Name of the lifecycle hook.


notificationMetadata?

Type: string (optional, default: No metadata.)

Additional data to pass to the lifecycle hook target.


notificationTarget?

Type: ILifecycleHookTarget (optional, default: No target.)

The target of the lifecycle hook.


role?

Type: IRole (optional, default: A role will be created if a target is provided. Otherwise, no role is created.)

The role that allows publishing to the notification target.

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
lifecycleHookNamestringThe name of this lifecycle hook.
nodeNodeThe tree node.
roleIRoleThe role that allows the ASG to publish to the notification target.
stackStackThe stack in which this resource is defined.

env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


lifecycleHookName

Type: string

The name of this lifecycle hook.


node

Type: Node

The tree node.


role

Type: IRole

The role that allows the ASG to publish to the notification target.


stack

Type: Stack

The stack in which this resource is defined.

Methods

NameDescription
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
toString()Returns a string representation of this construct.

applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.