iCodeLikeImDrunk
iCodeLikeImDrunk

Reputation: 17806

How can I retry a AWS CloudFormation update if an update is already happening?

Trying to implement CI, every commit will trigger a CFN update. How can I check if an update is happening and force my script to wait or schedule some retry at a future time?

I see there's a describe-stack-events, but this gives me a list not the most recent event. Is there a shortened version?

aws cloudformation describe-stack-events --profile dev --stack-name name --max-items 1

Upvotes: 4

Views: 2574

Answers (2)

andrew lorien
andrew lorien

Reputation: 2678

The one-liner I use when I'm testing scripts (and assuming that there will be failures). It runs the script, waits for the update to complete, then returns the event which caused the problem.

aws cloudformation update-stack --stack-name name --template-body file://stack.yaml && aws cloudformation wait stack-update-complete --stack-name name || aws cloudformation describe-stack-events --stack-name name | grep -B2 -A8 CREATE_FAILED

Upvotes: 2

iCodeLikeImDrunk
iCodeLikeImDrunk

Reputation: 17806

Found the solution:

aws cloudformation wait stack-update-complete --stack-name name --profile dev

More details at: https://docs.aws.amazon.com/cli/latest/reference/cloudformation/wait/index.html#cli-aws-cloudformation-wait

Upvotes: 4

Related Questions