You need to enable JavaScript to run this app. bash脚本创建ECS服务后运行AWS命令报错,是我操作有误吗?
优惠活动
大模型
产品
解决方案
定价
更多

bash脚本创建ECS服务后运行AWS命令报错,是我操作有误吗?

问题说明

我写了一段bash脚本,调用AWS命令完成ECS服务的启动流程,后续本来计划给这个服务配置自动伸缩策略,但脚本执行的时候直接报错了。目前我拿不准问题是出在AWS CLI本身,还是我写的bash脚本的运行逻辑有问题,对着AWS官方文档核对了一遍,感觉命令语法好像没什么问题。

脚本代码
aws ecs create-service \
      --cluster $1 \
      --service-name $2 \
      --task-definition $3:$4 \
      --desired-count $DESIRED_COUNT \
      --launch-type FARGATE \
      --platform-version LATEST \
      --network-configuration "awsvpcConfiguration={subnets=[${SUBNETS[0]}${SUBNETS[1]}${SUBNETS[2]}],securityGroups=[$SECURITY_GROUPS],assignPublicIp=ENABLED}" \
      --service-registries registryArn=$SERVICE_DISCOVERY_ARN \
      --load-balancers targetGroupArn=$BACKEND_TARGETGROUP,containerName=$BACKEND_CONTAINERNAME,containerPort=$BACKEND_CONTAINERPORT \
      --profile $PROFILE

echo "============ Now creating $2 service auto-scaling policies ============"
aws application-autoscaling register-scalable-target \
      --service-namespace ecs \
      --scalable-dimension ecs:service:DesiredCount \
      --resource-id "service/$CLUSTER/$BACKEND_SERVICE" \
      --min-capacity $MINIMUM_APP_COUNT --max-capacity $MAXIMUM_APP_COUNT
    
aws application-autoscaling put-scaling-policy 
      --service-namespace ecs \
      --scalable-dimension ecs:service:DesiredCount \
      --resource-id "service/$CLUSTER/$BACKEND_SERVICE" \
      --policy-name "${CLUSTER}_scale_up" --policy-type StepScaling \
      --step-scaling-policy-configuration file://stepScalingUpPolicy.json
    
aws application-autoscaling put-scaling-policy 
      --service-namespace ecs \
      --scalable-dimension ecs:service:DesiredCount \
      --resource-id "service/$CLUSTER/$BACKEND_SERVICE" \
      --policy-name "${CLUSTER}_scale_down" --policy-type StepScaling \
      --step-scaling-policy-configuration file://stepScalingDownPolicy.json
报错触发场景

流水线在执行完第一条ECS服务创建命令后,直接输出了报错内容。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.25 13:06:03