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.

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

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

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.

risk-label

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.

Review your AWS Amazon EC2 Auto Scaling settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

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

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.

Frequently asked questions

What is AWS Amazon EC2 Auto Scaling Lifecycle Hook?

AWS Amazon EC2 Auto Scaling Lifecycle Hook is a resource for Amazon EC2 Auto Scaling of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.