def send_to_aws(self): """Everything should be packaged now. Let's send it to S3""" # Establish connection to AWS and upload tarball conn = S3Connection(self.config.get('general', 'aws_key'), self.config.get('general', 'aws_secret_key')) bucket = Bucket(conn, self.config.get('general', 'bucket_name')) tarball_key = Key(bucket) tarball_key.key = self.config.get('general', 'tarball_name') tarball_path = self.config.get('general', 'dump_path') + self.config.get('general', 'tarball_name') tarball_key.set_contents_from_filename(tarball_path) # uncomment the following to make the bucket publicly downloadable bucket.set_acl('public-read', tarball_key.key) # Upload the stats file stats_key = Key(bucket) stats_key.key = 'stats.json' stats_key.set_contents_from_filename(self.config.get('general', 'dump_path') + 'stats.json') # uncomment the following to make the bucket publicly downloadable bucket.set_acl('public-read', stats_key.key)
def export_to_aws(filename, bucket_name, s3_filename=None): # Get the document and push to an S3 bucket. from boto.s3.connection import S3Connection from boto.s3.bucket import Bucket from boto.s3.key import Key try: conn = S3Connection('AKIAIDFEDRWJ4BW5JGMQ', '0b5+2w+/RMRu4HtvziE3VGwrnZdns68WiZ0GGg+2') bucket = Bucket(conn, bucket_name) key = Key(bucket) key.key = s3_filename if s3_filename else filename key.set_contents_from_filename(filename) bucket.set_acl('public-read', s3_filename if s3_filename else filename) # Print the entire URL in the stdout return 'http://' + bucket_name + '.s3.amazonaws.com/' + ( s3_filename if s3_filename else filename) except Exception, e: print e