Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enabling versioning for s3 bucket object

I want to enable versioning for my s3 bucket object aka nested files inside my bucket.

object = s3.Bucket('ben-uguru').Object('db.sqlite')
object.configure_versioning(versioning=True)
print object

In this case I'd want the file 'db.sqlite' inside the bucket 'ben-uguru' have versioning enabled. However the problem that I get is AttributeError: 's3.Object' object has no attribute 'configure_versioning'

like image 800
Biplov Avatar asked Nov 15 '25 16:11

Biplov


1 Answers

With boto3, check and change versioning state.

import boto3


bucket_name = 'avilpage'

s3 = boto3.resource('s3')
versioning = s3.BucketVersioning(bucket_name)

# check status
print(versioning.status)

# enable versioning
versioning.enable()

# disable versioning
versioning.suspend()

S3 Docs: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#bucketversioning

like image 89
Pandikunta Anand Reddy Avatar answered Nov 17 '25 08:11

Pandikunta Anand Reddy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!