Part of my job lately has been generating periodic CSVs (maybe I’ll talk more about this in a later post). To share them with my co-workers I decided that the apt thing to do was to pop them on S3 where storage is cheap and secure. To do this I wrote the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | from boto.s3.connection import S3Connection from boto.s3.key import Key #... bunch of other cool stuff conn = S3Connection('<key>', '<secret>') bucket = conn.get_bucket('your_bucket') k = Key(bucket) # what you want the file to be named on S3 k.key = 'your_data.csv' # file to be uploaded csv_file = '<path to your csv file>/your_data.csv' k.set_contents_from_filename(csv_file) |
Replacing the tedious work with 5 lines of code.
