Lets start with some code . We will first enable versioning on bucket and then upload few versions to bucket via S3 API using python SDK.
|
import boto3 #Endpoint information #Bucket name #Connect to your Objects endpoint.
#Enable versioning #Get versioning status of Bucket |
Find this code on git
Output :
|
Creating bucket : bucket-from-api Enabling versioning on bucket : bucket-from-api Versioning status of bucket : bucket-from-api {u'Status': 'Enabled', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RetryAttempts': 0, 'HostId': '', 'RequestId': '15FCBD036858B7A4', 'HTTPHeaders': {'transfer-encoding': 'chunked', 'accept-ranges': 'bytes', 'vary': 'Origin', 'server': 'NutanixS3', 'x-amz-request-id': '15FCBD036858B7A4', 'date': 'Mon, 16 Mar 2020 08:56:31 GMT', 'content-type': 'application/xml'}}} |
Related API :
- Put_bucket_versioning : Is the API to enable/suspend versioning.
- Get_bucket_versioning : To get the bucket versioning status.
- To suspend bucket versioning, change : versioning_config = {"Status":"Enabled"} -> versioning_config = {"Status":"Disabled"} in above code.
Lets upload few versions and check how things look :
|
import boto3 #Endpoint information #Bucket name #Connect to your Objects endpoint.
#Enable versioning #Get versioning status of Bucket #Upload 3 versions |
Find this code on git
In above code :
- We enabled versioning on bucket
- Validate the bucket versioning.
- I am uploading object=moviename, three times with different data. Which created 3 different versions of the same object.
Output :
|
Creating bucket : bucket-from-api Enabling versioning on bucket : bucket-from-api Versioning status of bucket : bucket-from-api {u'VersionId': '209393', u'ETag': '"175b13d8ce8d83053c15f2687c916d78"', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RetryAttempts': 0, 'HostId': '', 'RequestId': '15FCBEFD7BDEC565', 'HTTPHeaders': {'content-length': '0', 'accept-ranges': 'bytes', 'vary': 'Origin', 'server': 'NutanixS3', 'etag': '"175b13d8ce8d83053c15f2687c916d78"', 'x-amz-request-id': '15FCBEFD7BDEC565', 'date': 'Mon, 16 Mar 2020 09:32:44 GMT', 'x-amz-version-id': '209393'}}} ********** {u'VersionId': '209394', u'ETag': '"607cf407c1ec1582849e374324e76d48"', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RetryAttempts': 0, 'HostId': '', 'RequestId': '15FCBEFD82A00BBD', 'HTTPHeaders': {'content-length': '0', 'accept-ranges': 'bytes', 'vary': 'Origin', 'server': 'NutanixS3', 'etag': '"607cf407c1ec1582849e374324e76d48"', 'x-amz-request-id': '15FCBEFD82A00BBD', 'date': 'Mon, 16 Mar 2020 09:32:44 GMT', 'x-amz-version-id': '209394'}}} ********** {u'VersionId': '209395', u'ETag': '"f381fa744927007d8ca0aa2d66d19b45"', 'ResponseMetadata': {'HTTPStatusCode': 200, 'RetryAttempts': 0, 'HostId': '', 'RequestId': '15FCBEFD89AFE0E8', 'HTTPHeaders': {'content-length': '0', 'accept-ranges': 'bytes', 'vary': 'Origin', 'server': 'NutanixS3', 'etag': '"f381fa744927007d8ca0aa2d66d19b45"', 'x-amz-request-id': '15FCBEFD89AFE0E8', 'date': 'Mon, 16 Mar 2020 09:32:45 GMT', 'x-amz-version-id': '209395'}}} ********** |
You may notice 'VersionId' returned in put_object response. And this is the unique identifier for a particular object.
From above code and output, this is how object version to content mapping look :
- Object with version '209393' has content = “The Dark Knight”
- Version '209394' has content = “Star Wars”
- Version '209395' is the latest version (since this was the last upload) and has content = “The God Father”