Welcome to Pulumi Registry, your window into the cloud. Read the announcement.

AWS Classic

v4.25.0 published on Friday, Oct 15, 2021 by Pulumi

LifecycleHook

Provides an AutoScaling Lifecycle Hook resource.

NOTE: This provider has two types of ways you can add lifecycle hooks - via the initial_lifecycle_hook attribute from the aws.autoscaling.Group 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 initial_lifecycle_hook in aws.autoscaling.Group, but take care to not duplicate those hooks with this resource.

Example Usage

using Pulumi;
using Aws = Pulumi.Aws;

class MyStack : Stack
{
    public MyStack()
    {
        var foobarGroup = new Aws.AutoScaling.Group("foobarGroup", new Aws.AutoScaling.GroupArgs
        {
            AvailabilityZones = 
            {
                "us-west-2a",
            },
            HealthCheckType = "EC2",
            TerminationPolicies = 
            {
                "OldestInstance",
            },
            Tags = 
            {
                new Aws.AutoScaling.Inputs.GroupTagArgs
                {
                    Key = "Foo",
                    Value = "foo-bar",
                    PropagateAtLaunch = true,
                },
            },
        });
        var foobarLifecycleHook = new Aws.AutoScaling.LifecycleHook("foobarLifecycleHook", new Aws.AutoScaling.LifecycleHookArgs
        {
            AutoscalingGroupName = foobarGroup.Name,
            DefaultResult = "CONTINUE",
            HeartbeatTimeout = 2000,
            LifecycleTransition = "autoscaling:EC2_INSTANCE_LAUNCHING",
            NotificationMetadata = @"{
  ""foo"": ""bar""
}
",
            NotificationTargetArn = "arn:aws:sqs:us-east-1:444455556666:queue1*",
            RoleArn = "arn:aws:iam::123456789012:role/S3Access",
        });
    }

}
package main

import (
	"fmt"

	"github.com/pulumi/pulumi-aws/sdk/v4/go/aws/autoscaling"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		foobarGroup, err := autoscaling.NewGroup(ctx, "foobarGroup", &autoscaling.GroupArgs{
			AvailabilityZones: pulumi.StringArray{
				pulumi.String("us-west-2a"),
			},
			HealthCheckType: pulumi.String("EC2"),
			TerminationPolicies: pulumi.StringArray{
				pulumi.String("OldestInstance"),
			},
			Tags: autoscaling.GroupTagArray{
				&autoscaling.GroupTagArgs{
					Key:               pulumi.String("Foo"),
					Value:             pulumi.String("foo-bar"),
					PropagateAtLaunch: pulumi.Bool(true),
				},
			},
		})
		if err != nil {
			return err
		}
		_, err = autoscaling.NewLifecycleHook(ctx, "foobarLifecycleHook", &autoscaling.LifecycleHookArgs{
			AutoscalingGroupName:  foobarGroup.Name,
			DefaultResult:         pulumi.String("CONTINUE"),
			HeartbeatTimeout:      pulumi.Int(2000),
			LifecycleTransition:   pulumi.String("autoscaling:EC2_INSTANCE_LAUNCHING"),
			NotificationMetadata:  pulumi.String(fmt.Sprintf("%v%v%v", "{\n", "  \"foo\": \"bar\"\n", "}\n")),
			NotificationTargetArn: pulumi.String("arn:aws:sqs:us-east-1:444455556666:queue1*"),
			RoleArn:               pulumi.String("arn:aws:iam::123456789012:role/S3Access"),
		})
		if err != nil {
			return err
		}
		return nil
	})
}
import pulumi
import pulumi_aws as aws

foobar_group = aws.autoscaling.Group("foobarGroup",
    availability_zones=["us-west-2a"],
    health_check_type="EC2",
    termination_policies=["OldestInstance"],
    tags=[aws.autoscaling.GroupTagArgs(
        key="Foo",
        value="foo-bar",
        propagate_at_launch=True,
    )])
