ECS 默认 CloudWatch 指标 1 分钟粒度,自动扩缩容响应慢。流量突增时,1 分钟才能触发扩容,用户体验下降。
ECS 默认 CloudWatch 指标 1 分钟粒度,自动扩缩容响应慢。流量突增时,1 分钟才能触发扩容,用户体验下降。
CloudWatch 默认指标聚合周期 60 秒,ECS Service Auto Scaling 基于此周期,无法更快响应。
ECS 现在支持 10 秒粒度的指标:
# 启用高分辨率指标
aws ecs update-service \
--cluster my-cluster \
--service my-service \
--enable-execute-command \
--network-configuration "awsvpcConfiguration={...}"
# 配置 Auto Scaling(10 秒响应)
aws application-autoscaling put-scaling-policy \
--service-namespace ecs \
--scalable-dimension ecs:service:DesiredCount \
--resource-id service/my-cluster/my-service \
--policy-name high-res-scaling \
--policy-type TargetTrackingScaling \
--target-tracking-scaling-policy-configuration '{
"TargetValue": 70.0,
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ECSServiceAverageCPUUtilization"
},
"ScaleInCooldown": 60,
"ScaleOutCooldown": 10
}'| 指标粒度 | 扩容触发时间 | 适用场景 |
|---|---|---|
| 60 秒(默认) | 1-2 分钟 | 稳定流量 |
| 10 秒(新) | 10-20 秒 | 突增流量 |
| 1 秒(自定义) | 1-2 秒 | 实时响应 |
# 查看高分辨率指标
aws cloudwatch get-metric-statistics \
--namespace AWS/ECS \
--metric-name CPUUtilization \
--dimensions Name=ServiceName,Value=my-service \
--period 10 \
--statistics Average \
--start-time 2026-07-01T00:00:00Z \
--end-time 2026-07-01T01:00:00Zaws ecs update-service \
echo "Verification passed: fix command exited 0"Expected Output: command completes without error, then Verification passed is printed. (Checks: aws ecs update-service \)