Skip to content

Enable versioning on object storage buckets using the S3 API

Overview

Versioning allows you to store multiple versions of an object in a bucket. This feature helps protect against accidental overwrites and deletions by maintaining all previous versions of objects, which you can restore if needed.

  • Multiple object versions count against your object storage quota.
  • You can view the total storage used in the cloud console.
  • Once enabled, versioning cannot be removed, only suspended.

In the Rumble Cloud console, select Storage > Object Storage to view a list of containers. You can view the Bucket Details of a selected container to view the the space used by the bucket in total, including versions. Note that the display does not show the object versions. The object will display the size of the most recent version in the bucket details display.

You can use an S3 client application to make the required versioning API calls. Not all client applications support displaying or manipulating specific object versions.

Enable versioning

To enable versioning via s3cmd:

Bash
s3cmd setversioning s3://versioned-bucket enable

To enable versioning via the AWS CLI:

Bash
aws s3api put-bucket-versioning --bucket versioned-bucket --versioning-configuration Status=Enabled

To enable versioning via python/boto3:

Bash
#!/usr/bin/env python 
import boto3  
bucket = 'versioned-bucket'  
session = boto3.Session() 
s3 = session.resource('s3') 
versioning = s3.BucketVersioning(bucket) 
versioning.enable() 
print("Versioning is " + versioning.status + " on " + bucket)

Suspend versioning

To suspend versioning via s3cmd:

Bash
s3cmd setversioning s3://versioned-bucket disable

To suspend versioning via AWS CLI:

Bash
aws s3api put-bucket-versioning --bucket bucket --versioning-configuration Status=Suspended

To suspend versioning via python/boto3:

Bash
#!/usr/bin/env python 
import boto3  
bucket = 'versioned-bucket'  
session = boto3.Session() 
s3 = session.resource('s3') 
versioning = s3.BucketVersioning(bucket) 
versioning.suspend() 
print("Versioning is " + versioning.status + " on " + bucket)

List versioned objects

To list versions using the AWS CLI:

Bash
aws s3api list-object-versions --bucket versioned-bucket

To list versions via python/boto3:

Bash
#!/usr/bin/env python 
import boto3 
s3 = boto3.client('s3')
s3.list_object_versions(Bucket='versioned-bucket') 

Sample output:

Bash
{'ResponseMetadata': {'RequestId': 'tx000005db40b08b7b23250-00670d66b2-46d27a-cle9-local',
  'HostId': '',
  'HTTPStatusCode': 200,
  'HTTPHeaders': {'date': 'Mon, 14 Oct 2024 18:45:06 GMT',
   'content-type': 'application/xml',
   'transfer-encoding': 'chunked',
   'connection': 'keep-alive',
   'x-amz-request-id': 'tx000005db40b08b7b23250-00670d66b2-46d27a-cle9-local',
   'strict-transport-security': 'max-age=31536000;includeSubDomains;preload'},
  'RetryAttempts': 0},
 'IsTruncated': False,
 'KeyMarker': '',
 'VersionIdMarker': '',
 'Versions': [{'ETag': '"e506d4241cb482d5c3f1279f28f1d8b1-7"',
   'Size': 104857600,
   'StorageClass': 'STANDARD',
   'Key': '100M.file',
   'VersionId': 'zW0.4NhBukb3HWEKMeOjytMMCtubjDu',
   'IsLatest': True,
   'LastModified': datetime.datetime(2024, 10, 14, 18, 27, 36, 268000, tzinfo=tzutc()),
   'Owner': {'DisplayName': 'ProjectName',
    'ID': 'ProjectID$ProjectID'}},
  {'ETag': '"5b0a207d7a18e363cf4d2a09231307b9-7"',
   'Size': 104857600,
   'StorageClass': 'STANDARD',
   'Key': '100M.file',
   'VersionId': 'xppu9AK.pqhZVjA3YFJ4XgRY.T9-LnZ',
   'IsLatest': False,
   'LastModified': datetime.datetime(2024, 10, 14, 18, 27, 21, 985000, tzinfo=tzutc()),
   'Owner': {'DisplayName': 'ProjectName',
    'ID': 'ProjectID$ProjectID'}}],
 'Name': 'versioned-bucket',
 'Prefix': '',
 'MaxKeys': 1000,
 'EncodingType': 'url'}

Delete objects in a versioned bucket

  • Deleting a specific object version is possible and will release space and object count from the quota
  • Deleting objects as normal in a versioned bucket will prevent the object from appearing in normal listings
  • Listing object versions will still show the object/versions but will also show a delete marker for that object version
  • Note: the bucket may appear empty but it still contains object versions that consume space and object quotas

To delete using the AWS CLI:

Bash
aws s3api delete-object  --bucket versioned-bucket --key 100M.file --version-id zW0.4NhBukb3HWEKMeOjytMMCtubjDu