Amazon Command Line Interface (Amazon CLI) 的扩展策略示例 - Amazon EC2 Auto Scaling
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

Amazon Command Line Interface (Amazon CLI) 的扩展策略示例

您可以通过 Amazon Web Services Management Console、Amazon CLI 或软件开发工具包创建 Amazon EC2 Auto Scaling 扩展策略。

以下示例显示如何使用 Amazon CLI put-scaling-policy 命令为 Amazon EC2 Auto Scaling 创建扩缩策略。有关从 Amazon CLI 创建扩展策略的介绍性练习,请参阅 目标跟踪扩缩策略步进和简单扩展策略

示例 1:应用具有预定义指标规范的目标跟踪扩展策略

aws autoscaling put-scaling-policy --policy-name cpu40-target-tracking-scaling-policy \ --auto-scaling-group-name my-asg --policy-type TargetTrackingScaling \ --target-tracking-configuration file://config.json { "TargetValue": 40.0, "PredefinedMetricSpecification": { "PredefinedMetricType": "ASGAverageCPUUtilization" } }

示例 2:应用具有自定义指标规范的目标跟踪扩展策略

aws autoscaling put-scaling-policy --policy-name sqs100-target-tracking-scaling-policy \ --auto-scaling-group-name my-asg --policy-type TargetTrackingScaling \ --target-tracking-configuration file://config.json { "TargetValue": 100.0, "CustomizedMetricSpecification": { "MetricName": "MyBacklogPerInstance", "Namespace": "MyNamespace", "Dimensions": [{ "Name": "MyOptionalMetricDimensionName", "Value": "MyOptionalMetricDimensionValue" }], "Statistic": "Average", "Unit": "None" } }

示例 3:为仅向外扩展应用目标跟踪扩展策略

aws autoscaling put-scaling-policy --policy-name alb1000-target-tracking-scaling-policy \ --auto-scaling-group-name my-asg --policy-type TargetTrackingScaling \ --target-tracking-configuration file://config.json { "TargetValue": 1000.0, "PredefinedMetricSpecification": { "PredefinedMetricType": "ALBRequestCountPerTarget", "ResourceLabel": "app/my-alb/778d41231b141a0f/targetgroup/my-alb-target-group/943f017f100becff" }, "DisableScaleIn": true }

示例 4:为向外扩展应用步进扩展策略

aws autoscaling put-scaling-policy \ --auto-scaling-group-name my-asg \ --policy-name my-step-scale-out-policy \ --policy-type StepScaling \ --adjustment-type PercentChangeInCapacity \ --metric-aggregation-type Average \ --step-adjustments MetricIntervalLowerBound=10.0,MetricIntervalUpperBound=20.0,ScalingAdjustment=10 \ MetricIntervalLowerBound=20.0,MetricIntervalUpperBound=30.0,ScalingAdjustment=20 \ MetricIntervalLowerBound=30.0,ScalingAdjustment=30 \ --min-adjustment-magnitude 1

记下策略的 Amazon Resource Name (ARN)。创建 CloudWatch 警报时,您需要 ARN。

示例 5:为缩减应用步进扩展策略

aws autoscaling put-scaling-policy \ --auto-scaling-group-name my-asg \ --policy-name my-step-scale-in-policy \ --policy-type StepScaling \ --adjustment-type ChangeInCapacity \ --step-adjustments MetricIntervalUpperBound=0.0,ScalingAdjustment=-2

记下策略的 Amazon Resource Name (ARN)。创建 CloudWatch 警报时,您需要 ARN。

示例 6:为向外扩展应用简单扩展策略

aws autoscaling put-scaling-policy --policy-name my-simple-scale-out-policy \ --auto-scaling-group-name my-asg --scaling-adjustment 30 \ --adjustment-type PercentChangeInCapacity --min-adjustment-magnitude 2

记下策略的 Amazon Resource Name (ARN)。创建 CloudWatch 警报时,您需要 ARN。

示例 7:为缩减应用简单扩展策略

aws autoscaling put-scaling-policy --policy-name my-simple-scale-in-policy \ --auto-scaling-group-name my-asg --scaling-adjustment -1 \ --adjustment-type ChangeInCapacity --cooldown 180

记下策略的 Amazon Resource Name (ARN)。创建 CloudWatch 警报时,您需要 ARN。