Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

737
Views
How to wait until an AWS CloudFormation stack creation or update is completed in bash?

I have a use-case where my bash script needs to wait until AWS CloudFormation completes Creating or Updating the stacks.

I found the following commands can be used to do so:

aws cloudformation wait stack-create-complete --stack-name STACK_NAME

aws cloudformation wait stack-update-complete --stack-name STACK_NAME

Following is a snippet of the script -

echo "Creating stack ..."

aws cloudformation create-stack --stack-name $STACK_NAME \
--parameters  ParameterKey=Environment,ParameterValue=Development \
--template-body file://someCfScript.yaml \
--capabilities CAPABILITY_AUTO_EXPAND --profile someProfileName

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

But I am not able to do so and I get the following error:

{
    "StackId": "arn:aws:cloudformation:ap-southeast-1:someAwsAcId:stack/someStackName/xxxx-xxx-xx-xxx-xxxxx"
}

Waiter StackCreateComplete failed: Waiter encountered a terminal failure state

And instead of waiting, the script goes to the next line, causing things to break.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Wait for a new stack creation -- aws cloudformation wait stack-create-complete

Wait for an existing stack update -- aws cloudformation wait stack-update-complete

wait_stack_create() {
    STACK_NAME=$1

    echo "Waiting for [$STACK_NAME] stack creation."

    aws cloudformation wait stack-create-complete \
    --region ${REGION}  \
    --stack-name ${STACK_NAME}
    status=$?

    if [[ ${status} -ne 0 ]] ; then
        # Waiter encountered a failure state.
        echo "Stack [${STACK_NAME}] creation failed. AWS error code is ${status}."

        exit ${status}
    fi
}

Function call:

wait_stack_create ${TEST_SERVICE_STACK}
over 4 years ago · Santiago Trujillo Report

0

The wait command expect the stack arn

add to the create stack command jq -r '.StackId'

Something like:

ID=$(aws cloudformation create-stack --stack-name $STACK_NAME \
--parameters  ParameterKey=Environment,ParameterValue=Development \
--template-body file://someCfScript.yaml \
--capabilities CAPABILITY_AUTO_EXPAND --profile someProfileName| jq -r '.StackId')

And then you can do

aws cloudformation wait stack-create-complete --stack-name "${STACKID}"
over 4 years ago · Santiago Trujillo Report

0

The error message indicates that the stack reached a terminal failure state. As with anything, if what you're doing fails, you shouldn't continue.

You can get the status of your stack after reaching a terminal state:

aws cloudformation describe-stacks --stack-name STACK_NAME --query 'Stacks[].StackStatus' --output text

If the status isn't CREATE_COMPLETE or UPDATE_COMPLETE you should print an error message and exit your script.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!