I also needed a wait in my bash script after running aws cloudformation create-stack
. I was hesitant to use the aws cloudformation wait stack-create-complete
command as it only polls up to 60 minutes (120 times 30 seconds). Also, I did not want to run tests to see how it would behave if the stack ended up in a state other than "CREATE_COMPLETE". I therefore wrote my own wait in bash as follows:
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