Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

739
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda