Skip to content

Instantly share code, notes, and snippets.

@amrakm
Created August 24, 2022 15:13
Show Gist options
  • Save amrakm/e6b475cbe7856d031e2940f68bbd5b07 to your computer and use it in GitHub Desktop.
Save amrakm/e6b475cbe7856d031e2940f68bbd5b07 to your computer and use it in GitHub Desktop.
load json from s3
import boto3
import json
s3_bucket = 'production-db'
s3 = boto3.client('s3')
def get_json_from_s3(key: str, bucket=s3_bucket):
"""
Retrieves the json file containing responses from s3. returns a dict
Args:
key (str): file path to the json file
Returns:
dict: json style dict
"""
data = s3.get_object(Bucket=s3_bucket, Key=key)
json_text_bytes = data["Body"].read().decode("utf-8")
json_text = json.loads(json_text_bytes)
return json_text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment