You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ECS服务的AWS资源ID是什么?如何创建自定义扩缩容策略?

ECS自定义自动扩缩容策略创建问题解答

ARN是否是resource-id的正确值?

是的,ECS服务的ARN确实是put-scaling-policy命令中resource-id字段的正确格式。你遇到的ObjectNotFoundException错误,核心原因不是ARN格式错误,而是该ECS服务尚未注册为Application Auto Scaling的可扩缩目标——创建扩缩容策略前,必须先完成这一步。

完整自定义自动扩缩容策略创建流程

1. 注册可扩缩目标

先通过register-scalable-target命令将ECS服务纳入Application Auto Scaling管理,指定任务数的上下限:

aws application-autoscaling register-scalable-target \
  --service-namespace ecs \
  --scalable-dimension ecs:service:DesiredCount \
  --resource-id arn:aws:ecs:us-east-1:XXXXXXXXXXXX:service/XYZ-SERVICE \
  --min-capacity 1 \
  --max-capacity 10
  • 根据业务需求调整min-capacity(最小任务数)和max-capacity(最大任务数)。

2. 创建自定义指标扩缩容策略

完成目标注册后,执行你原本的put-scaling-policy命令即可:

aws application-autoscaling put-scaling-policy \
  --service-namespace ecs \
  --scalable-dimension ecs:service:DesiredCount \
  --resource-id arn:aws:ecs:us-east-1:XXXXXXXXXXXX:service/XYZ-SERVICE \
  --policy-name custom-scaling-policy \
  --policy-type TargetTrackingScaling \
  --target-tracking-scaling-policy-configuration file://custom_autoscaling_config.json

确保你的custom_autoscaling_config.json配置正确,以下是两种常见场景的示例:

场景1:使用预定义ECS指标(如CPU使用率)

{
  "TargetValue": 70.0,
  "PredefinedMetricSpecification": {
    "PredefinedMetricType": "ECSServiceAverageCPUUtilization"
  },
  "ScaleOutCooldown": 60,
  "ScaleInCooldown": 60
}

场景2:使用自定义CloudWatch指标

{
  "TargetValue": 500.0,
  "CustomizedMetricSpecification": {
    "MetricName": "YourCustomMetric",
    "Namespace": "YourMetricNamespace",
    "Dimensions": [
      {
        "Name": "ServiceName",
        "Value": "XYZ-SERVICE"
      }
    ],
    "Statistic": "Average",
    "Unit": "Count"
  },
  "ScaleOutCooldown": 300,
  "ScaleInCooldown": 300
}

3. 验证配置

检查已注册的可扩缩目标:

aws application-autoscaling describe-scalable-targets \
  --service-namespace ecs \
  --resource-id arn:aws:ecs:us-east-1:XXXXXXXXXXXX:service/XYZ-SERVICE

检查已创建的扩缩容策略:

aws application-autoscaling describe-scaling-policies \
  --service-namespace ecs \
  --policy-names custom-scaling-policy

内容的提问来源于stack exchange,提问作者S7H

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 19:02:26