LifecycleTransition

class aws_cdk.aws_autoscaling.LifecycleTransition(*values)

Bases: Enum

What instance transition to attach the hook to.

ExampleMetadata:

infused

Example:

# vpc: ec2.Vpc
# instance_type: ec2.InstanceType
# machine_image: ec2.IMachineImage


asg = autoscaling.AutoScalingGroup(self, "ASG",
    vpc=vpc,
    instance_type=instance_type,
    machine_image=machine_image,

    # Configure instance lifecycle policy
    instance_lifecycle_policy=autoscaling.InstanceLifecyclePolicy(
        retention_triggers=autoscaling.RetentionTriggers(
            terminate_hook_abandon=autoscaling.TerminateHookAbandonAction.RETAIN
        )
    )
)

# Add termination lifecycle hook (required for the policy to take effect)
asg.add_lifecycle_hook("TerminationHook",
    lifecycle_transition=autoscaling.LifecycleTransition.INSTANCE_TERMINATING
)

Attributes

INSTANCE_LAUNCHING

Execute the hook when an instance is about to be added.

INSTANCE_TERMINATING

Execute the hook when an instance is about to be terminated.