简体   繁体   English

使用相同的 CloudFormation 模板来参数化 DeletionPolicy?

[英]Same CloudFormation template to parameterize DeletionPolicy?

As a DevOps guy I wanted to use the same template to provision both Dev and Prod stacks... Where dev stacks should not have any DeletionPolicy but Prod stacks should utilize a DeletionPolicy作为一个 DevOps 人员,我想使用相同的模板来配置 Dev 和 Prod 堆栈......其中 dev 堆栈不应该有任何DeletionPolicy但 Prod 堆栈应该使用DeletionPolicy

So, at first sight CFT gives an ok tooling for this but.... there is no possibility to parametrize S3 DeletionPolicy (that I've been able to locate at least)...因此,乍一看,CFT 为此提供了一个不错的工具,但是.... 不可能对 S3 DeletionPolicy进行参数化(至少我已经能够找到)...

Here's some threads I dug up这是我挖掘的一些线索

The suggested workaround from AWS was to make the whole resource conditional, which leads us duplicating the resource and create a „Deletable and „Undeletable versions of it and all the depending resources should handle that condition... AWS建议的解决方法是使整个资源有条件,这导致我们复制资源并创建它的„Deletable删除和„Undeletable版本,所有依赖资源都应处理该条件......

This seems wonky and bloated, is there a way to parameterize this or a better methodology to accomplish my end goal?这看起来很奇怪而且很臃肿,有没有办法参数化这个或更好的方法来实现我的最终目标?

Doesn't seem like there's an option in CFT other than resource duplication.除了资源复制之外,CFT 中似乎没有其他选项。

What you can do is create a Lambda with a Python script that would setup the S3 deletion policy.您可以做的是使用 Python 脚本创建一个 Lambda,该脚本将设置 S3 删除策略。 That Lambda function can be triggered through SNS during CloudFormation stack creation.该 Lambda 函数可以在 CloudFormation 堆栈创建期间通过 SNS 触发。 Here is described how this can be configured: Is it possible to trigger a lambda on creation from CloudFormation template这里描述了如何配置: Is it possible to trigger a lambda on creation from CloudFormation template

But in your particular case I'd go with resource duplication in same CFT.但是在您的特定情况下,我会在同一个 CFT 中使用资源重复。

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

相关问题 Cloudformation模板格式错误:每个DeletionPolicy成员必须是一个字符串 - Cloudformation Template format error: Every DeletionPolicy member must be a string 我们可以在AWS cloudformation模板中参数化逻辑ID吗 - Can we parameterize Logical ID in AWS cloudformation template ec2 实例缺少 Cloudformation DeletionPolicy 策略 - Cloudformation DeletionPolicy policy missing for ec2 instance Cloudformation:参数化参数的名称? - Cloudformation: parameterize the name of a parameter? Cloudformation:在 S3 存储桶上遇到不受支持的属性 DeletionPolicy - Cloudformation : Encountered unsupported property DeletionPolicy on S3 Bucket Cloudformation 删除删除 S3 存储桶,尽管有 DeletionPolicy:保留 - Cloudformation deletion deleting the S3 bucket in spite of DeletionPolicy: Retain 如何从 CloudFormation 模板中的同一 AWS 角色担任 AWS 角色? - How to assume AWS role from the same AWS role in CloudFormation template? Lambda 和 S3 资源可以存在于同一个 CloudFormation 模板中吗? - Can Lambda and S3 resources exist in the same CloudFormation template? 如何在同一个 CloudFormation 模板中声明多个相似的资源组? - How to declare multiple and similar groups of resources in the same CloudFormation template? 如何在CloudFormation模板中同时使用Sub和GetAtt函数? - How to use Sub and GetAtt functions at the same time in CloudFormation template?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM