Skip to main content

Using versioning

When versioning is enabled, a bucket retains the previous versions of objects whenever they are overwritten or deleted. This allows accidental changes and deletions to be undone.

How it works

  • Each PUT creates a new version with its own VersionId; older versions are retained.
  • A DELETE without a VersionId does not physically delete anything, but instead sets a Delete Marker as the latest ‘version’ – the object appears to be deleted, but can be restored.
  • Only the deletion of a specific version (with a VersionId) permanently removes data.
  • Each version occupies memory and is calculated.

Versioning can be enabled (Enabled) or suspended (Suspended) on a per-bucket basis – once enabled, it cannot be completely removed, only suspended.

Enable versioning

aws s3api put-bucket-versioning \
--bucket mein-bucket \
--versioning-configuration Status=Enabled \
--endpoint-url s3.internet1.de

Check status:

aws s3api get-bucket-versioning --bucket mein-bucket \
--endpoint-url https://s3.internet1.de

View versions

aws s3api list-object-versions --bucket mein-bucket --prefix dokumente/ \
--endpoint-url https://s3.internet1.de

This edition includes Versions (all versions with VersionId, IsLatest, LastModified) and DeleteMarkers.

Restore an earlier version

Recommended method: copy the desired version onto itself – this makes it the latest version whilst preserving the version history:

aws s3api copy-object \
--bucket mein-bucket \
--key dokumente/vertrag.pdf \
--copy-source "mein-bucket/dokumente/vertrag.pdf?versionId=ALTE_VERSION_ID" \
--endpoint-url https://s3.internet1.de

Alternatively, download a specific version directly:

aws s3api get-object --bucket mein-bucket --key dokumente/vertrag.pdf \
--version-id ALTE_VERSION_ID vertrag_alt.pdf \
--endpoint-url https://s3.internet1.de

Restoring a deleted object

Remove the delete marker – this will reveal the latest version again:

aws s3api delete-object --bucket mein-bucket --key dokumente/vertrag.pdf \
--version-id DELETE_MARKER_VERSION_ID \
--endpoint-url https://s3.internet1.de

Permanently delete version

aws s3api delete-object --bucket mein-bucket --key dokumente/vertrag.pdf \
--version-id VERSION_ID \
--endpoint-url https://s3.internet1.de

Keeping storage under control

Old versions tend to pile up. Two strategies:

  1. Lifecycle Policies : Automatically delete obsolete versions after X days (NoncurrentVersionExpiration) and clear out expired delete markers.
  2. Manually: regular clean-up via script using list-object-versions + delete-objects.

Integration with Object Lock

Object Lock requires versioning: retention and legal hold protect individual versions from deletion.**