Home
Head's Up: I'm in the middle of upgrading my site. Most things are in place, but there are something missing and/or broken including image alt text. Please bear with me while I'm getting things fixed.

Read A File From S3 With The boto3 Python Module

Here's how to read an S3 file with either a [TODO: Code shorthand span ] or [TODO: Code shorthand span ] object :

### boto3.client('s3')

python
#!/usr/bin/env python3

import boto3

s3 = boto3.client('s3')
data = s3.get_object(
    Bucket="bucket_name",
    Key="key_path_name"
)
text_contents = data['Body'].read().decode('utf-8')

print(text_contents)

### boto3.resource('s3')

python
#!/usr/bin/env python3

import boto3

s3 = boto3.resource('s3')
s3_object = s3.Object('bucket_name', 'key_path_name')
text_content = s3_object.get()['Body'].read().decode('utf-8')

print(text_content)