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
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.