Esempio n. 1
0
# Create a bucket if the bucket does not exist

if action == "create-bucket":
    if not s3.lookup(bucket_name):
        print ("creating bucket")
        s3.create_bucket(bucket_name)

# Create a new key and value inside s3 (object)
# key.key is the name of the file
# key.set_content... is the content of that file
if action == "create-object":
    bucket = s3.get_bucket(bucket_name)
    key = Key(bucket)
    key.key = sys.argv[3]
    key.set_contents_from_strings(sys,argv[4])
    
if action == "upload-text-files":
    bucket = s3.get_bucket(bucket_name)
    print "upload all txt files to " + bucket_name
    for filename in glob.glob("*.txt"):
        key = bucket.new_key("files/"+ filename)
        key.set_contents_from_filename(filename)
        print "uploaded files" + filename
    
if action == "delete-bucket"):
    bucket = s3.get_bucket(bucket_name)
    for key in bucket.list():
        key.delete()
    s3.delete_bucket(bucket_name)