【问题标题】:Wait and Loop condition in Bash ScriptBash 脚本中的等待和循环条件
【发布时间】:2020-11-24 02:33:39
【问题描述】:

我有一个 AWS CLI 脚本,它将获取实例的 AMI、创建启动配置、使用最新的启动配置更新自动扩展组并执行实例刷新操作。

除非 AMI 处于“可用状态”,否则我不想执行实例刷新操作。所以,我正在考虑添加一个每 10 秒检查一次的条件。

这是我现有的脚本文件:

...
#Create AMI
IMAGE=`aws ec2 create-image --instance-id ${INST_ID} --name NEW-IMAGE-${TIME} --no-reboot --output text`
echo "Create Image of instance ${INST_ID}"

#Create new launch Configuration
aws autoscaling create-launch-configuration --launch-configuration-name ${NEW_LC} --image-id ${IMAGE} --instance-type t2.micro --key forclient --associate-public-ip-address --security-groups sg-01be135cb14a00960
echo "Create new Launch Configuration ${NEW_LC}"

#Update Auto Scaling Group to use new Launch Configuration
aws autoscaling update-auto-scaling-group --auto-scaling-group-name ${ASG_NAME} --launch-configuration-name ${NEW_LC}
echo "New Launch Configuration is updated in ASG ${NEW_LC}"

aws autoscaling start-instance-refresh --auto-scaling-group-name ${ASG_NAME}

在“create-image”处于“可用”状态之前,我不想运行“start-instance-refresh”命令。

我需要对此脚本文件进行哪些更改才能发生这种情况?

【问题讨论】:

    标签: bash amazon-web-services shell terminal aws-cli


    【解决方案1】:

    创建镜像后可以使用image-available服务员:

    aws ec2 wait image-available --image-ids ${IMAGE}
    

    【讨论】:

      猜你喜欢
      • 2015-03-13
      • 2015-07-03
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 2014-10-30
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多