简体   繁体   English

在 bash 脚本中运行 AWS 服务会在尝试运行第二个命令时产生错误,我做错了什么吗?

[英]Running AWS services in bash script creates an error when trying to run the second command, am I doing something wrong?

So I have a bash script that runs some AWS commands to spin up an ECS service, I then want to attach some autoscaling policies to it but I am getting an error.所以我有一个 bash 脚本,它运行一些 AWS 命令来启动 ECS 服务,然后我想向它附加一些自动缩放策略,但我收到了一个错误。 I'm not sure if it is anything to do with the AWS service CLI or I am running it incorrectly in bash, syntax wise it seems fine according to the AWS docs.我不确定这是否与 AWS 服务 CLI 有任何关系,或者我在 bash 中运行不正确,根据 AWS 文档,语法上看起来不错。

Here's the code:这是代码:

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

Image is of error on my pipeline after running the first aws service.运行第一个 aws 服务后,图像在我的管道上出现错误。 [1]: https://i.stack.imgur.com/5PxBW.png [1]: https://i.stack.imgur.com/5PxBW.png

You are missing slashes \ after two commands.您在两个命令后缺少斜杠\ It should be它应该是

 aws application-autoscaling put-scaling-policy \

and

aws application-autoscaling put-scaling-policy \

Also make sure you don't have any white characters (spaces or tabs) after \\ .还要确保在\\之后没有任何白色字符(空格或制表符)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM