简体   繁体   English

删除 AWS 云形成堆栈及其创建的资源

[英]Delete AWS Cloud formation stack with resources created by it

Based on this page I can do:基于页面,我可以执行以下操作:

aws cloudformation delete-stack \
    --stack-name my-stack

It says I can attach the command: [--retain-resources <value>]它说我可以附加命令: [--retain-resources <value>]

Does that mean that if I don't specify that line, all the resources created by the stack will be removed?这是否意味着如果我不指定那一行,堆栈创建的所有资源都将被删除? I'm trying to delete everything generated by the stack, which is a lot.我正在尝试删除堆栈生成的所有内容,这很多。

How can I achieve this?我怎样才能做到这一点?

Thanks谢谢

Yes, those resources will be kept if you specify the [--retain-resources <value>] , if you dont Cloudformation will delete all the resources in the stack name (including the nested stacks as well) you are providing given you have permissions to do.是的,如果您指定[--retain-resources <value>] ,这些资源将被保留,如果您不指定,Cloudformation 将删除您提供的堆栈名称中的所有资源(包括嵌套堆栈),前提是您有权限去做。 If any of the resources inside the cloudformation stack has retain policy set they won't be deleted.如果 cloudformation 堆栈中的任何资源具有保留策略集,它们将不会被删除。

During deletion, AWS CloudFormation deletes the stack but does not delete the retained resources.在删除期间,AWS CloudFormation 会删除堆栈,但不会删除保留的资源。

From the same page aws cloudformation delete-stack从同一页面aws cloudformation delete-stack

You might wanna read this too How do I retain some of my resources when I delete an AWS CloudFormation stack?您可能也想阅读这篇文章 当我删除 AWS CloudFormation 堆栈时如何保留我的一些资源?

You can specify the retain policy as well in cloudformation template.您也可以在 cloudformation 模板中指定保留策略

In vase if you want to delete all the CFN stacks created in the account, I write small bash script to provide that:在花瓶中,如果您想删除帐户中创建的所有 CFN 堆栈,我编写了小的 bash 脚本来提供:

#!/bin/bash
STACKS=$(aws cloudformation list-stacks --stack-status-filter CREATE_IN_PROGRESS CREATE_COMPLETE ROLLBACK_IN_PROGRESS ROLLBACK_FAILED ROLLBACK_COMPLETE DELETE_IN_PROGRESS DELETE_FAILED UPDATE_IN_PROGRESS UPDATE_COMPLETE_CLEANUP_IN_PROGRESS UPDATE_COMPLETE UPDATE_ROLLBACK_IN_PROGRESS UPDATE_ROLLBACK_FAILED UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS UPDATE_ROLLBACK_COMPLETE REVIEW_IN_PROGRESS --query "StackSummaries[*].StackName" --output text)

for stack in $STACKS
do
    aws cloudformation delete-stack --stack-name $stack
done

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

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