Last active
December 19, 2022 10:39
-
-
Save edihasaj/1a46039aa113d2d2fac88e7bbb47a3f3 to your computer and use it in GitHub Desktop.
Download or list s3 bucket custom url or custom hosting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
if __name__ == '__main__': | |
s3 = boto3.client( | |
's3', | |
aws_access_key_id='your key', | |
aws_secret_access_key='your password', | |
endpoint_url="https://s3.yourcustomdomain.com", | |
) | |
# List all the objects in the bucket | |
objects = s3.list_objects(Bucket='your-bucket-name', Prefix='optional-if-you-want-to-list-only-files-with-a-prefix') | |
# Print the names of the objects | |
for obj in objects['Contents']: | |
key = obj['Key'] | |
print(key) | |
s3.download_file("your-bucket-name", key, 'what-do-you-want-the-last-name-to-be') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment