LifecycleHook class
Provides an AutoScaling Lifecycle Hook resource.
> NOTE: This provider has two types of ways you can add lifecycle hooks - via
the initialLifecycleHook 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
initialLifecycleHook in
aws.autoscaling.Group,
but take care to not duplicate those hooks with this resource.
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const foobar = new aws.autoscaling.Group("foobar", {
tags: [{
key: "Foo",
value: "foo-bar",
propagateAtLaunch: true,
}],
availabilityZones: ["us-west-2a"],
name: "test-foobar5",
healthCheckType: "EC2",
terminationPolicies: ["OldestInstance"],
});
const foobarLifecycleHook = new aws.autoscaling.LifecycleHook("foobar", {
name: "foobar",
autoscalingGroupName: foobar.name,
defaultResult: "CONTINUE",
heartbeatTimeout: 2000,
lifecycleTransition: "autoscaling:EC2_INSTANCE_LAUNCHING",
notificationMetadata: JSON.stringify({
foo: "bar",
}),
notificationTargetArn: "arn:aws:sqs:us-east-1:444455556666:queue1*",
roleArn: "arn:aws:iam::123456789012:role/S3Access",
});
import pulumi
import json
import pulumi_aws as aws
foobar = aws.autoscaling.Group("foobar",
tags=[{
"key": "Foo",
"value": "foo-bar",
"propagate_at_launch": True,
}],
availability_zones=["us-west-2a"],
name="test-foobar5",
health_check_type="EC2",
termination_policies=["OldestInstance"])
foobar_lifecycle_hook = aws.autoscaling.LifecycleHook("foobar",
name="foobar",
autoscaling_group_name=foobar.name,
default_result="CONTINUE",
heartbeat_timeout=2000,
lifecycle_transition="autoscaling:EC2_INSTANCE_LAUNCHING",
notification_metadata=json.dumps({
"foo": "bar",
}),
notification_target_arn="arn:aws:sqs:us-east-1:444455556666:queue1*",
role_arn="arn:aws:iam::123456789012:role/S3Access")
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Pulumi;
using Aws = Pulumi.Aws;
return await Deployment.RunAsync(() =>
{
var foobar = new Aws.AutoScaling.Group("foobar", new()
{
Tags = new[]
{
new Aws.AutoScaling.Inputs.GroupTagArgs
{
Key = "Foo",
Value = "foo-bar",
PropagateAtLaunch = true,
},
},
AvailabilityZones = new[]
{
"us-west-2a",
},
Name = "test-foobar5",
HealthCheckType = "EC2",
TerminationPolicies = new[]
{
"OldestInstance",
},
});
var foobarLifecycleHook = new Aws.AutoScaling.LifecycleHook("foobar", new()
{
Name = "foobar",
AutoscalingGroupName = foobar.Name,
DefaultResult = "CONTINUE",
HeartbeatTimeout = 2000,
LifecycleTransition = "autoscaling:EC2_INSTANCE_LAUNCHING",
NotificationMetadata = JsonSerializer.Serialize(new Dictionary<string, object?>
{
["foo"] = "bar",
}),
NotificationTargetArn = "arn:aws:sqs:us-east-1:444455556666:queue1*",
RoleArn = "arn:aws:iam::123456789012:role/S3Access",
});
});
package main
import (
"encoding/json"
"github.com/pulumi/pulumi-aws/sdk/v7/go/aws/autoscaling"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
foobar, err := autoscaling.NewGroup(ctx, "foobar", &autoscaling.GroupArgs{
Tags: autoscaling.GroupTagArray{
&autoscaling.GroupTagArgs{
Key: pulumi.String("Foo"),
Value: pulumi.String("foo-bar"),
PropagateAtLaunch: pulumi.Bool(true),
},
},
AvailabilityZones: pulumi.StringArray{
pulumi.String("us-west-2a"),
},
Name: pulumi.String("test-foobar5"),
HealthCheckType: pulumi.String("EC2"),
TerminationPolicies: pulumi.StringArray{
pulumi.String("OldestInstance"),
},
})
if err != nil {
return err
}
tmpJSON0, err := json.Marshal(map[string]string{
"foo": "bar",
})
if err != nil {
return err
}
json0 := string(tmpJSON0)
_, err = autoscaling.NewLifecycleHook(ctx, "foobar", &autoscaling.LifecycleHookArgs{
Name: pulumi.String("foobar"),
AutoscalingGroupName: foobar.Name,
DefaultResult: pulumi.String("CONTINUE"),
HeartbeatTimeout: pulumi.Int(2000),
LifecycleTransition: pulumi.String("autoscaling:EC2_INSTANCE_LAUNCHING"),
NotificationMetadata: pulumi.String(json0),
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
})
}
pulumi {
required_providers {
aws = {
source = "pulumi/aws"
}
}
}
resource "aws_autoscaling_group" "foobar" {
tags {
key = "Foo"
value = "foo-bar"
propagate_at_launch = true
}
availability_zones = ["us-west-2a"]
name = "test-foobar5"
health_check_type = "EC2"
termination_policies = ["OldestInstance"]
}
resource "aws_autoscaling_lifecyclehook" "foobar" {
name = "foobar"
autoscaling_group_name = aws_autoscaling_group.foobar.name
default_result = "CONTINUE"
heartbeat_timeout = 2000
lifecycle_transition = "autoscaling:EC2_INSTANCE_LAUNCHING"
notification_metadata = jsonencode({
"foo" = "bar"
})
notification_target_arn = "arn:aws:sqs:us-east-1:444455556666:queue1*"
role_arn = "arn:aws:iam::123456789012:role/S3Access"
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.autoscaling.Group;
import com.pulumi.aws.autoscaling.GroupArgs;
import com.pulumi.aws.autoscaling.inputs.GroupTagArgs;
import com.pulumi.aws.autoscaling.LifecycleHook;
import com.pulumi.aws.autoscaling.LifecycleHookArgs;
import static com.pulumi.codegen.internal.Serialization.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
var foobar = new Group("foobar", GroupArgs.builder()
.tags(GroupTagArgs.builder()
.key("Foo")
.value("foo-bar")
.propagateAtLaunch(true)
.build())
.availabilityZones("us-west-2a")
.name("test-foobar5")
.healthCheckType("EC2")
.terminationPolicies("OldestInstance")
.build());
var foobarLifecycleHook = new LifecycleHook("foobarLifecycleHook", LifecycleHookArgs.builder()
.name("foobar")
.autoscalingGroupName(foobar.name())
.defaultResult("CONTINUE")
.heartbeatTimeout(2000)
.lifecycleTransition("autoscaling:EC2_INSTANCE_LAUNCHING")
.notificationMetadata(serializeJson(
jsonObject(
jsonProperty("foo", "bar")
)))
.notificationTargetArn("arn:aws:sqs:us-east-1:444455556666:queue1*")
.roleArn("arn:aws:iam::123456789012:role/S3Access")
.build());
}
}
resources:
foobar:
type: aws:autoscaling:Group
properties:
tags:
- key: Foo
value: foo-bar
propagateAtLaunch: true
availabilityZones:
- us-west-2a
name: test-foobar5
healthCheckType: EC2
terminationPolicies:
- OldestInstance
foobarLifecycleHook:
type: aws:autoscaling:LifecycleHook
name: foobar
properties:
name: foobar
autoscalingGroupName: ${foobar.name}
defaultResult: CONTINUE
heartbeatTimeout: 2000
lifecycleTransition: autoscaling:EC2_INSTANCE_LAUNCHING
notificationMetadata:
fn::toJSON:
foo: bar
notificationTargetArn: arn:aws:sqs:us-east-1:444455556666:queue1*
roleArn: arn:aws:iam::123456789012:role/S3Access
Import
Identity Schema
Required
autoscalingGroupName(String) Name of the Auto Scaling group.name(String) Name of the lifecycle hook.
Optional
accountId(String) AWS Account where this resource is managed.region(String) Region where this resource is managed.
Using pulumi import, import AutoScaling Lifecycle Hooks using autoscalingGroupName and name separated by a forward slash (/). For example:
$ pulumi import aws:autoscaling/lifecycleHook:LifecycleHook example example-asg/example-hook
Constructors
- LifecycleHook(String name, {LifecycleHookArgs? args, CustomResourceOptions? options})
-
Creates a new LifecycleHook.
nameThe Pulumi resource name.argsArguments used to configure this LifecycleHook. The set of arguments for LifecycleHook.optionsResource options controlling this resource's behavior. - LifecycleHook.reference(String urn)
- Creates a typed reference to an existing LifecycleHook resource.
Properties
-
autoscalingGroupName
↔ Output<
String> -
Name of the Auto Scaling group to which you want to assign the lifecycle hook
latefinal
-
childResources
→ Set<
Resource> -
finalinherited
-
completionSources
↔ Map<
String, IOutputCompletionSource> -
latefinalinherited
-
defaultResult
↔ Output<
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.
latefinal
- hashCode → int
-
The hash code for this object.
no setterinherited
-
heartbeatTimeout
↔ Output<
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
latefinal
-
id
↔ Output<
String> -
getter/setter pairinherited
- isCustom → bool
-
Returns whether this resource is provider-managed.
no setterinherited
- isProtected → bool
-
Returns whether this resource is protected from deletion.
no setterinherited
- isRemote → bool
-
Whether this resource is registered as remote.
no setterinherited
- isResourceReference → bool
-
Whether this instance represents a resource value returned over RPC.
finalinherited
-
lifecycleTransition
↔ Output<
String> -
Instance state to which you want to attach the lifecycle hook. For a list of lifecycle hook types, see describe-lifecycle-hook-types
latefinal
-
name
↔ Output<
String> -
Name of the lifecycle hook.
latefinal
-
notificationMetadata
↔ Output<
String?> -
Contains additional information that you want to include any time Auto Scaling sends a message to the notification target.
latefinal
-
notificationTargetArn
↔ Output<
String?> -
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, an SNS topic, or a Lambda function.
latefinal
-
region
↔ Output<
String> -
Region where this resource will be managed. Defaults to the Region set in the provider configuration.
latefinal
-
resourceTransforms
→ List<
ResourceTransform> -
Inherited/explicit async transforms.
no setterinherited
-
roleArn
↔ Output<
String?> -
ARN of the IAM role that allows the Auto Scaling group to publish to the specified notification target.
latefinal
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
transformations
→ List<
ResourceTransformation> -
Inherited/explicit legacy transformations.
no setterinherited
-
urn
↔ Output<
String> -
latefinalinherited
Methods
-
failId(
Object error) → void -
Completes this resource ID with an error when registration fails.
inherited
-
failOutputs(
Object error) → void -
Completes all output properties with
error.inherited -
failUrn(
Object error) → void -
Completes this resource URN with an error when registration fails.
inherited
-
getProvider(
String moduleMember) → ProviderResource? -
Returns provider for
moduleMember's package, if configured.inherited -
getResourceName(
) → String -
Returns this resource's logical name.
inherited
-
getResourceType(
) → String -
Returns this resource's Pulumi type token.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
registerOutput<
T> (String propertyName, {Object? decoder(Object?)?, bool isSecret = false}) → Output< T> -
Registers a dynamic output property for this resource.
inherited
-
resolveId(
String? value, {required bool isKnown}) → void -
Resolves the provider-assigned ID for this resource.
inherited
-
resolveOutputs(
Struct outputs) → void -
Resolves all output properties from a monitor response payload.
inherited
-
resolveUrn(
String value) → void -
Resolves this resource's URN once assigned by the engine.
inherited
-
serializeProperties(
Map< String, dynamic> properties) → Future<Struct> -
Serializes resource properties for RPC transmission.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
get(
String name, Input< String> id, {LifecycleHookState? state, CustomResourceOptions? options}) → LifecycleHook -
Gets an existing LifecycleHook resource's state with the given
nameandid.