'Attempt to read a file from s3 containing a flat json object. Adds each
key->value pair as environment variables. Helpful for keeping
sensitiZve or stage-specific configuration variables in s3 instead of
version control.'

def load_remote_settings(self, remote_bucket, remote_file):

    if (not self.session):
        boto_session = boto3.Session()
    else:
        boto_session = self.session
    s3 = boto_session.resource(u's3')
    try:
        remote_env_object = s3.Object(remote_bucket, remote_file).get()
    except Exception as e:
        print (u'Could    not    load    remote    settings    file.', e)
        return
    try:
        content = remote_env_object[u'Body'].read()
    except Exception as e:
        print (u'Exception    while    reading    remote    settings    file.', e)
        return
    try:
        settings_dict = json.loads(content)
    except (ValueError, TypeError):
        print u'Failed    to    parse    remote    settings!'
        return
    for (key, value) in settings_dict.items():
        if (self.settings.LOG_LEVEL == u'DEBUG'):
            print u'Adding    {}    ->    {}    to    environment'.format(key, value)
        try:
            os.environ[str(key)] = value
        except Exception:
            if (self.settings.LOG_LEVEL == u'DEBUG'):
                print u'Environment    variable    keys    must    be    non-unicode!'
