Download file/folder from Public AWS S3 with Python, no credentials

Viewed 3633

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?

1 Answers

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

Related