Skip to content

Instantly share code, notes, and snippets.

@tal66
Last active August 30, 2023 20:22
Show Gist options
  • Save tal66/ea2c78e1d163746340c8da4a0996b046 to your computer and use it in GitHub Desktop.
Save tal66/ea2c78e1d163746340c8da4a0996b046 to your computer and use it in GitHub Desktop.
read s3 json in lambda
# read json from s3 in lambda
s3_client = boto3.client('s3')
resp = s3_client.get_object(
Bucket='<BUCKETNAME>',
Key='<FILENAME>.json',
)
content = resp['Body'] # botocore.response.StreamingBody
json_obj = json.load(content)
# lambda role policy (if bucket in same account - no need to edit bucket policy)
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:GetObjectAttributes"
],
"Resource": "arn:aws:s3:::<BUCKETNAME>/*"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment