Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Boto3 get file list without authentication

I was wondering if someone can help me with this. I am trying to get a list of files in an s3 bucket by using boto3 without authenticating. I can accomplish this using aws s3 ls s3://mysite.com/ --no-sign-request --region us-east-2, but I am trying to do this in a pythonic manner using boto3.

Currently, when I try using boto.session.Session(), it is asking for credentials.

Thanks

like image 201
securisec Avatar asked Dec 11 '25 04:12

securisec


1 Answers

I think a Session always requires credentials. You should be able to disable signing and use boto3.resource('s3') to access the bucket instead.

According to this answer:

from botocore.handlers import disable_signing
resource = boto3.resource('s3')
resource.meta.client.meta.events.register('choose-signer.s3.*', disable_signing)

And then it should be a case of:

bucket = resource.Bucket('mysite.com')

for item in bucket.objects.all():
    print(item.key)
like image 75
alitheg Avatar answered Dec 13 '25 16:12

alitheg