4
votes

When creating an S3 Bucket with Versioning turned on how do you use CloudFormation to enable the lifecycle option to delete "Object Delete Markers" when there are no "Non Current" objects remaining.

See Example 8 in the Examples of Lifecycle Configuration documentation that uses ExpiredObjectDeleteMarker:

<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.

This is achievable via the UI, however I cannot find reference to this support via CloudFormation: Amazon S3 Lifecycle Rule

3
@yarin thanks for the reference. It supports John's point that the option is apparently missing from CloudFormation. Unless you see something there that both of us missed? - Amos Shapira
@amos , you are right,i just answered too quickly - yarin

3 Answers

4
votes

At the time of writing CloudFormation syntax doesn't have the option. Instead of using the original S3 LifecycleConfiguration they renamed the properties for CloudFormation purposes and forgot this particular one (and a couple of others).

A much better place to ask this question would be CloudFormation forums, where people working at AWS can actually notice and fix the problem by implementing the missing rule.

Example of another missing rule (AbortIncompleteMultipartUpload) that was asked about in the forums: https://forums.aws.amazon.com/thread.jspa?messageID=746212

As a workaround, one possible solution is to use CloudFormation Custom Resources which can be implemented using a Lambda function. The process is described at http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources-lambda.html

2
votes

AWS prioritizes the CloudFormation roadmap based on votes on github issues. Vote for adding ExpiredObjectDeleteMarker support here

0
votes

I've posted my solution as a GitHub gist here.

Basically, this CloudFormation template creates a Lambda function written in Python using Boto and passes it the name of the bucket to set/unset ExpiredObjectDeleteMarker on. The rest of the bucket life cycle is NOT controlled by the function.