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
resource "aws_autoscaling_policy" "proxy_policy_up" {
name = "proxy-scale-up"
scaling_adjustment = 2
adjustment_type = "ChangeInCapacity"
policy_type = "SimpleScaling"
cooldown = 300
resource "aws_autoscaling_policy" "proxy_policy_up" {
name = "proxy-scale-up"
scaling_adjustment = 2
adjustment_type = "ChangeInCapacity"
policy_type = "SimpleScaling"
cooldown = 300
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"
Parameters
-
adjustment_type
optional - string -
arn
optional computed - string -
autoscaling_group_name
required - string -
cooldown
optional - number -
estimated_instance_warmup
optional - number -
id
optional computed - string -
metric_aggregation_type
optional computed - string -
min_adjustment_magnitude
optional - number -
name
required - string -
policy_type
optional - string -
scaling_adjustment
optional - number -
step_adjustment
set block-
metric_interval_lower_bound
optional - string -
metric_interval_upper_bound
optional - string -
scaling_adjustment
required - number
-
-
target_tracking_configuration
list block-
disable_scale_in
optional - bool -
target_value
required - number -
customized_metric_specification
list block-
metric_name
required - string -
namespace
required - string -
statistic
required - string -
unit
optional - string -
metric_dimension
list block
-
-
predefined_metric_specification
list block-
predefined_metric_type
required - string -
resource_label
optional - string
-
-
Explanation in Terraform Registry
Provides an AutoScaling Scaling Policy resource.
NOTE: You may want to omit
desired_capacity
attribute from attachedaws_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.
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::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
-
AdjustmentType
optional - String -
AutoScalingGroupName
required - String -
Cooldown
optional - String -
EstimatedInstanceWarmup
optional - Integer -
MetricAggregationType
optional - String -
MinAdjustmentMagnitude
optional - Integer -
PolicyType
optional - String -
PredictiveScalingConfiguration
optional - PredictiveScalingConfiguration -
ScalingAdjustment
optional - Integer -
StepAdjustments
optional - List of StepAdjustment -
TargetTrackingConfiguration
optional - TargetTrackingConfiguration
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.