I've multiple files under a specific folder in s3 bucket , I want to create a single zip file of all those files. Is there a way that I can do loop across all the files in s3 bucket and make zip? I am able to do one file but I want to do all files at a time and make one zip out of it (all files in a folder)
Any help is appreciated.
s3 = boto3.client('s3')
zip_buffer = io.BytesIO()
with zipfile.ZipFile(zip_buffer, "a", zipfile.ZIP_DEFLATED, False) as zipper:
infile_object = s3.get_object(Bucket=bucket, Key=object_key)
infile_content = infile_object['Body'].read()
zipper.writestr(file_name, infile_content)
s3.put_object(Bucket=bucket, Key=PREFIX + "test.zip", Body=zip_buffer.getvalue())