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?
Asked
Active
Viewed 4,388 times
8
-
1In 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
-
1this 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 Answers
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)

Adi Dembak
- 2,433
- 2
- 18
- 26
-
3After using a full `url = 'https://
.s3- – Aramakus May 29 '20 at 13:38.amazonaws.com/ ` worked like a charm!