Read s3 files (PDF)

PHOTO EMBED

Wed May 29 2024 09:59:37 GMT+0000 (Coordinated Universal Time)

Saved by @krishna01 ##read_s3 ##read_s3_pdf ##read_s3_files

import boto3

def read_s3_file(bucket_name, file_name):
    s3 = boto3.client('s3')
    try:
        response = s3.get_object(Bucket=bucket_name, Key=file_name)
        return response['Body'].read().decode('utf-8')
    except Exception as e:
        print(f"Error reading file from S3: {e}")
        return None
content_copyCOPY