CloudFormation 支持 "Expired Object Delete Marker"

Support for "Expired Object Delete Marker" with CloudFormation

在打开版本控制的情况下创建 S3 存储桶时,如何使用 CloudFormation 启用生命周期选项以在没有 "Non Current" 个剩余对象时删除 "Object Delete Markers"。

请参阅 Examples of Lifecycle Configuration 文档中使用 ExpiredObjectDeleteMarker 的 示例 8

<LifecycleConfiguration>
    <Rule>
        ...
        <Expiration>
           <ExpiredObjectDeleteMarker>true</ExpiredObjectDeleteMarker>
        </Expiration>
        <NoncurrentVersionExpiration>     
            <NoncurrentDays>30</NoncurrentDays>    
        </NoncurrentVersionExpiration>
    </Rule>
</LifecycleConfiguration>

By setting the ExpiredObjectDeleteMarker element to true in the Expiration action, you direct Amazon S3 to remove expired object delete markers. Amazon S3 will remove an expired object delete marker no sooner than 48 hours after the object expired.

这可以通过 UI 实现,但是我无法通过 CloudFormation 找到对此支持的引用:Amazon S3 Lifecycle Rule

编写 CloudFormation 语法时没有选项。他们没有使用原始的 S3 LifecycleConfiguration,而是出于 CloudFormation 的目的重命名了属性,并忘记了这个特定的属性(以及其他几个)。

问这个问题的更好的地方是 CloudFormation forums,在 AWS 工作的人实际上可以通过实施缺失的规则注意到并解决问题。

在论坛中被问及的另一个缺失规则 (AbortIncompleteMultipartUpload) 的示例:https://forums.aws.amazon.com/thread.jspa?messageID=746212

作为解决方法,一种可能的解决方案是使用 CloudFormation 自定义资源,它可以使用 Lambda 函数实现。 http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources-lambda.html

中描述了该过程

我已将我的解决方案发布为 GitHub 要点 here

基本上,此 CloudFormation 模板使用 Boto 创建一个用 Python 编写的 Lambda 函数,并将其传递给 set/unset ExpiredObjectDeleteMarker 上的存储桶名称。存储桶生命周期的其余部分 NOT 由函数控制。

AWS 根据对 github 个问题的投票确定 CloudFormation 路线图的优先级。投票添加 ExpiredObjectDeleteMarker 支持 here