#!/usr/bin/env python

import os
import sys
import json
import requests
from requests.exceptions import HTTPError

def upload_dump_to_s3():
    s3_post_data_url = json.loads(os.environ['S3_POST_URL_DATA'])
    dump_file = os.environ['DUMP_FILE']

    url = s3_post_data_url['url']
    fields = s3_post_data_url['fields']
    files = { "file": open(dump_file, 'r') }

    response = requests.post(url, data=fields, files=files)

    try:
        response.raise_for_status()
    except HTTPError as e:
        print("Error uploading {} to {}: {}".format(dump_file, url, e.args[0]))
        sys.exit(1)
    else:
        print('Successfully uploaded {} to {}'.format(dump_file, url))

if __name__ == "__main__":
    upload_dump_to_s3()

Add script to upload dump to s3
Add script to upload dump to s3

This is a simple python script which uses the signed url previously
generated to upload the encrypted dump to s3 using the requets library.

If the response from s3 is not successful, an error is raised and we
print the error message. Also sets the exit code to be not zero.
