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,210 points
8,904 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,300 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
32,228 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,140 points
6,665 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
1,292 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,300 points
1,019 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,300 points
1,006 views