Skip to content

Instantly share code, notes, and snippets.

@mikegrima
Last active September 14, 2017 17:53
Show Gist options
  • Save mikegrima/5ad31821da1651ac5b597fd6191b72fd to your computer and use it in GitHub Desktop.
Save mikegrima/5ad31821da1651ac5b597fd6191b72fd to your computer and use it in GitHub Desktop.
Boto3 Read Object from S3
import boto3
BUCKET = "LOLSOMEBUCKET"
KEY = "LOL/SOME/KEY"
client = boto3.client("s3")
result = client.get_object(Bucket=BUCKET, Key=KEY)
compressed = False
# Read the object (not compressed):
if not compressed:
text = result["Body"].read().decode()
else:
# If compressed (Python 3):
import gzip
text = gzip.decompress(result["Body"].read()).decode()
print(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment