gpt4 book ai didi

amazon-web-services - 如何保护 AWS CloudFormation 堆栈不被删除?

转载 作者:行者123 更新时间:2023-12-04 18:37:18 25 4
gpt4 key购买 nike

我有一个创建三层应用程序的堆栈。我想保护我的堆栈不被意外删除。有什么方法可以保护 AWS CloudFormation 堆栈吗?

此外,我想知道即使我的堆栈被删除,我如何才能停止与被删除的堆栈关联的资源。

最佳答案

有多种方法可以保护 AWS CloudFormation 创建的资源。

保护堆栈

AWS CloudFormation 采用一个描述所需资源的模板,并将其部署为资源堆栈。当删除堆栈时,资源也会被删除。

因此,第一个方法是控制哪些用户有权限删除堆栈。这可以通过身份和访问管理(IAM)分配。

以下是 Controlling Access with AWS Identity and Access Management 文档中的示例:

A sample policy that denies the delete and update stack actions for the MyProductionStack:

{
"Version":"2012-10-17",
"Statement":[{
"Effect":"Deny",
"Action":[
"cloudformation:DeleteStack",
"cloudformation:UpdateStack"
],
"Resource":"arn:aws:cloudformation:us-east-1:123456789012:stack/MyProductionStack/*"
}]
}

策略还可以在执行敏感操作(例如删除堆栈)之前 require use of a Multi-factor Authentication (MFA) code

保护资源

任何具有适当权限的用户仍然可以删除/修改 CloudFormation 创建的资源。因此,保护​​重要资源免受未经授权的用户的影响非常重要。 AWS 建议授予最低权限,以便用户只能控制他们需要的资源,而不能控制更多。

CloudFormation 删除策略

删除策略定义删除堆栈时不应删除的资源。

来自CloudFormation documentation:

With the DeletionPolicy attribute you can preserve or (in some cases) backup a resource when its stack is deleted. You specify a DeletionPolicy attribute for each resource that you want to control. If a resource has no DeletionPolicy attribute, AWS CloudFormation deletes the resource by default.

To keep a resource when its stack is deleted, specify Retain for that resource. You can use retain for any resource. For example, you can retain an Amazon S3 bucket or an Amazon EC2 instance so that you can continue to use or modify those resources after you delete their stacks.

这通常用于在有意删除堆栈后保留资源。例如,保留 Amazon S3 存储桶或 Amazon RDS 数据库。但是,即使堆栈被意外删除,它也可以用于保留资源。

关于amazon-web-services - 如何保护 AWS CloudFormation 堆栈不被删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32602103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com