Skip to content

Latest commit

 

History

History
59 lines (46 loc) · 2 KB

README.md

File metadata and controls

59 lines (46 loc) · 2 KB

S3.FMA

S3.FMA is a thin Python wrapper around boto to perform specific high level file management tasks on an AWS S3 Bucket.

Requirements

You must have boto installed to use S3.FMA. For directions to installing boto see this post

Usage

The S3.FMA programming model looks like this:

Creating an instance of S3FileManager

from S3FMA import *
 
AWS_KEY = 'my key'
AWS_SECRET = 'my secret'
s3FileManager = S3FileManager(AWS_KEY, AWS_SECRET, use_ssl = True)

List all files in an S3 bucket

# returns a list of files stored in bucket 'mybucket'
fileNames = s3FileManager.getFileNamesInBucket('mybucket')
    for f in filenames:
        print f

Download a file from a bucket

# download a file named 'fileToDownload.txt' from bucket 'mybucket' to '~/Downloads/download_to_here/'
s3FileManager.downloadFileFromBucket('mybucket', 'fileToDownload.txt', '~/Downloads/download_to_here/')

Download all files from a bucket

# download all of the files in bucket 'mybucket' to the '~/Downloads/download_to_here/'
s3FileManager.downloadAllFilesFromBucket('mybucket', '~/Downloads/download_to_here/')

Download all files from a bucket whose filename satisfy a predicate

# download files that contain the word 'foo' in their name from 'mybucket' to '~/Downloads/download_to_here/'
s3FileManager.downloadFilesInBucketWithPredicate('mybucket', lambda filename: 'foo' in filename, '~/Downloads/download_to_here/')

Delete all files from a bucket

# delete all files in bucket 'mybucket'
s3FileManager.deleteAllFilesFromBucket('mybucket')

Delete all files from a bucket whose filename satisfy a predicate

# delete files that contain the word 'foo' in their name from 'mybucket'
s3FileManager.deleteFilesInBucketWithPredicate('mybucket', lambda filename: 'foo' in filename)