Closed
Description
It would be really great if to_(filetype)
supported writing to S3.
Here is an example upload to s3 function that takes in a local file and places it on a s3 bucket.
def upload_to_s3(local_file_path, file_name, bucket_name, s3_directory):
"""
Returns
----------
Uploads local file to appropriate s3 key, and prints status
Parameters
----------
local_file_path : str
ex. 'my/local/path'
file_name : str
ex. 'cleaned_data.csv'
bucket_name : str
ex. 'dsapp-edu-data'
s3_directory : str
ex. 'NC-Cabarrus/cleaned_data'
"""
def percent_cb(complete, total):
"""
Helper function that prints progress
"""
sys.stdout.write('.')
sys.stdout.flush()
conn = boto.connect_s3()
bucket = conn.get_bucket(bucket_name)
full_key_name = os.path.join(s3_directory, file_name)
k = bucket.new_key(full_key_name)
full_filepath = os.path.join(local_file_path, file_name)
k.set_contents_from_filename(full_filepath, cb=percent_cb, num_cb=10)
return None