I can't find Python source code example to update/overwrite an object in an Amazon S3 Bucket.
Is this possible?
I can't find Python source code example to update/overwrite an object in an Amazon S3 Bucket.
Is this possible?
From the docs : https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.put_object
If you want to overwrite the object you just upload the file with the same name and if that name already exists it'll be done automatically.
Extra note: If you want to keep all historic versions of the object enable versioning on the bucket.
As mentioned in the other answer if you push the file with the same name it will overwrite it, just for completeness here is an actual implementation using boto3
import boto3
s3 = boto3.resource(‘s3’)
try:
s3.upload_file(file_path, bucket, key)
except ClientError as e:
print("Error")