This module will take in some datum (a file, or a folder) and write it to
    S3.  It requires a master key to encrypt the datum with, and a bucket to
    drop the results into.  If remote dir is set, the datum is dropped into the
    provided directory.
    :param str datum: File or folder that needs to be transferred to S3
    :param str master_key: Path to the master key used for encryption.
    :param str bucket_name: AWS bucket to store the remote data
    :param str remote_dir: An optional parameter describing a remote pseudo directory in the bucket
                           where the data will be stored.

def write_to_s3(datum, master_key, bucket_name, remote_dir=''):
    """
    This module will take in some datum (a file, or a folder) and write it to
    S3.  It requires a master key to encrypt the datum with, and a bucket to
    drop the results into.  If remote dir is set, the datum is dropped into the
    provided directory.
    :param str datum: File or folder that needs to be transferred to S3
    :param str master_key: Path to the master key used for encryption.
    :param str bucket_name: AWS bucket to store the remote data
    :param str remote_dir: An optional parameter describing a remote pseudo directory in the bucket
                           where the data will be stored.
    """
    # Instantiate the bucket info class to set up the https and s3 url bases.
    bucket_info = BucketInfo(bucket_name)

    # Retain the base dir separately from the file name / folder structure of DATUM.  This way it
    # can be easily joined into an AWS filename
    folder_base_dir = os.path.split(datum)[0]
    # Ensure files are either "regular files" or folders
    if os.path.isfile(datum):
        files = [os.path.basename(datum)]
    elif os.path.isdir(datum):
        files = ['/'.join([re.sub(folder_base_dir, '', folder), filename]).lstrip('/')
                 for folder, _, files in os.walk(datum) for filename in files]
    else:
        raise RuntimeError(datum + 'was neither regular file nor folder.')

    # Write each file to S3
    for file_path in files:
        # key, here, refers to the key or token used to access the file once it's in S3.
        # THIS IS NOT RELATED TO THE ENCRYPTION KEY.
        key = os.path.join(remote_dir, file_path)
        # base command call
        command = ['s3am', 'upload']
        if master_key:
            new_key = generate_unique_key(master_key, bucket_info.object_https_url(key))
            #  Add base64 encoded key
            command.extend(['--sse-key-base64', base64.b64encode(new_key)])
        # Add source path info to the call
        command.extend(['file://' + os.path.join(folder_base_dir, file_path)])
        # Add destination to the call
        command.append(bucket_info.object_s3_url(key))
        subprocess.call(command)
    return None