Created
August 4, 2017 20:33
-
-
Save oremj/62fa75851cc2c3dca27d778efe2c7485 to your computer and use it in GitHub Desktop.
All keys in bucket
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
#!/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