Can I use boto3 anonymously?

匆匆过客 提交于 2019-12-17 18:52:27

问题


With boto I could connect to public S3 buckets without credentials by passing the anon= keyword argument.

s3 = boto.connect_s3(anon=True)

Is this possible with boto3?


回答1:


Yes. Your credentials are used to sign all the requests you send out, so what you have to do is configure the client to not perform the signing step at all. You can do that as follows:

import boto3
from botocore import UNSIGNED
from botocore.client import Config

s3 = boto3.client('s3', config=Config(signature_version=UNSIGNED))
# Use the client



回答2:


Disable signing

import boto3

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



回答3:


None of these seem to work as of the current boto3 version (1.9.168). This hack (courtesy of an unfixed github issue on botocore) does seem to do the trick:

client = boto3.client('s3', aws_access_key_id='', aws_secret_access_key='')
client._request_signer.sign = (lambda *args, **kwargs: None)


来源:https://stackoverflow.com/questions/34865927/can-i-use-boto3-anonymously

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!