<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

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