# BasicLifecycleHookProps

Basic properties for a lifecycle hook.

Used as argument in: [IAutoScalingGroup.addLifecycleHook](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.IAutoScalingGroup.html#addlifecyclehook)

- Source: [`aws-autoscaling/lib/lifecycle-hook.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-autoscaling/lib/lifecycle-hook.ts#L15)
- Type last changed: v2.2.0 · 15 Dec 2021

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

- `defaultResult`: [DefaultResult](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.DefaultResult.html) = Continue — The action the Auto Scaling group takes when the lifecycle hook timeout elapses or if an unexpected failure occurs.

- `heartbeatTimeout`: [Duration](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Duration.html) — Maximum time between calls to RecordLifecycleActionHeartbeat for the hook.

  **Default:** No heartbeat timeout.

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

- `lifecycleHookName`: string — Name of the lifecycle hook.

  **Default:** Automatically generated name.

- `lifecycleTransition`: [LifecycleTransition](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.LifecycleTransition.html) (required) — The state of the Amazon EC2 instance to which you want to attach the lifecycle hook.

- `notificationMetadata`: string — Additional data to pass to the lifecycle hook target.

  **Default:** No metadata.

- `notificationTarget`: [ILifecycleHookTarget](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_autoscaling.ILifecycleHookTarget.html) — The target of the lifecycle hook.

  **Default:** No target.

- `role`: [IRole](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IRole.html) — The role that allows publishing to the notification target.

  **Default:** A role will be created if a target is provided. Otherwise, no role is created.
