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

752
Views
¿Cómo esperar hasta que se complete la creación o actualización de una pila de AWS CloudFormation en bash?

Tengo un caso de uso en el que mi script bash debe esperar hasta que AWS CloudFormation complete la creación o actualización de las pilas.

Encontré que los siguientes comandos se pueden usar para hacerlo:

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

A continuación se muestra un fragmento del guión:

 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

Pero no puedo hacerlo y me sale el siguiente 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

Y en lugar de esperar, el guión pasa a la siguiente línea, lo que hace que las cosas se quiebren.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Espere a que se cree una nueva pila: aws cloudformation wait stack-create-complete

Espere una actualización de pila existente: 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 }

Llamada de función:

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

0

El comando de espera espera la pila arn

agregue al comando de creación de pila jq -r '.StackId'

Algo como:

 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')

Y luego puedes hacer

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

0

El mensaje de error indica que la pila alcanzó un estado de falla de terminal. Como con cualquier cosa, si lo que estás haciendo falla, no deberías continuar.

Puede obtener el estado de su pila después de llegar a un estado terminal:

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

Si el estado no es CREATE_COMPLETE o UPDATE_COMPLETE , debe mostrar un mensaje de error y salir de la secuencia de comandos.

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!