10

I am trying to create a stack with aws cloudformation create-stack --stack-name ... --template-body file://... to create a stack. It output the stack id as soon as I execute the command. But the resources which are required by the stack are stilling in creating.

I want to output some message until the all the resources are created.

I don't want to describe the stack in a loop. and output the message until got the stack create completed signal.

2 Answers 2

22

After the initial create-stack request you will need to request another one:

 aws cloudformation wait stack-create-complete --stack-name $STACK_ID_FROM_CREATE_STACK

From the aws docs http://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/stack-create-complete.html

Wait until stack status is CREATE_COMPLETE. It will poll every 30 seconds until a successful state has been reached. This will exit with a return code of 255 after 120 failed checks.

2
  • 4
    Do you know what happens if the stack goes into CREATE_FAILED instead? Will the command still take 60 minutes (30 seconds * 120) to fail, or will if fail as soon as the stack enters the CREATE_FAILED state? Mar 17, 2017 at 20:21
  • i am facing Rate Exceeded exception frequently. Is there a way to configure the poll interval?
    – Gowtham
    Aug 7, 2018 at 18:08
5

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
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.