How to open S3 object as a string with Boto3

0 votes

Hi Guys,

I have objects in the AWS S3 bucket. I want to open S3 object as a string with Boto3. How can I do that?

Sep 21, 2020 in AWS by akhtar
• 38,260 points
4,384 views

1 answer to this question.

0 votes

Hi@akhtar,

If you want to return a string, you have to decode using the right encoding as shown below.

import boto3
import botocore
s3 = boto3.resource('s3')
obj = s3.Object(bucket, key)
obj.get()['Body'].read().decode('utf-8') 
answered Sep 21, 2020 by MD
• 95,460 points

Related Questions In AWS

0 votes
1 answer

How do I write an S3 Object to a file?

While IOUtils.copy() and IOUtils.copyLarge() are great, I would prefer the old ...READ MORE

answered Jul 13, 2018 in AWS by Hammer
• 360 points
4,637 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to list contents of a bucket with boto3?

Hi@akhtar, You can create a session for an ...READ MORE

answered Sep 21, 2020 in AWS by MD
• 95,460 points
13,363 views
0 votes
1 answer

How to download S3 Objects With Python and Boto3?

Hi@akhtar, You can download one file from a ...READ MORE

answered Oct 8, 2020 in AWS by MD
• 95,460 points
2,626 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP