简体   繁体   English

CloudFormation:删除整个嵌套堆栈

[英]CloudFormation: Deleting an entire nested stack

I have a CloudFormation stack which is made up of 3 nested stacks:我有一个 CloudFormation 堆栈,它由 3 个嵌套堆栈组成:

Resources:
  ParamsSetup:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: a-params.yaml          
  ResourcePrep:
     Type: AWS::CloudFormation::Stack
     Properties:
       TemplateURL: b-prep.yaml
  Services:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: c-service.yaml

I realized the ResourcePrep nested stack was unnecessary, so I moved the only important resource in that stack into the Services stack and removed the stack from my main template:我意识到ResourcePrep嵌套堆栈是不必要的,所以我将该堆栈中唯一重要的资源移动到Services堆栈中,并从我的主模板中删除了该堆栈:

Resources:
  ParamsSetup:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: a-params.yaml     
  Services:
    Type: AWS::CloudFormation::Stack
    Properties:
      TemplateURL: c-service.yaml

Now I have a problem.现在我有一个问题。 CloudFormation updates fail because the resource in Services already belongs to ResourcePrep , but ResourcePrep shouldn't exist anymore. CloudFormation 更新失败,因为Services中的资源已经属于ResourcePrep ,但ResourcePrep不应再存在。

I had expected that CloudFormation would be smart enough to delete the removed stack, but it isn't.我曾期望 CloudFormation 足够聪明,可以删除已删除的堆栈,但事实并非如此。 The removed stack is still there, and I don't know how to get rid of it.删除的堆栈仍然存在,我不知道如何摆脱它。 Everything I've read says you should never delete a nested stack manually.我读过的所有内容都说您永远不应该手动删除嵌套堆栈。

You have a couple options here, none of which are particularly elegant like what your hoping.您在这里有几个选择,没有一个像您希望的那样特别优雅。

  1. Delete out the stack and leave the resource you want commented out (or deleted) for the cloudformation update/rebuild.删除堆栈并留下您想要注释掉(或删除)的资源,以便进行 cloudformation 更新/重建。 After successfully updating with the stack removed, readd the resource you wanted/uncomment.在删除堆栈成功更新后,读取您想要/取消注释的资源。
  2. If the resource needs to be persisted, add a deletion retain parameter onto the resource, run the update, then delete the entire stack.如果需要持久化资源,请在资源上添加删除保留参数,运行更新,然后删除整个堆栈。 After update complete re-add/reassociate the existing resource with the stack of your choosing.更新完成后重新添加/重新关联现有资源与您选择的堆栈。
  3. Create an identical resource in the stack of your choosing with a different name and delete the odd stack.在您选择的堆栈中创建一个具有不同名称的相同资源并删除奇数堆栈。

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

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