'Package your project, upload it to S3, register the Lambda function
and create the API Gateway routes.'

def deploy(self):

    self.check_venv()
    if self.prebuild_script:
        self.execute_prebuild_script()
    deployed_versions = self.zappa.get_lambda_function_versions(self.lambda_name)
    if (len(deployed_versions) > 0):
        raise ClickException(((((u'This    application    is    ' + click.style(u'already    deployed', fg=u'red')) + u'    -    did    you    mean    to    call    ') + click.style(u'update', bold=True)) + u'?'))
    if self.manage_roles:
        try:
            self.zappa.create_iam_roles()
        except botocore.client.ClientError:
            raise ClickException((((((((((click.style(u'Failed', fg=u'red') + u'    to    ') + click.style(u'manage    IAM    roles', bold=True)) + u'!\n') + u'You    may    ') + click.style(u'lack    the    necessary    AWS    permissions', bold=True)) + u'    to    automatically    manage    a    Zappa    execution    role.\n') + u'To    fix    this,    see    here:    ') + click.style(u'https://github.com/Miserlou/Zappa#using-custom-aws-iam-roles-and-policies', bold=True)) + u'\n'))
    self.create_package()
    self.callback(u'zip')
    success = self.zappa.upload_to_s3(self.zip_path, self.s3_bucket_name, disable_progress=self.disable_progress)
    if (not success):
        raise ClickException(u'Unable    to    upload    to    S3.    Quitting.')
    if self.stage_config.get(u'slim_handler', False):
        success = self.zappa.upload_to_s3(self.handler_path, self.s3_bucket_name, disable_progress=self.disable_progress)
        if (not success):
            raise ClickException(u'Unable    to    upload    handler    to    S3.    Quitting.')
        current_project_name = u'{0!s}_current_project.zip'.format(self.project_name)
        success = self.zappa.copy_on_s3(src_file_name=self.zip_path, dst_file_name=current_project_name, bucket_name=self.s3_bucket_name)
        if (not success):
            raise ClickException(u'Unable    to    copy    the    zip    to    be    the    current    project.    Quitting.')
        handler_file = self.handler_path
    else:
        handler_file = self.zip_path
    try:
        self.lambda_arn = self.zappa.get_lambda_function(function_name=self.lambda_name)
    except botocore.client.ClientError:
        self.lambda_arn = self.zappa.create_lambda_function(bucket=self.s3_bucket_name, s3_key=handler_file, function_name=self.lambda_name, handler=self.lambda_handler, description=self.lambda_description, vpc_config=self.vpc_config, dead_letter_config=self.dead_letter_config, timeout=self.timeout_seconds, memory_size=self.memory_size, runtime=self.runtime, aws_environment_variables=self.aws_environment_variables, aws_kms_key_arn=self.aws_kms_key_arn)
    self.schedule()
    endpoint_url = u''
    deployment_string = (click.style(u'Deployment    complete', fg=u'green', bold=True) + u'!')
    if self.use_apigateway:
        template = self.zappa.create_stack_template(lambda_arn=self.lambda_arn, lambda_name=self.lambda_name, api_key_required=self.api_key_required, iam_authorization=self.iam_authorization, authorizer=self.authorizer, cors_options=self.cors, description=self.apigateway_description)
        self.zappa.update_stack(self.lambda_name, self.s3_bucket_name, wait=True, disable_progress=self.disable_progress)
        api_id = self.zappa.get_api_id(self.lambda_name)
        if self.binary_support:
            self.zappa.add_binary_support(api_id=api_id, cors=self.cors)
        endpoint_url = self.deploy_api_gateway(api_id)
        deployment_string = (deployment_string + u':    {}'.format(endpoint_url))
        if self.api_key_required:
            if (self.api_key is None):
                self.zappa.create_api_key(api_id=api_id, stage_name=self.api_stage)
            else:
                self.zappa.add_api_stage_to_api_key(api_key=self.api_key, api_id=api_id, stage_name=self.api_stage)
        if self.stage_config.get(u'touch', True):
            requests.get(endpoint_url)
    if self.stage_config.get(u'delete_local_zip', True):
        self.remove_local_zip()
    self.remove_uploaded_zip()
    self.callback(u'post')
    click.echo(deployment_string)
