简体   繁体   English

部署 CloudFormation 模板,而不仅仅是变更集

[英]Deploy CloudFormation template, not just the changeset

Context语境

I manually deleted stacks in an aws account because a particular resource was using an outdated version of Node.我手动删除了 aws 帐户中的堆栈,因为特定资源使用的是过时版本的 Node。 Now I'm trying to redeploy the stacks manually.现在我正在尝试手动重新部署堆栈。 But I am getting <resource type> does not exist errors .但我收到<resource type> does not exist errors My thought so far is that somewhere CF is caching those deleted resources and their associated names/service names.到目前为止,我的想法是 CF 在某处缓存那些已删除的资源及其关联的名称/服务名称。 Then when I deploy the stack, a changeset is created where the deleted resources already exist.然后,当我部署堆栈时,会在已存在已删除资源的地方创建一个变更集。 Then when the changeset is executed, it cannot find the deleted resources, which it thinks still exists resulting in InvalidServiceName errors.然后当执行变更集时,它找不到已删除的资源,它认为这些资源仍然存在,导致InvalidServiceName错误。

Question问题

Is there a way to outright deploy an entire CF template, not the changeset?有没有办法直接部署整个 CF 模板,而不是变更集?

Effort努力

I've tried creating "dummy" resources for the changeset to then overwrite.我已经尝试为变更集创建“虚拟”资源然后覆盖。 The difficulty is that service names are dynamic, so the changeset still does not find the "dummy" resource because the servicename is not the same.困难在于服务名称是动态的,因此变更集仍然找不到“虚拟”资源,因为服务名称不同。

CloudFormation holds an internal state of the stack, which does not necessarily correspond to the actual situation if you have manually changed or deleted some resources. CloudFormation持有一个内部state的堆栈,如果你手动更改或删除了一些资源,这不一定符合实际情况。 For some AWS services, you can view how this state is different by looking at the stack drift .对于某些 AWS 服务,您可以通过查看堆栈漂移来了解这个 state 有何不同。 I also want to point out that the notion of "applying the stack and not the changeset" is impossible.我还想指出“应用堆栈而不是变更集”的概念是不可能的。 CloudFormation always uses a changeset, even when it initially deploys the stack, even though this is sometimes obfuscated for the end-user. CloudFormation 始终使用变更集,即使它最初部署堆栈时也是如此,尽管这有时对最终用户来说是模糊的。

I see two possible options to fix this.我看到两个可能的选项来解决这个问题。 The first is to delete the stack in its entirety and recreate it completely.第一种是删除整个堆栈并完全重新创建它。 CloudFormation might error the first time, since it cannot delete certain resources, but you would be able to retain those resources on a second try. CloudFormation 第一次可能会出错,因为它无法删除某些资源,但您可以在第二次尝试时保留这些资源。 If you select the already deleted resources in the second try, the stack should be deleted after which you can recreate it.如果您在第二次尝试中 select 已经删除的资源,则应删除堆栈,然后您可以重新创建它。

Depending on the situation you would also have a second option.根据情况,您还有第二种选择。 You could delete only the already deleted resources from the stack (eg, by commenting them out and updating the stack) and then redeploy with the lines uncommented again.您可以仅从堆栈中删除已删除的资源(例如,通过注释掉它们并更新堆栈),然后重新部署并再次取消注释行。 If this doesn't work since the resources cannot be found, you might have better luck by adding a DeletionPolicy set to retain in a first update, which would prevent CloudFormation from actually deleting (the non-existent) resource.如果这不起作用,因为找不到资源,您可能会通过添加DeletionPolicy集以在第一次更新中retain获得更好的运气,这将防止 CloudFormation 实际删除(不存在的)资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM