One way to see the contents would be:

for my_bucket_object in my_bucket.objects.all():
    print(my_bucket_object)
Answer from garnaat on Stack Overflow
🌐
AWS
docs.aws.amazon.com › goto › boto3 › s3-2006-03-01 › ListObjects
list_objects - Boto3 1.43.56 documentation
Resources are available in boto3 via the resource method. For more detailed instructions and examples on the usage of resources, see the resources user guide. ... The following example shows how to use an Amazon S3 bucket resource to list the objects in the bucket.
Discussions

listing the top level contents of a s3 bucket with Prefix and Delimiter
Apologies for what sounds like a very basic question. In this example from the s3 docs is there a way to list the continents? I was hoping this might work, but it doesn't seem to: import boto3 ... More on github.com
🌐 github.com
17
June 17, 2015
Using boto3 to list only all key names of files in a bucket - best methods when the bucket is ridiculously big?
Take a look at S3 Inventory. It's not realtime, but it's a better option than doing a full key enumeration when dealing with large buckets. https://docs.aws.amazon.com/AmazonS3/latest/userguide/storage-inventory.html More on reddit.com
🌐 r/aws
4
2
June 20, 2021
boto3 s3 in Python - how to search objects
There's no possibility of remotely searching files with just S3. If you know the max length of the first line, and you can properly handle multi-line responses for files with shorter line lengths, you could use the Range option to retrieve the first 0-X bytes of each file for searching within your script... https://stackoverflow.com/questions/30075978/reading-part-of-a-file-in-s3-using-boto For any binary file, you would need to download the file, decompress it or otherwise make it readable, then search it unless you could also do that processing on a Range returned subset of the file. More on reddit.com
🌐 r/aws
7
3
May 22, 2020
boto3 to delete s3 buckets and their objects
Set a retention policy on the bucket, come back the next day and delete the now empty buckets. More on reddit.com
🌐 r/aws
7
0
February 4, 2023
🌐
DEV Community
dev.to › aws-builders › how-to-list-contents-of-s3-bucket-using-boto3-python-47mm
How to List Contents of s3 Bucket Using Boto3 Python? - DEV Community
October 12, 2021 - Note: In addition to listing objects present in the Bucket, it'll also list the sub-directories and the objects inside the sub-directories. Use the below snippet to list objects of an S3 bucket. ... import boto3 session = boto3.Session(aws_access_key_id='<your_access_key_id>', aws_secret_access_key='<your_secret_access_key>') #Then use the session to get the resource s3 = session.resource('s3') my_bucket = s3.Bucket('stackvidhya') for my_bucket_object in my_bucket.objects.all(): print(my_bucket_object.key)
🌐
GitHub
github.com › boto › boto3 › issues › 134
listing the top level contents of a s3 bucket with Prefix and Delimiter · Issue #134 · boto/boto3
June 17, 2015 - import boto3 s3 = boto3.resource('s3') bucket = s3.Bucket('edsu-test-bucket') for o in bucket.objects.filter(Delimiter='/'): print(o.key) However, the equivalent code using boto2 does seem to work the way I expect: import boto s3 = boto.connect_s3() bucket = s3.get_bucket('edsu-test-bucket') for o in bucket.list(delimiter='/'): print(o.name) Reactions are currently unavailable ·
Author   boto
🌐
Medium
habil.medium.com › how-to-list-aws-s3-directory-contents-using-python-and-boto3-6281f5c3dea3
How to List AWS S3 Directory Contents Using Python and Boto3 | by Habil BOZALİ | Medium
February 26, 2025 - import boto3 import csv def list_bucket(): # Configuration bucket = "your-bucket-name" folder = "path/to/folder" # Initialize S3 client s3 = boto3.resource("s3", aws_access_key_id="YOUR_ACCESS_KEY", aws_secret_access_key="YOUR_SECRET_KEY" ) # Get bucket reference s3_bucket = s3.Bucket(bucket) # List files and extract relative paths files_in_s3 = [ f.key.split(folder + "/")[1] for f in s3_bucket.objects.filter(Prefix=folder).all() ] # Write results to file with open('bucket-contents.txt', 'w', encoding='UTF8') as file: file.write(str(files_in_s3)) if name == 'main': list_bucket()
🌐
GeeksforGeeks
geeksforgeeks.org › devops › how-to-retrieve-the-sub-folders-names-in-s3-bucket-using-boto3
How To Retrieve the Sub Folders Names In S3 Bucket Using Boto3? - GeeksforGeeks
July 23, 2025 - ListObjectsV2: This is an API operation to list objects inside a bucket in AWS S3. The operation supports pagination and can be filtered with prefixes and delimiters. It is the enhanced version of the ListObjects operation, now equipped with ...
🌐
Reddit
reddit.com › r/aws › using boto3 to list only all key names of files in a bucket - best methods when the bucket is ridiculously big?
r/aws on Reddit: Using boto3 to list only all key names of files in a bucket - best methods when the bucket is ridiculously big?
June 20, 2021 -

Till now, to check the names or last_modified details of all objects in a bucket, what I did was the following:

import boto3

s3r = boto3.resource('s3',  aws_access_key_id=access_key_id,  aws_secret_access_key=access_key_secret)

bucket_items = list(s3r.Bucket('BucketName').objects.all())

However, this seems to be a terrible idea for handling it when the bucket gets too big. Running this on a machine with 8GB RAM threw a memory error!

I assume I have to be doing something wrong if only fetching the file keys is this difficult. Is the objects.all() method actually saving details of the file's contents into memory when I call it?

🌐
AWS
docs.aws.amazon.com › boto3 › latest › reference › services › s3.html
S3 - Boto3 1.43.58 documentation
Resources are available in boto3 via the resource method. For more detailed instructions and examples on the usage of resources, see the resources user guide. ... The following example shows how to use an Amazon S3 bucket resource to list the objects in the bucket.
Find elsewhere
🌐
Alexwlchan
alexwlchan.net › 2017 › listing-s3-keys
Listing keys in an S3 bucket with Python – alexwlchan
import boto3 s3 = boto3.client('s3') s3.list_objects_v2(Bucket='example-bukkit')
🌐
AWS
docs.aws.amazon.com › boto3 › latest › reference › services › s3 › client › list_objects.html
list_objects - Boto3 1.43.57 documentation
Do you have a suggestion to improve this website or boto3? Give us feedback. ... This operation is not supported for directory buckets. Returns some or all (up to 1,000) of the objects in a bucket. You can use the request parameters as selection criteria to return a subset of the objects in ...
🌐
AWS
docs.aws.amazon.com › boto3 › latest › reference › services › s3 › client › list_objects_v2.html
list_objects_v2 - Boto3 1.43.57 documentation
Do you have a suggestion to improve this website or boto3? Give us feedback. ... Returns some or all (up to 1,000) of the objects in a bucket with each request. You can use the request parameters as selection criteria to return a subset of the objects in a bucket. A 200 OK response can contain valid or invalid XML. Make sure to design your application to parse the contents of the response and handle it appropriately. For more information about listing ...
🌐
Amazon Web Services
boto3.amazonaws.com › v1 › documentation › api › latest › reference › services › s3 › client › get_object.html
get_object - Boto3 1.43.57 documentation
The s3:GetObjectVersion permission is not required in this scenario. If the object that you request doesn’t exist, the error that Amazon S3 returns depends on whether you also have the s3:ListBucket permission. If you have the s3:ListBucket permission on the bucket, Amazon S3 returns an HTTP status code 404 Not Found error.
🌐
Cloud Analytics Blog
awsanalyticsblog.wordpress.com › 2023 › 03 › 12 › how-to-list-objects-in-an-s3-bucket-using-boto3
How to List Objects in an S3 Bucket Using Boto3 – Cloud Analytics Blog
April 1, 2023 - Create the boto3 S3 client using the boto3.client('s3') method. Invoke the list_objects_v2() method with the bucket name to list all the objects in the S3 bucket.
🌐
YouTube
youtube.com › watch
Boto3 Tutorial - List S3 Buckets - YouTube
This lesson demonstrates using the Boto3 S3 client and Boto3 S3 resource to list S3 buckets. Also, you'll cover your code with unit tests using the moto libr...
Published   February 12, 2023
🌐
CopyProgramming
copyprogramming.com › howto › boto3-python-list-objects
Python: Python Boto3 - Retrieving a List of Objects
April 30, 2023 - Python boto, list contents of specific dir in bucket, The following code will list all the files in specific dir of the S3 bucket: import boto3 s3 = boto3.client('s3') def get_all_s3_keys(s3_path): """ Get a list of all keys in an S3 bucket.
🌐
YouTube
youtube.com › aws made easy
How to list files in S3 using Python | AWS S3 Python Boto3 | Step by step tutorial - YouTube
n this video , i show you how to get the list of files in S3 bucket using Python. We use the AWS Boto3 module to do this operation. #AWSPython #Boto3 #Lambda...
Published   March 28, 2022
Views   8K
🌐
Analytics Vidhya
analyticsvidhya.com › home › using aws s3 with python boto3
Using AWS S3 with Python boto3 - Analytics Vidhya
December 29, 2022 - To get the file or object’s details, such as last modification time, storage class, content length, size in bytes, etc., use the head_object() method with Key and Bucket parameters. my_bucket = "enter your s3 bucket name from which objects ...