# InstanceLifecyclePolicy

Instance lifecycle policy for an Auto Scaling group.

- Source: [`aws-autoscaling/lib/auto-scaling-group.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-autoscaling/lib/auto-scaling-group.ts#L1402)
- Type last changed: v2.245.0 · 27 Mar 2026

## Example

TypeScript:

```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:

```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:

```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());
```

C# / .NET:

```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
});
```

Golang:

```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

- `retentionTriggers`: [RetentionTriggers](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.RetentionTriggers.html) — Retention triggers for the instance lifecycle policy.

  **Default:** No retention triggers configured
