How to list contents of a bucket with boto3

0 votes

Hi Guys,

I want to list the files of my S3 bucket using the boto3 module. But I am not able to find any script. Can anyone help me with this?

Sep 21, 2020 in AWS by akhtar
• 38,230 points
13,077 views

1 answer to this question.

0 votes

Hi@akhtar,

You can create a session for an S3 bucket. After that, you need to create your own customized code. You can take help from the below example.

from boto3.session import Session
ACCESS_KEY='your_access_key'
SECRET_KEY='your_secret_key'
session = Session(aws_access_key_id=ACCESS_KEY, aws_secret_access_key=SECRET_KEY)
s3 = session.resource('s3')
your_bucket = s3.Bucket('your_bucket'
for s3_file in your_bucket.objects.all():
    print(s3_file.key)
answered Sep 21, 2020 by MD
• 95,440 points

Related Questions In AWS

0 votes
1 answer

How to list the contents of Amazon S3 by modified date?

One easy solution would be probably to ...READ MORE

answered Aug 21, 2018 in AWS by datageek
• 2,530 points
52,167 views
0 votes
1 answer

How to fetch a list of items (like a SQL IN clause)

You can use this as this worked ...READ MORE

answered Oct 26, 2018 in AWS by Priyaj
• 58,090 points
9,600 views
0 votes
1 answer
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
3,458 views
+2 votes
1 answer
0 votes
1 answer

How to open S3 object as a string with Boto3?

Hi@akhtar, If you want to return a string, you ...READ MORE

answered Sep 21, 2020 in AWS by MD
• 95,440 points
3,865 views
0 votes
1 answer

How to create a security group in AWS with Boto3?

Hi@akhtar, You can create a new security group ...READ MORE

answered Oct 11, 2020 in AWS by MD
• 95,440 points
3,752 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