8

I have opened a public access to S3 bucket and I need to download files / folders with files from the bucket using python. The trick is that I do not want to supply credentials (which boto3 apparently requires). Is it even possible?

Aramakus
  • 1,910
  • 2
  • 11
  • 22
  • 1
    In case you don't get an answer. You may have a better chance of getting an answer in "Data Science" community, because it includes data engineers who actively use AWS and python. – Commissar Vasili Karlovic May 29 '20 at 12:37
  • 1
    this might help: https://stackoverflow.com/questions/42090830/use-boto3-to-download-from-public-bucket – E.Serra May 29 '20 at 12:48
  • Thanks @E.Serra , but unfortunately boto3 does require credentials when you set it up. At least all the resources I have seen point to that. – Aramakus May 29 '20 at 12:52

1 Answers1

3

You can use GetObject from the S3 REST API, together with the Requests library in Python. If you grant READ access to the anonymous user, you can return the object without using an authorization header.

Example of such an S3 REST call::

> GET /example-object HTTP/1.1
> Host: example-bucket.s3.<Region>.amazonaws.com    

Python(rough example):

import requests
url = '/example-object'
headers = {'Host': 'example-bucket.s3.<Region>.amazonaws.com'}
r = requests.get(url, headers=headers)

Requests

GetObject

Adi Dembak
  • 2,433
  • 2
  • 18
  • 26