Skip to content

Instantly share code, notes, and snippets.

View prerna-p's full-sized avatar

Prerna prerna-p

  • Amazon Web Services
  • British Columbia
View GitHub Profile
@tobywf
tobywf / boto3-gzip.py
Last active September 10, 2024 22:07
GZIP compressing files for S3 uploads with boto3
from io import BytesIO
import gzip
import shutil
def upload_gzipped(bucket, key, fp, compressed_fp=None, content_type='text/plain'):
"""Compress and upload the contents from fp to S3.
If compressed_fp is None, the compression is performed in memory.
"""