foobar_lifecycle_hook = aws.autoscaling.LifecycleHook("foobarLifecycleHook",
    autoscaling_group_name=foobar_group.name,
    default_result="CONTINUE",
    heartbeat_timeout=2000,
    lifecycle_transition="autoscaling:EC2_INSTANCE_LAUNCHING",
    notification_metadata="""{
  "foo": "bar"
}
""",
    notification_target_arn="arn:aws:sqs:us-east-1:444455556666:queue1*",
    role_arn="arn:aws:iam::123456789012:role/S3Access")
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const foobarGroup = new aws.autoscaling.Group("foobarGroup", {
    availabilityZones: ["us-west-2a"],
    healthCheckType: "EC2",
    terminationPolicies: ["OldestInstance"],
    tags: [{
        key: "Foo",
        value: "foo-bar",
        propagateAtLaunch: true,
    }],
});
const foobarLifecycleHook = new aws.autoscaling.LifecycleHook("foobarLifecycleHook", {
    autoscalingGroupName: foobarGroup.name,
    defaultResult: "CONTINUE",
    heartbeatTimeout: 2000,
    lifecycleTransition: "autoscaling:EC2_INSTANCE_LAUNCHING",
    notificationMetadata: `{
  "foo": "bar"
}
`,
    notificationTargetArn: "arn:aws:sqs:us-east-1:444455556666:queue1*",
    roleArn: "arn:aws:iam::123456789012:role/S3Access",
});

Create a LifecycleHook Resource

new LifecycleHook(name: string, args: LifecycleHookArgs, opts?: CustomResourceOptions);
@overload
def LifecycleHook(resource_name: str,
                  opts: Optional[ResourceOptions] = None,
                  autoscaling_group_name: Optional[str] = None,
                  default_result: Optional[str] = None,
                  heartbeat_timeout: Optional[int] = None,
                  lifecycle_transition: Optional[str] = None,
                  name: Optional[str] = None,
                  notification_metadata: Optional[str] = None,
                  notification_target_arn: Optional[str] = None,
                  role_arn: Optional[str] = None)
@overload
def LifecycleHook(resource_name: str,
                  args: LifecycleHookArgs,
                  opts: Optional[ResourceOptions] = None)
func NewLifecycleHook(ctx *Context, name string, args LifecycleHookArgs, opts ...ResourceOption) (*LifecycleHook, error)
public LifecycleHook(string name, LifecycleHookArgs args, CustomResourceOptions? opts = null)
name string
The unique name of the resource.
args LifecycleHookArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name str
The unique name of the resource.
args LifecycleHookArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name string
The unique name of the resource.
args LifecycleHookArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name string
The unique name of the resource.
args LifecycleHookArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.

LifecycleHook Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

The LifecycleHook resource accepts the following input properties:

AutoscalingGroupName string
The name of the Auto Scaling group to which you want to assign the lifecycle hook
LifecycleTransition string
The instance state to which you want to attach the lifecycle hook. For a list of lifecycle hook types, see describe-lifecycle-hook-types
DefaultResult string
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 int
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
Name string
The name of the lifecycle hook.
NotificationMetadata string
Contains additional information that you want to include any time Auto Scaling sends a message to the notification target.
NotificationTargetArn string
The 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 string
The ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target.
AutoscalingGroupName string
The name of the Auto Scaling group to which you want to assign the lifecycle hook
LifecycleTransition string
The instance state to which you want to attach the lifecycle hook. For a list of lifecycle hook types, see describe-lifecycle-hook-types
DefaultResult string
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 int
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
Name string
The name of the lifecycle hook.
NotificationMetadata string
Contains additional information that you want to include any time Auto Scaling sends a message to the notification target.
NotificationTargetArn string
The 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 string
The ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target.
autoscalingGroupName string
The name of the Auto Scaling group to which you want to assign the lifecycle hook
lifecycleTransition string
The instance state to which you want to attach the lifecycle hook. For a list of lifecycle hook types, see describe-lifecycle-hook-types
defaultResult string
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 number
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
name string
The name of the lifecycle hook.
notificationMetadata string
Contains additional information that you want to include any time Auto Scaling sends a message to the notification target.
notificationTargetArn string
The 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 string
The ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target.
autoscaling_group_name str
The name of the Auto Scaling group to which you want to assign the lifecycle hook
lifecycle_transition str
The instance state to which you want to attach the lifecycle hook. For a list of lifecycle hook types, see describe-lifecycle-hook-types
default_result str
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.
heartbeat_timeout int
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
name str
The name of the lifecycle hook.
notification_metadata str
Contains additional information that you want to include any time Auto Scaling sends a message to the notification target.
notification_target_arn str
The 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.
role_arn str
The ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target.

