Skip to content

Instantly share code, notes, and snippets.

@gm3dmo
Created December 8, 2017 10:07
Show Gist options
  • Select an option

  • Save gm3dmo/a64898a5904eeb709c49f652cb845778 to your computer and use it in GitHub Desktop.

Select an option

Save gm3dmo/a64898a5904eeb709c49f652cb845778 to your computer and use it in GitHub Desktop.
Lists objects in an S3 bucket
#!/usr/local/aws/bin/python
import botocore.session
# wanted_profile should be set to the profile for the key you want to use
# normally found in ~/.aws/credentials
wanted_profile = 's3monster'
wanted_bucket = 's3monsters'
session1 = botocore.session.Session(profile=wanted_profile)
s3_client = session1.create_client('s3')
buckets = s3_client.list_buckets()
# pagination!
objects_in_wanted_bucket = s3_client.list_objects_v2(Bucket=wanted_bucket)
print(objects_in_wanted_bucket)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment