Home > Net >  How to configure AWS S3 versioning only for restoring deleted files, not keeping multiple versions
How to configure AWS S3 versioning only for restoring deleted files, not keeping multiple versions

Time:12-10

The Goal

I'd like to set up our bucket so that files can be restored in case they're accidentally deleted. I don't want to keep multiple versions of a file, however.

Files on S3 should look either like this:

  • image.jpg (current)
  • image.jpg (non-current)

or this:

  • [delete marker] (current)
  • image.jpg (non-current)

Action Taken

I've enabled versioning on my bucket, and I've set the lifecycle policy as pictured below. Is this correct?

enter image description here enter image description here

CodePudding user response:

Yes, your lifecycle policy is correct.


However, do note that you may have multiple versions that are stored if they are all created within the same day as the minimum duration of days after objects become noncurrent is currently 1.

You cannot "prevent" multiple versions from existing simultaneously but you can prevent them from existing from at least 1 day1 after the last updated timestamp.

With the above policy, all versions - except the latest version of the file 1 non-current version before it - will be deleted at:

latest object modified time 1 day & then rounded to next day midnight UTC

e.g.

  • Version 1 > A.txt created > Thu 9th December 10:00 UTC
  • Version 2 > A.txt updated > Thu 9th December 12:00 UTC
  • Version 3 > A.txt updated > Thu 9th December 13:00 UTC

In this case, version 3 is the latest current version & version 2 is the latest non-current version so version 1 would be scheduled for deletion.

Version 1 would be deleted on:

Thu 9th December 13:00 UTC 1 day & then rounded to next day midnight UTC

Fri 9th December 13:00 rounded to next day midnight UTC

Saturday 10th December 00:00 UTC

Just pointing out FYI that there is the 1 day "grace period".


1 1 day as in (1 day duration of time needed to round up to next day midnight UTC)

  • Related