Outputs

All input properties are implicitly available as output properties. Additionally, the LifecycleHook resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.

Look up an Existing LifecycleHook Resource

Get an existing LifecycleHook resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: LifecycleHookState, opts?: CustomResourceOptions): LifecycleHook
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        autoscaling_group_name: Optional[str] = None,
        default_result: Optional[str] = None,
        heartbeat_timeout: Optional[int] = None,
        lifecycle_transition: Optional[str] = None,
        name: Optional[str] = None,
        notification_metadata: Optional[str] = None,
        notification_target_arn: Optional[str] = None,
        role_arn: Optional[str] = None) -> LifecycleHook
func GetLifecycleHook(ctx *Context, name string, id IDInput, state *LifecycleHookState, opts ...ResourceOption) (*LifecycleHook, error)
public static LifecycleHook Get(string name, Input<string> id, LifecycleHookState? state, CustomResourceOptions? opts = null)
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name
The unique name of the resulting resource.
id
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.

The following state arguments are supported:

AutoscalingGroupName string
The name of the Auto Scaling group to which you want to assign the lifecycle hook
DefaultResult string
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 int
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 string
The instance state to which you want to attach the lifecycle hook. For a list of lifecycle hook types, see describe-lifecycle-hook-types
Name string
The name of the lifecycle hook.
NotificationMetadata string
Contains additional information that you want to include any time Auto Scaling sends a message to the notification target.
NotificationTargetArn string
The 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 string
The ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target.
AutoscalingGroupName string
The name of the Auto Scaling group to which you want to assign the lifecycle hook
DefaultResult string
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 int
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 string
The instance state to which you want to attach the lifecycle hook. For a list of lifecycle hook types, see describe-lifecycle-hook-types
Name string
The name of the lifecycle hook.
NotificationMetadata string
Contains additional information that you want to include any time Auto Scaling sends a message to the notification target.
NotificationTargetArn string
The 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 string
The ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target.
autoscalingGroupName string
The name of the Auto Scaling group to which you want to assign the lifecycle hook
defaultResult string
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 number
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 string
The instance state to which you want to attach the lifecycle hook. For a list of lifecycle hook types, see describe-lifecycle-hook-types
name string
The name of the lifecycle hook.
notificationMetadata string
Contains additional information that you want to include any time Auto Scaling sends a message to the notification target.
notificationTargetArn string
The 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 string
The ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target.
autoscaling_group_name str
The name of the Auto Scaling group to which you want to assign the lifecycle hook
default_result str
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.
heartbeat_timeout int
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
lifecycle_transition str
The instance state to which you want to attach the lifecycle hook. For a list of lifecycle hook types, see describe-lifecycle-hook-types
name str
The name of the lifecycle hook.
notification_metadata str
Contains additional information that you want to include any time Auto Scaling sends a message to the notification target.
notification_target_arn str
The 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.
role_arn str
The ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target.

Import

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

 $ pulumi import aws:autoscaling/lifecycleHook:LifecycleHook test-lifecycle-hook asg-name/lifecycle-hook-name

Package Details

Repository
https://github.com/pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.