'Ensure that the package can be properly configured,
and then create it.'

def create_package(self, output=None):

    current_file = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
    handler_file = ((os.sep.join(current_file.split(os.sep)[0:]) + os.sep) + u'handler.py')
    if self.stage_config.get(u'slim_handler', False):
        self.zip_path = self.zappa.create_lambda_zip(prefix=self.lambda_name, use_precompiled_packages=self.stage_config.get(u'use_precompiled_packages', True), exclude=self.stage_config.get(u'exclude', []), disable_progress=self.disable_progress)
        exclude = self.stage_config.get(u'exclude', [])
        cur_venv = self.zappa.get_current_venv()
        exclude.append(cur_venv.split(u'/')[(-1)])
        self.handler_path = self.zappa.create_lambda_zip(prefix=u'handler_{0!s}'.format(self.lambda_name), venv=self.zappa.create_handler_venv(), handler_file=handler_file, slim_handler=True, exclude=exclude, output=output, disable_progress=self.disable_progress)
    else:
        if (sys.version_info[0] < 3):
            exclude = self.stage_config.get(u'exclude', [u'boto3', u'dateutil', u'botocore', u's3transfer', u'six.py', u'jmespath', u'concurrent'])
        else:
            exclude = self.stage_config.get(u'exclude', [u'boto3', u'dateutil', u'botocore', u's3transfer', u'concurrent'])
        self.zip_path = self.zappa.create_lambda_zip(prefix=self.lambda_name, handler_file=handler_file, use_precompiled_packages=self.stage_config.get(u'use_precompiled_packages', True), exclude=exclude, output=output, disable_progress=self.disable_progress)
        file_stats = os.stat(self.zip_path)
        if (file_stats.st_size > 52428800):
            print u'\n\nWarning:    Application    zip    package    is    likely    to    be    too    large    for    AWS    Lambda.    Try    setting    "slim_handler"    to    true    in    your    Zappa    settings    file.\n\n'
    if self.stage_config.get(u'slim_handler', False):
        handler_zip = self.handler_path
    else:
        handler_zip = self.zip_path
    with zipfile.ZipFile(handler_zip, u'a') as lambda_zip:
        settings_s = u'#    Generated    by    Zappa\n'
        if self.app_function:
            if (u'.' not in self.app_function):
                raise ClickException((((((u'Your    ' + click.style(u'app_function', fg=u'red', bold=True)) + u'    value    is    not    a    modular    path.') + u'    It    needs    to    be    in    the    format    `') + click.style(u'your_module.your_app_object', bold=True)) + u'`.'))
            (app_module, app_function) = self.app_function.rsplit(u'.', 1)
            settings_s = (settings_s + u"APP_MODULE='{0!s}'\nAPP_FUNCTION='{1!s}'\n".format(app_module, app_function))
        if self.exception_handler:
            settings_s += u"EXCEPTION_HANDLER='{0!s}'\n".format(self.exception_handler)
        else:
            settings_s += u'EXCEPTION_HANDLER=None\n'
        if self.debug:
            settings_s = (settings_s + u'DEBUG=True\n')
        else:
            settings_s = (settings_s + u'DEBUG=False\n')
        settings_s = (settings_s + u"LOG_LEVEL='{0!s}'\n".format(self.log_level))
        if self.binary_support:
            settings_s = (settings_s + u'BINARY_SUPPORT=True\n')
        else:
            settings_s = (settings_s + u'BINARY_SUPPORT=False\n')
        head_map_dict = {}
        head_map_dict.update(dict(self.context_header_mappings))
        settings_s = (settings_s + u'CONTEXT_HEADER_MAPPINGS={0}\n'.format(head_map_dict))
        if self.domain:
            settings_s = (settings_s + u"DOMAIN='{0!s}'\n".format(self.domain))
        else:
            settings_s = (settings_s + u'DOMAIN=None\n')
        if self.remote_env:
            settings_s = (settings_s + u"REMOTE_ENV='{0!s}'\n".format(self.remote_env))
        elif (self.remote_env_bucket and self.remote_env_file):
            settings_s = (settings_s + u"REMOTE_ENV='s3://{0!s}/{1!s}'\n".format(self.remote_env_bucket, self.remote_env_file))
        env_dict = {}
        if self.aws_region:
            env_dict[u'AWS_REGION'] = self.aws_region
        env_dict.update(dict(self.environment_variables))
        try:
            env_dict = dict(((k.encode(u'ascii').decode(u'ascii'), v) for (k, v) in env_dict.items()))
        except Exception:
            raise ValueError(u'Environment    variable    keys    must    be    ascii.')
        settings_s = (settings_s + u'ENVIRONMENT_VARIABLES={0}\n'.format(env_dict))
        settings_s = (settings_s + u"API_STAGE='{0!s}'\n".format(self.api_stage))
        settings_s = (settings_s + u"PROJECT_NAME='{0!s}'\n".format(self.project_name))
        if self.settings_file:
            settings_s = (settings_s + u"SETTINGS_FILE='{0!s}'\n".format(self.settings_file))
        else:
            settings_s = (settings_s + u'SETTINGS_FILE=None\n')
        if self.django_settings:
            settings_s = (settings_s + u"DJANGO_SETTINGS='{0!s}'\n".format(self.django_settings))
        else:
            settings_s = (settings_s + u'DJANGO_SETTINGS=None\n')
        if self.stage_config.get(u'slim_handler', False):
            settings_s += u"ZIP_PATH='s3://{0!s}/{1!s}_current_project.zip'\n".format(self.s3_bucket_name, self.project_name)
            settings_s += u'SLIM_HANDLER=True\n'
            include = self.stage_config.get(u'include', [])
            if (len(include) >= 1):
                settings_s += ((u'INCLUDE=' + str(include)) + u'\n')
        event_mapping = {}
        events = self.stage_config.get(u'events', [])
        for event in events:
            arn = event.get(u'event_source', {}).get(u'arn')
            function = event.get(u'function')
            if (arn and function):
                event_mapping[arn] = function
        settings_s = (settings_s + u'AWS_EVENT_MAPPING={0!s}\n'.format(event_mapping))
        authorizer_function = self.authorizer.get(u'function', None)
        if authorizer_function:
            settings_s += u"AUTHORIZER_FUNCTION='{0!s}'\n".format(authorizer_function)
        if self.django_settings:
            base = __file__.rsplit(os.sep, 1)[0]
            django_py = u''.join(os.path.join(base, u'ext', u'django_zappa.py'))
            lambda_zip.write(django_py, u'django_zappa_app.py')
        temp_settings = tempfile.NamedTemporaryFile(delete=False)
        os.chmod(temp_settings.name, 420)
        temp_settings.write(bytes(settings_s, u'utf-8'))
        temp_settings.close()
        lambda_zip.write(temp_settings.name, u'zappa_settings.py')
        os.remove(temp_settings.name)
