Skip to content

Resource: awsAutoscalingLifecycleHook

Provides an AutoScaling Lifecycle Hook resource.

\~> NOTE: Terraform has two types of ways you can add lifecycle hooks - via the initialLifecycleHook attribute from the awsAutoscalingGroup resource, or via this one. Hooks added via this resource will not be added until the autoscaling group has been created, and depending on your capacity settings, after the initial instances have been launched, creating unintended behavior. If you need hooks to run on all instances, add them with initialLifecycleHook in awsAutoscalingGroup, but take care to not duplicate those hooks with this resource.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsAutoscalingGroupFoobar = new aws.autoscalingGroup.AutoscalingGroup(
  this,
  "foobar",
  {
    availabilityZones: ["us-west-2a"],
    healthCheckType: "EC2",
    name: "terraform-test-foobar5",
    tag: [
      {
        key: "Foo",
        propagateAtLaunch: true,
        value: "foo-bar",
      },
    ],
    terminationPolicies: ["OldestInstance"],
  }
);
const awsAutoscalingLifecycleHookFoobar =
  new aws.autoscalingLifecycleHook.AutoscalingLifecycleHook(this, "foobar_1", {
    autoscalingGroupName: awsAutoscalingGroupFoobar.name,
    defaultResult: "CONTINUE",
    heartbeatTimeout: 2000,
    lifecycleTransition: "autoscaling:EC2_INSTANCE_LAUNCHING",
    name: "foobar",
    notificationMetadata: '${jsonencode({\n    foo = "bar"\n  })}',
    notificationTargetArn: "arn:aws:sqs:us-east-1:444455556666:queue1*",
    roleArn: "arn:aws:iam::123456789012:role/S3Access",
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
awsAutoscalingLifecycleHookFoobar.overrideLogicalId("foobar");

Argument Reference

The following arguments are supported:

  • name - (Required) Name of the lifecycle hook.
  • autoscalingGroupName - (Required) Name of the Auto Scaling group to which you want to assign the lifecycle hook
  • defaultResult - (Optional) Defines the action the Auto Scaling group should take when the lifecycle hook timeout elapses or if an unexpected failure occurs. The value for this parameter can be either CONTINUE or ABANDON. The default value for this parameter is ABANDON.
  • heartbeatTimeout - (Optional) Defines the amount of time, in seconds, that can elapse before the lifecycle hook times out. When the lifecycle hook times out, Auto Scaling performs the action defined in the DefaultResult parameter
  • lifecycleTransition - (Required) Instance state to which you want to attach the lifecycle hook. For a list of lifecycle hook types, see describe-lifecycle-hook-types
  • notificationMetadata - (Optional) Contains additional information that you want to include any time Auto Scaling sends a message to the notification target.
  • notificationTargetArn - (Optional) ARN of the notification target that Auto Scaling will use to notify you when an instance is in the transition state for the lifecycle hook. This ARN target can be either an SQS queue or an SNS topic.
  • roleArn - (Optional) ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target.

Attributes Reference

No additional attributes are exported.

Import

AutoScaling Lifecycle Hooks can be imported using the role autoscaling_group_name and name separated by /.

$ terraform import aws_autoscaling_lifecycle_hook.test-lifecycle-hook asg-name/lifecycle-hook-name