0 votes
1 view
in AWS by (18.5k 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?

1 Answer

0 votes
by (43.1k 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 (18.5k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...