Reading an JSON file from S3 using Python boto3

前端 未结 5 938
灰色年华
灰色年华 2020-12-08 04:41

I kept following JSON in S3 bucket \'test\'

{
  \'Details\' : \"Something\" 
}

I am using following code to read this JSON and printing the

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-08 05:07

    You can use the below code in AWS Lambda to read the JSON file from the S3 bucket and process it using python.

    import json
    import boto3
    import sys
    import logging
    
    # logging
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)
    
    VERSION = 1.0
    
    s3 = boto3.client('s3')
    
    def lambda_handler(event, context):
        bucket = 'my_project_bucket'
        key = 'sample_payload.json'
        
        response = s3.get_object(Bucket = bucket, Key = key)
        content = response['Body']
        jsonObject = json.loads(content.read())
        print(jsonObject)
    

提交回复
热议问题