I have an s3 bucket with a folder which has many objects in it and I would like to write a python boto3 code which will zip those files and upload that zip file back into the bucket.
s3 = boto3.resource('s3')
my_bucket = s3.Bucket(bucket_name)
for file in my_bucket.objects.all():
print(file)
This fetches the objects and file.key gives us the keys. Instead of downloading the files to a folder and then zipping that and sending it to S3 is there another way? if so can someone provide me a code for this?
Thanks in advance!
CodePudding user response:
is there another way?
Sadly there is not. You have to download the files, zip them, and re-upload to S3. To speed up this process, you can perform all operations on a good ec2 instance and use S3 gateway endpoint for fast exchange of files with s3.