InstanceLifecyclePolicy Struct
Instance lifecycle policy for an Auto Scaling group.
| Source | aws-autoscaling/lib/auto-scaling-group.ts |
|---|---|
| Type last changed |
Example
ts
declare const vpc: ec2.Vpc;
declare const instanceType: ec2.InstanceType;
declare const machineImage: ec2.IMachineImage;
const asg = new autoscaling.AutoScalingGroup(this, 'ASG', {
vpc,
instanceType,
machineImage,
// Configure instance lifecycle policy
instanceLifecyclePolicy: {
retentionTriggers: {
terminateHookAbandon: autoscaling.TerminateHookAbandonAction.RETAIN,
},
},
});
// Add termination lifecycle hook (required for the policy to take effect)
asg.addLifecycleHook('TerminationHook', {
lifecycleTransition: autoscaling.LifecycleTransition.INSTANCE_TERMINATING,
});
python
# 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
)
java
Vpc vpc;
InstanceType instanceType;
IMachineImage machineImage;
AutoScalingGroup asg = AutoScalingGroup.Builder.create(this, "ASG")
.vpc(vpc)
.instanceType(instanceType)
.machineImage(machineImage)
// Configure instance lifecycle policy
.instanceLifecyclePolicy(InstanceLifecyclePolicy.builder()
.retentionTriggers(RetentionTriggers.builder()
.terminateHookAbandon(TerminateHookAbandonAction.RETAIN)
.build())
.build())
.build();
// Add termination lifecycle hook (required for the policy to take effect)
asg.addLifecycleHook("TerminationHook", BasicLifecycleHookProps.builder()
.lifecycleTransition(LifecycleTransition.INSTANCE_TERMINATING)
.build());
csharp
// Install: dotnet add package Amazon.CDK.Lib
Vpc vpc;
InstanceType instanceType;
IMachineImage machineImage;
var asg = new AutoScalingGroup(this, "ASG", new AutoScalingGroupProps {
Vpc = vpc,
InstanceType = instanceType,
MachineImage = machineImage,
// Configure instance lifecycle policy
InstanceLifecyclePolicy = new InstanceLifecyclePolicy {
RetentionTriggers = new RetentionTriggers {
TerminateHookAbandon = TerminateHookAbandonAction.RETAIN
}
}
});
// Add termination lifecycle hook (required for the policy to take effect)
asg.AddLifecycleHook("TerminationHook", new BasicLifecycleHookProps {
LifecycleTransition = LifecycleTransition.INSTANCE_TERMINATING
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
var vpc Vpc
var instanceType InstanceType
var machineImage IMachineImage
asg := autoscaling.NewAutoScalingGroup(this, jsii.String("ASG"), &AutoScalingGroupProps{
Vpc: Vpc,
InstanceType: InstanceType,
MachineImage: MachineImage,
// Configure instance lifecycle policy
InstanceLifecyclePolicy: &InstanceLifecyclePolicy{
RetentionTriggers: &RetentionTriggers{
TerminateHookAbandon: autoscaling.TerminateHookAbandonAction_RETAIN,
},
},
})
// Add termination lifecycle hook (required for the policy to take effect)
asg.addLifecycleHook(jsii.String("TerminationHook"), &BasicLifecycleHookProps{
LifecycleTransition: autoscaling.LifecycleTransition_INSTANCE_TERMINATING,
})
Properties
retentionTriggersoptionalRetentionTriggersretention_triggersoptionalRetentionTriggersretentionTriggersoptionalRetentionTriggersRetentionTriggersoptionalRetentionTriggersRetentionTriggersoptionalRetentionTriggers #Retention triggers for the instance lifecycle policy.
Default: No retention triggers configured