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

后端 未结 1 1575
心在旅途
心在旅途 2021-01-18 08:36

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 credenti

相关标签:
1条回答
  • 2021-01-18 09:12

    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 a such a 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

    0 讨论(0)
提交回复
热议问题