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 in AWS by akhtar
• 27,980 points
35 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 by MD
• 64,820 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
1,057 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 in AWS by MD
• 64,820 points
77 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 7 in AWS by MD
• 64,820 points
36 views