用于创建和执行更改集的 AWS Cloudformation 脚本

AWS Cloud formation script to create and execute change set

我正在使用以下 AWS Cli Cloud Formation 命令创建然后执行和更改集:

aws cloudformation create-change-set --change-set-name change-set-1
aws cloudformation execute-change-set --change-set-name change-set-1

但是第一个命令 returns 在创建变更集之前,如果我立即执行第二个命令它会失败。

我考虑过的解决方案:

  1. 在两个命令之间添加延迟。
  2. 重复第二个命令直到成功。

这两个都有问题。

理想情况下,create-change-set 命令上有一个选项可以立即执行,或者 运行 同步执行,而不是 return,直到创建了更改集。

有没有人试过这个并想出比我更好的解决方案?

我还没有亲自尝试过,但也许你可以使用命令 list-change-sets 循环直到你的更改集的状态为 CREATE_COMPLETE , 然后执行你的第二个命令。

希望对您有所帮助。

如果您不需要创建变更集然后执行它的中间步骤(因为我们没有),请使用 update-stack 子命令。

aws cloudformation update-stack --stack-name myStack --template-url ...

我使用以下顺序解决了这个问题:

aws cloudformation create-change-set
aws cloudformation wait change-set-create-complete
aws cloudformation execute-change-set
aws cloudformation wait stack-create-complete

希望对您有所帮助。