class LifecycleHook (construct)
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.AutoScaling.LifecycleHook |
![]() | github.com/aws/aws-cdk-go/awscdk/v2/awsautoscaling#LifecycleHook |
![]() | software.amazon.awscdk.services.autoscaling.LifecycleHook |
![]() | aws_cdk.aws_autoscaling.LifecycleHook |
![]() | aws-cdk-lib » aws_autoscaling » LifecycleHook |
Implements
IConstruct
, IDependable
, IResource
, ILifecycle
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
Lifecycle
Hook Props
Construct Props
Name | Type | Description |
---|---|---|
auto | IAuto | The AutoScalingGroup to add the lifecycle hook to. |
lifecycle | Lifecycle | The state of the Amazon EC2 instance to which you want to attach the lifecycle hook. |
default | Default | The action the Auto Scaling group takes when the lifecycle hook timeout elapses or if an unexpected failure occurs. |
heartbeat | Duration | Maximum time between calls to RecordLifecycleActionHeartbeat for the hook. |
lifecycle | string | Name of the lifecycle hook. |
notification | string | Additional data to pass to the lifecycle hook target. |
notification | ILifecycle | The target of the lifecycle hook. |
role? | IRole | The role that allows publishing to the notification target. |
autoScalingGroup
Type:
IAuto
The AutoScalingGroup to add the lifecycle hook to.
lifecycleTransition
Type:
Lifecycle
The state of the Amazon EC2 instance to which you want to attach the lifecycle hook.
defaultResult?
Type:
Default
(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:
ILifecycle
(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
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
lifecycle | string | The name of this lifecycle hook. |
node | Node | The tree node. |
role | IRole | The role that allows the ASG to publish to the notification target. |
stack | Stack | The stack in which this resource is defined. |
env
Type:
Resource
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
Name | Description |
---|---|
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
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.