Created
June 25, 2022 17:42
-
-
Save mrts/a2a82e1aabc667dadecdd729b9cab450 to your computer and use it in GitHub Desktop.
List all DigitalOcean Spaces files with Python
This file contains 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 | |
ENDPOINT_URL = 'https://fra1.digitaloceanspaces.com' | |
SPACE = "space-name" | |
REGION = "FRA1" | |
ACCESS_KEY_ID = "..." | |
SECRET_ACCESS_KEY = "..." | |
def main(): | |
session = boto3.session.Session() | |
client = session.client('s3', | |
region_name=REGION, | |
endpoint_url=ENDPOINT_URL, | |
aws_access_key_id=ACCESS_KEY_ID, | |
aws_secret_access_key=SECRET_ACCESS_KEY) | |
paginator = client.get_paginator("list_objects_v2") | |
for page in paginator.paginate(Bucket=SPACE): | |
for obj in page['Contents']: | |
print(obj['Key']) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment