AWS Amazon EC2 Auto Scaling Policy

This page shows how to write Terraform and CloudFormation for Amazon EC2 Auto Scaling Policy and write them securely.

aws_autoscaling_policy (Terraform)

The Policy in Amazon EC2 Auto Scaling can be configured in Terraform with the resource name aws_autoscaling_policy. The following sections describe 3 examples of how to use the resource and its parameters.

Example Usage from GitHub

auto-scaling.tf#L24
resource "aws_autoscaling_policy" "proxy_policy_up" {
  name                   = "proxy-scale-up"
  scaling_adjustment     = 2
  adjustment_type        = "ChangeInCapacity"
  policy_type            = "SimpleScaling"
  cooldown               = 300
auto-scaling.tf#L24
resource "aws_autoscaling_policy" "proxy_policy_up" {
  name                   = "proxy-scale-up"
  scaling_adjustment     = 2
  adjustment_type        = "ChangeInCapacity"
  policy_type            = "SimpleScaling"
  cooldown               = 300
asg_policy.tf#L3
resource "aws_autoscaling_policy" "hi-cpu-masters-policy" {
    name = format("%s-%s-hi-cpu-masters-policy",var.environment,var.namespace)
    autoscaling_group_name = aws_autoscaling_group.masters.name
    adjustment_type = "ChangeInCapacity"
    scaling_adjustment = "1"
    cooldown = "300"

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 Scaling Policy resource.

NOTE: You may want to omit desired_capacity attribute from attached aws_autoscaling_group when using autoscaling policies. It's good practice to pick either manual or dynamic (policy-based) scaling.

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::ScalingPolicy (CloudFormation)

The ScalingPolicy in AutoScaling can be configured in CloudFormation with the resource name AWS::AutoScaling::ScalingPolicy. 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::ScalingPolicy resource specifies an Amazon EC2 Auto Scaling scaling policy so that the Auto Scaling group can scale the number of instances available for your application.

For more information about using scaling policies to scale your Auto Scaling group automatically, see Dynamic scaling and Predictive scaling in the Amazon EC2 Auto Scaling User Guide.

Frequently asked questions

What is AWS Amazon EC2 Auto Scaling Policy?

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

Where can I find the example code for the AWS Amazon EC2 Auto Scaling Policy?

For Terraform, the MiguelIsaza95/Ramup_nodejs_Infra, MIsazaB95/Ramup_nodejs_Infra and VernonCo/AWS_auto-scaling_swarm source code examples are useful. See the Terraform Example section for further details.