Dilli Dilli - 4 months ago 42
Python Question

boto3 version and appending if changes are made to file

I've written a call to upload a file inside boto3 bucket.
In the call you're required to pass in filename, bucket.
It'll then upload the file to bucket.
However, I'm trying to add versions for each files uploaded to a bucket. So to achieve that I enabled versioning for my bucket; that then gave me versions for files I uploaded to to that bucket.

bucketFile = s3.meta.client.upload_file(filename, str(bucket),filename)

Then to get a object version of that file I uploaded, I do the following

objectSummary = s3.ObjectSummary(bucket,filename)
object = objectSummary.get()
versionID = object.get('VersionId')

The following code gives me a Version-id for every file I upload to that bucket.
So what I am trying to do is
---> Get a version for a file
----> Append that version to my local database like this

versionsAdd = versions(version_url=versionID, filename=filename)

However the difficult part for me is that, I don't want to append that version if the file content is still same. boto3 gives me versionID regardless of what file contents are. So for me, I want to be able to read a file and compare it with my existing file in my bucket. If there are changes made on a file, I'd only then like to append it under my version in local database. If the file uploaded to bucket are still same contents --> just skip that and not add on my local database.


You can use the ETag associated with an object in Amazon S3 to compare objects and determine whether they are identical. It is an MD5 checksum of the object contents.

If the new version has the same ETag as the previous version, simply skip over it.