Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I'm aware that with Boto 2 it's possible to open an S3 object as a string with:

get_contents_as_string() http://boto.readthedocs.org/en/latest/ref/file.html?highlight=contents%20string#boto.file.key.Key.get_contents_as_string

Is there an equivalent function in boto3?

closed

1 Answer

0 votes
by (44.4k points)
selected by
 
Best answer

read() will return bytes, so for Python 3 make sure to use decode() if you want a string to be returned.

import boto3

s3 = boto3.resource('s3')

obj = s3.Object(bucket, key)

obj.get()['Body'].read().decode('utf-8')

Related questions

0 votes
1 answer
asked Jul 23, 2019 in AWS by yuvraj (19.1k points)

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...