Ang*_*Tom 6 aws-cloudformation
我正在尝试创建一个堆栈aws cloudformation create-stack --stack-name ... --template-body file://...来创建一个堆栈.它在我执行命令后立即输出堆栈ID.但是堆栈所需的资源仍在创建中.
我想输出一些消息,直到创建所有资源.
我不想在循环中描述堆栈.并输出消息,直到获得堆栈创建完成信号.
Woo*_*Dzu 16
在初始创建堆栈请求之后,您将需要请求另一个:
aws cloudformation wait stack-create-complete --stack-name $STACK_ID_FROM_CREATE_STACK
Run Code Online (Sandbox Code Playgroud)
来自aws docs http://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/stack-create-complete.html
等到堆栈状态为CREATE_COMPLETE.它将每30秒轮询一次,直到达到成功状态.在120次检查失败后,这将以返回码255退出.
运行后我还需要在 bash 脚本中等待aws cloudformation create-stack。我对是否使用该命令犹豫不决aws cloudformation wait stack-create-complete,因为它最多只能轮询 60 分钟(120 次 30 秒)。另外,我不想运行测试来看看如果堆栈最终处于“CREATE_COMPLETE”以外的状态,它会如何表现。因此,我在 bash 中编写了自己的等待,如下所示:
aws --region ${AWS_REGION} --profile ${AWS_PROFILE} cloudformation create-stack --template-body ${STACK_TEMPLATE} --stack-name ${STACK_NAME}
if [[ $? -eq 0 ]]; then
# Wait for create-stack to finish
echo "Waiting for create-stack command to complete"
CREATE_STACK_STATUS=$(aws --region ${AWS_REGION} --profile ${AWS_PROFILE} cloudformation describe-stacks --stack-name ${STACK_NAME} --query 'Stacks[0].StackStatus' --output text)
while [[ $CREATE_STACK_STATUS == "REVIEW_IN_PROGRESS" ]] || [[ $CREATE_STACK_STATUS == "CREATE_IN_PROGRESS" ]]
do
# Wait 30 seconds and then check stack status again
sleep 30
CREATE_STACK_STATUS=$(aws --region ${AWS_REGION} --profile ${AWS_PROFILE} cloudformation describe-stacks --stack-name ${STACK_NAME} --query 'Stacks[0].StackStatus' --output text)
done
fi
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4325 次 |
| 最近记录: |