Last active
September 14, 2017 17:53
-
-
Save mikegrima/5ad31821da1651ac5b597fd6191b72fd to your computer and use it in GitHub Desktop.
Boto3 Read Object from S3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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