可以将UsePreviousTemplate(在CloudFormation UpdateStack中)与嵌套堆栈一起使用 [英] Can UsePreviousTemplate (in CloudFormation UpdateStack) be used together with nested stacks

查看:84
本文介绍了可以将UsePreviousTemplate(在CloudFormation UpdateStack中)与嵌套堆栈一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用嵌套堆栈是最佳实践在AWS CloudFormation中,确实可以解决许多问题(代码重用,堆栈限制等)。

Using nested stacks is a best practice in AWS CloudFormation, and indeed they solve many problems (code reuse, stack limits, etc).

在更新堆栈(通过UpdateStack或ChangeSets)时,一个可以提供 UsePreviousTemplate = True 来指示CloudFormation使用当前用于堆栈的任何模板。如果您只想更新一些参数,尤其是当您有一些自动化脚本进行更新时,这将非常有用(我们使用将要发布的github上代码的SHA来更新参数,而CloudFormation会为其余部分进行更新)我们-构建和部署,因此我们在准备好要部署的代码后立即从lambda更新此参数);在这种情况下,您要确保所做的只是更新参数控制的内容,而不是意外地提供新的(或旧的)模板。

When updating a stack (either through UpdateStack or ChangeSets), one can provide UsePreviousTemplate=True in order to instruct CloudFormation to use whatever template is currently live for the stack. This is useful if all you want to is update some parameters, and especially if you have some automated script doing the update (we update a parameter with the SHA of the code on github that we want to put live, and CloudFormation does the rest for us -- build and deploy, so we update this parameter from a lambda as soon as we have the code ready for a deploy); in this case you want to make sure that all you do is update the stuff controlled by the parameter, and not accidentally provide a new (or old) template.

没有关于在涉及嵌套堆栈时给出此参数会发生什么情况的文档,似乎也没有任何地方可以指定这方面的有用信息。在的定义中,似乎也没有任何用处。嵌套堆栈

There seems to be no documentation on what happens if you give this parameter when there are nested stacks involved, nor does there seem to be any place where one could specify anything useful in this regard. There also seems to be nothing useful in the definition of the nested stack:

Type: AWS::CloudFormation::Stack
Properties: 
  NotificationARNs: 
    - String
  Parameters: 
    Key : Value
  Tags: 
    - Tag
  TemplateURL: String
  TimeoutInMinutes: Integer

因此出现以下问题:


  • 在具有嵌套堆栈的堆栈上使用 UsePreviousTemplate = True 进行更新时的行为是什么?

  • 是否可以是否使用诸如 UsePreviousTemplate = True 之类的堆栈更新不仅用于父堆栈,还用于嵌套堆栈?

  • What is the behaviour when doing an update with UsePreviousTemplate=True on a stack with nested stacks?
  • Is it possible to do a stack update, using something like UsePreviousTemplate=True not only for the parent stack but also for the nested stacks?

推荐答案

在具有n的堆栈上使用 UsePreviousTemplate = True 进行更新时的行为是什么?



正在使用根堆栈的先前模板。但是,此模板指向嵌套模板的s3位置,然后再次从该位置检索嵌套模板。这意味着:

What is the behaviour when doing an update with UsePreviousTemplate=True on a stack with nested stacks?

The previous template for the root stack is being used. However this template points to the s3 location of the nested template, and the nested template is again retrieved from this location. This means that:


  • 在s3上对该模板所做的任何更改都会将这些更改部署到您的嵌套堆栈中

  • 如果不再可以在该位置找到模板,则堆栈更新将失败。

  • 通常,您将始终在ChangeSet中看到嵌套堆栈,(据说),因为CloudFormation直到它实际运行时才知道模板中是否有更改。

您可以使用版本化的URL避免出现第一个问题,如果您通过在URL中添加?versionId = ... 来打开存储桶中的版本控制,则:

You can avoid the first of these issues by using a versioned URL, if you have versioning switched on in your bucket by adding ?versionId=... to your url:

https://s3.#BUCKETREGION#.amazonaws.com/..../.../.../.../nested.template?versionId = XXXX

注意:以上内容是正确的,无论嵌套堆栈中是否有宏(这合法地意味着至少它们在更新时都需要重新评估),或者甚至不提供CAPABILITY_AUTO_EXPAND(如果没有,则该保证嵌套堆栈中没有宏)。

Note: the above is true regardless of whether there are Macros in the nested stacks (which legitimately would mean that at least they need re-evaluation upon update), or even CAPABILITY_AUTO_EXPAND is given or not (if not, this guarantees no macros in the nested stacks).

可以设置一个禁止在嵌套堆栈上进行更新的堆栈策略([此处] [3],在防止对Nes的更新ted Stacks),但是在我的实验中,它所做的一切都是不允许对父堆栈进行任何更新(因为任何更新都会自动影响客户端堆栈)。

There is a possibility to set a stack policy that disallows updates on nested stacks ([here][3], under "Prevent Updates to Nested Stacks"), however in my experiments all that it did was disallow any update on the parent stack (since any update will automatically affect the client stacks).

现在我倾向于说不,但我很高兴在这里被证明是错误的!

So for now I'm inclined to say "no", but I'd be happy to be proven wrong here!

这篇关于可以将UsePreviousTemplate(在CloudFormation UpdateStack中)与嵌套堆栈一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