def apply_zappa_settings(zappa_obj, zappa_settings, environment):
    '''Load Zappa settings, set defaults if needed, and apply to the Zappa object'''

    settings_all = json.load(zappa_settings)
    settings = settings_all[environment]

    # load defaults for missing options
    for key,value in DEFAULT_SETTINGS.items():
        settings[key] = settings.get(key, value)

    if '~' in settings['settings_file']:
        settings['settings_file'] = settings['settings_file'].replace('~', os.path.expanduser('~'))
    if not os.path.isfile(settings['settings_file']):
        raise SettingsError("Please make sure your settings_file "
                            "is properly defined in {0}.".format(zappa_settings))

    for setting in CUSTOM_SETTINGS:
        if setting in settings:
            setattr(zappa_obj, setting, settings[setting])

    return settings
Load Zappa settings, set defaults if needed, and apply to the Zappa object