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 in AWS by akhtar
• 27,980 points
77 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 by MD
• 64,820 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,490 points
19,845 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
• 57,680 points
4,253 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
719 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 in AWS by MD
• 64,820 points
35 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 10 in AWS by MD
• 64,820 points
26 views