Skip to content

Instantly share code, notes, and snippets.

@edihasaj
Last active December 19, 2022 10:39
Show Gist options
  • Save edihasaj/1a46039aa113d2d2fac88e7bbb47a3f3 to your computer and use it in GitHub Desktop.
Save edihasaj/1a46039aa113d2d2fac88e7bbb47a3f3 to your computer and use it in GitHub Desktop.
Download or list s3 bucket custom url or custom hosting
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