Created
August 24, 2022 15:13
-
-
Save amrakm/e6b475cbe7856d031e2940f68bbd5b07 to your computer and use it in GitHub Desktop.
load json 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 | |
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