/
Boto3
Boto3
Below example of how to list all containers and files in Swift using Boto3 and the S3 API. See https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.list_objects for more information on how to use Boto3.
Replace aws_access_key_id and aws_secret_access_key with your S3 API keys.
#!/usr/bin/env python
import boto3
if __name__ == "__main__":
session = boto3.Session(
aws_access_key_id='AAABBBCCC111222333',
aws_secret_access_key='333222111CCCBBBAAA')
s3 = session.client('s3', endpoint_url='https://object.cloud.sdsc.edu')
buckets = s3.list_buckets()
for bucket in buckets['Buckets']:
print(bucket['Name'])
print('=======================')
paginator = s3.get_paginator('list_objects_v2')
pages = paginator.paginate(Bucket=bucket['Name'])
for page in pages:
if 'Contents' in page:
for object in page['Contents']:
print(object['Key'])