AWS Amazon EC2 Auto Scaling Lifecycle Hook
This page shows how to write Terraform and CloudFormation for Amazon EC2 Auto Scaling Lifecycle Hook and write them securely.
aws_autoscaling_lifecycle_hook (Terraform)
The Lifecycle Hook in Amazon EC2 Auto Scaling can be configured in Terraform with the resource name aws_autoscaling_lifecycle_hook
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
-
autoscaling_group_name
required - string -
default_result
optional computed - string -
heartbeat_timeout
optional - number -
id
optional computed - string -
lifecycle_transition
required - string -
name
required - string -
notification_metadata
optional - string -
notification_target_arn
optional - string -
role_arn
optional - string
Explanation in Terraform Registry
Provides an AutoScaling Lifecycle Hook resource.
NOTE: Terraform has two types of ways you can add lifecycle hooks - via the
initial_lifecycle_hook
attribute from theaws_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 withinitial_lifecycle_hook
inaws_autoscaling_group
, but take care to not duplicate those hooks with this resource.
Tips: Best Practices for The Other AWS Amazon EC2 Auto Scaling Resources
In addition to the aws_launch_configuration, AWS Amazon EC2 Auto Scaling has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_launch_configuration
Check public IPs should be given to Auto Scaling instances
It is better to block public access on the Internet to them. It is better to avoid associating public IP addresses if this is unintentional.
AWS::AutoScaling::LifecycleHook (CloudFormation)
The LifecycleHook in AutoScaling can be configured in CloudFormation with the resource name AWS::AutoScaling::LifecycleHook
. The following sections describe how to use the resource and its parameters.
Example Usage from GitHub
An example could not be found in GitHub.
Parameters
-
AutoScalingGroupName
required - String -
DefaultResult
optional - String -
HeartbeatTimeout
optional - Integer -
LifecycleHookName
optional - String -
LifecycleTransition
required - String -
NotificationMetadata
optional - String -
NotificationTargetARN
optional - String -
RoleARN
optional - String
Explanation in CloudFormation Registry
The
AWS::AutoScaling::LifecycleHook
resource specifies lifecycle hooks for an Auto Scaling group. These hooks enable an Auto Scaling group to be aware of events in the Auto Scaling instance lifecycle, and then perform a custom action when the corresponding lifecycle event occurs. A lifecycle hook provides a specified amount of time (one hour by default) to complete the lifecycle action before the instance transitions to the next state. There are two types of lifecycle hooks that can be implemented: launch lifecycle hooks and termination lifecycle hooks. Use a launch lifecycle hook to prepare instances for use or to delay instances from registering behind the load balancer before their configuration has been applied completely. Use a termination lifecycle hook to prepare running instances to be shut down. For more information, see Amazon EC2 Auto Scaling lifecycle hooks in the Amazon EC2 Auto Scaling User Guide and PutLifecycleHook in the Amazon EC2 Auto Scaling API Reference.