Created
December 4, 2013 15:57
-
-
Save rafaelcaricio/7790030 to your computer and use it in GitHub Desktop.
find file in s3
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 python | |
import os | |
import argparse | |
from boto.s3.connection import S3Connection | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser(description='Find filename on s3') | |
parser.add_argument('resource_name', metavar='resource_name', help='Part of the resource name.') | |
args = parser.parse_args() | |
if args.resource_name: | |
conn = S3Connection(os.environ['AWS_ACCESS_KEY_ID'], | |
os.environ['AWS_SECRET_ACCESS_KEY']) | |
bucket = conn.get_bucket(os.environ['S3_BUCKET_NAME']) | |
for key in bucket.list(): | |
name = key.name.encode('utf-8') | |
if args.resource_name in name: | |
print key.generate_url(expires_in=999900) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment