gpt4 book ai didi

amazon-web-services - 云形成 : Block deleting resources

转载 作者:行者123 更新时间:2023-12-03 07:14:47 24 4
gpt4 key购买 nike

this question 衍生而来。尝试在更改期间确保云信息模板的安全。

有没有办法真正阻止角色和表的删除?添加政策会有帮助吗?

给出以下模板摘录:

{
...

"Parameters" : {
"ShouldCreateTable" : {
...
"Description" : "If true then the underlying DynamoDB table will be created with the CloudFormation stack."
},
...
},

"Conditions" : {
"CreateDynamoTable" : {"Fn::Equals" : [{"Ref" : "ShouldCreateTable"}, "true"]},
...
},

"Resources" : {

"Get" : {
"Type" : "AWS::Serverless::Function",
"Properties": {
...
"Role": {"Fn::If" : ["CreateRole", {"Fn::GetAtt":["LambdaRole", "Arn"]}, {"Ref":"RoleARN"}]},
"Environment" : {
"Variables" : {
"AppDynamoTable" : { "Fn::If" : ["CreateDynamoTable", {"Ref":"DynamoTable"}, { "Ref" : "TableName" } ] }
}
},
...
}
},

"LambdaRole":{
"Type":"AWS::IAM::Role",
...
},

"DynamoTable" : {
"Type" : "AWS::DynamoDB::Table",
...
}
},

}

最佳答案

解决方案可能是使用 DeletionPolicy Attribute 。您可以轻松地将 "DeletionPolicy": "Retain" 添加到要“阻止”删除的资源中。

AWS CloudFormation keeps the resource without deleting the resource or its contents when its stack is deleted. You can add this deletion policy to any resource type.

在您给定的示例中,这看起来像这样:

"LambdaRole":{
"Type":"AWS::IAM::Role",
"DeletionPolicy" : "Retain",
...
},
"DynamoTable" : {
"Type" : "AWS::DynamoDB::Table",
"DeletionPolicy" : "Retain",
...
}

关于amazon-web-services - 云形成 : Block deleting resources,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50322859/

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