Intellipaat 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

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

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...