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_typeoptional - string -
arnoptional computed - string -
autoscaling_group_namerequired - string -
cooldownoptional - number -
estimated_instance_warmupoptional - number -
idoptional computed - string -
metric_aggregation_typeoptional computed - string -
min_adjustment_magnitudeoptional - number -
namerequired - string -
policy_typeoptional - string -
scaling_adjustmentoptional - number -
step_adjustmentset block-
metric_interval_lower_boundoptional - string -
metric_interval_upper_boundoptional - string -
scaling_adjustmentrequired - number
-
-
target_tracking_configurationlist block-
disable_scale_inoptional - bool -
target_valuerequired - number -
customized_metric_specificationlist block-
metric_namerequired - string -
namespacerequired - string -
statisticrequired - string -
unitoptional - string -
metric_dimensionlist block
-
-
predefined_metric_specificationlist block-
predefined_metric_typerequired - string -
resource_labeloptional - string
-
-
Explanation in Terraform Registry
Provides an AutoScaling Scaling Policy resource.
NOTE: You may want to omit
desired_capacityattribute from attachedaws_autoscaling_groupwhen 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
-
AdjustmentTypeoptional - String -
AutoScalingGroupNamerequired - String -
Cooldownoptional - String -
EstimatedInstanceWarmupoptional - Integer -
MetricAggregationTypeoptional - String -
MinAdjustmentMagnitudeoptional - Integer -
PolicyTypeoptional - String -
PredictiveScalingConfigurationoptional - PredictiveScalingConfiguration -
ScalingAdjustmentoptional - Integer -
StepAdjustmentsoptional - List of StepAdjustment -
TargetTrackingConfigurationoptional - TargetTrackingConfiguration
Explanation in CloudFormation Registry
The
AWS::AutoScaling::ScalingPolicyresource 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.