Bash 脚本中的等待和循环条件

Wait and Loop condition in Bash Script

我有一个 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' 处于 'available' 状态之前,我不想 运行 'start-instance-refresh' 命令。

我需要对此脚本文件进行哪些更改才能实现这一点?

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

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