Skip to content

Instantly share code, notes, and snippets.

@oremj
Created August 4, 2017 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oremj/62fa75851cc2c3dca27d778efe2c7485 to your computer and use it in GitHub Desktop.
Save oremj/62fa75851cc2c3dca27d778efe2c7485 to your computer and use it in GitHub Desktop.
All keys in bucket
#!/usr/bin/env python3
import sys
import boto3
S3 = boto3.resource("s3")
def list_keys(bucket_name, prefix=''):
objs = S3.Bucket(bucket_name).objects
for obj in objs.filter(Prefix=prefix):
print(obj.key)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: {} <bucket>".format(sys.argv[0]))
exit(1)
bucket = sys.argv[1]
prefix = ''
if len(sys.argv) == 3:
prefix = sys.argv[2]
list_keys(bucket, prefix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment