39

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?

helloV
  • 50,176
  • 7
  • 137
  • 145
MRocklin
  • 55,641
  • 23
  • 163
  • 235

3 Answers3

55

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
Jordon Phillips
  • 14,963
  • 4
  • 35
  • 42
  • 5
    it would be nice to update this answer with an up to date solution. – weaver Mar 23 '20 at 18:44
  • I tested and it works on 2022. You just need to add the region_name to the client parameters, something like this: s3 = boto3.client('s3', config=Config(signature_version=UNSIGNED),region_name='us-east-1') – kevininhe May 03 '22 at 03:21
  • Doesn't seem to work anymore in 2023, even with region_name set. – derchambers Mar 12 '23 at 21:48
25

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)
helloV
  • 50,176
  • 7
  • 137
  • 145
  • Will this stop credentials from being used if they are present? Is it suitable to set as a default? – MRocklin Jan 19 '16 at 00:17
  • 1
    It will stop credentials from being used on that client. You will need another client to connect to restricted s3 buckets. The same is true of my solution. Note: both solutions do exactly the same thing. – Jordon Phillips Jan 19 '16 at 17:42
5

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)
RandomIOSDeveloper
  • 1,441
  • 2
  • 11
  • 4
  • 3
    [Jordon Phillips` answer](https://stackoverflow.com/a/34866092/974555) appears to work for me on boto3 1.9.251. – gerrit Oct 17 '19 at 15:36