Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Replace aws_access_key_id and aws_secret_access_key with your S3 API keys

Code Block
languagepy
#!/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:
      for object in page['Contents']:
        print(object['Key'])