def run_serverless(self, command='deploy'):
        """Run Serverless."""
        response = {'skipped_configs': False}
        sls_opts = [command]

        if not which('npm'):
            LOGGER.error('"npm" not found in path or is not executable; '
                         'please ensure it is installed correctly.')
            sys.exit(1)

        if 'CI' in self.context.env_vars and command != 'remove':
            sls_opts.append('--conceal')  # Hide secrets from serverless output

        if 'DEBUG' in self.context.env_vars:
            sls_opts.append('-v')  # Increase logging if requested

        warn_on_boto_env_vars(self.context.env_vars)

        sls_opts.extend(['-r', self.context.env_region])
        sls_opts.extend(['--stage', self.context.env_name])
        sls_env_file = get_sls_config_file(self.path,
                                           self.context.env_name,
                                           self.context.env_region)

        sls_cmd = generate_node_command(command='sls',
                                        command_opts=sls_opts,
                                        path=self.path)

        if (not self.options.get('environments') and os.path.isfile(os.path.join(self.path, sls_env_file))) or (  # noqa pylint: disable=line-too-long
                self.options.get('environments', {}).get(self.context.env_name)):  # noqa
            if os.path.isfile(os.path.join(self.path, 'package.json')):
                with change_dir(self.path):
                    run_npm_install(self.path, self.options, self.context)
                    LOGGER.info("Running sls %s on %s (\"%s\")",
                                command,
                                os.path.basename(self.path),
                                format_npm_command_for_logging(sls_cmd))
                    if command == 'remove':
                        # Need to account for exit code 1 on any removals after
                        # the first
                        run_sls_remove(sls_cmd, self.context.env_vars)
                    else:
                        run_module_command(cmd_list=sls_cmd,
                                           env_vars=self.context.env_vars)
            else:
                LOGGER.warning(
                    "Skipping serverless %s of %s; no \"package.json\" "
                    "file was found (need a package file specifying "
                    "serverless in devDependencies)",
                    command,
                    os.path.basename(self.path))
        else:
            response['skipped_configs'] = True
            LOGGER.info(
                "Skipping serverless %s of %s; no config file for "
                "this stage/region found (looking for one of \"%s\")",
                command,
                os.path.basename(self.path),
                ', '.join(gen_sls_config_files(self.context.env_name,
                                               self.context.env_region)))
        return response
def run_serverless ( self , command = 'deploy' ) : response = { 'skipped_configs' : False } sls_opts = [ command ] if not which ( 'npm' ) : LOGGER . error ( '"npm" not found in path or is not executable; ' 'please ensure it is installed correctly.' ) sys . exit ( 1 ) if 'CI' in self . context . env_vars and command != 'remove' : sls_opts . append ( '--conceal' ) if 'DEBUG' in self . context . env_vars : sls_opts . append ( '-v' ) warn_on_boto_env_vars ( self . context . env_vars ) sls_opts . extend ( [ '-r' , self . context . env_region ] ) sls_opts . extend ( [ '--stage' , self . context . env_name ] ) sls_env_file = get_sls_config_file ( self . path , self . context . env_name , self . context . env_region ) sls_cmd = generate_node_command ( command = 'sls' , command_opts = sls_opts , path = self . path ) if ( not self . options . get ( 'environments' ) and os . path . isfile ( os . path . join ( self . path , sls_env_file ) ) ) or ( self . options . get ( 'environments' , { } ) . get ( self . context . env_name ) ) : if os . path . isfile ( os . path . join ( self . path , 'package.json' ) ) : with change_dir ( self . path ) : run_npm_install ( self . path , self . options , self . context ) LOGGER . info ( "Running sls %s on %s (\"%s\")" , command , os . path . basename ( self . path ) , format_npm_command_for_logging ( sls_cmd ) ) if command == 'remove' : run_sls_remove ( sls_cmd , self . context . env_vars ) else : run_module_command ( cmd_list = sls_cmd , env_vars = self . context . env_vars ) else : LOGGER . warning ( "Skipping serverless %s of %s; no \"package.json\" " "file was found (need a package file specifying " "serverless in devDependencies)" , command , os . path . basename ( self . path ) ) else : response [ 'skipped_configs' ] = True LOGGER . info ( "Skipping serverless %s of %s; no config file for " "this stage/region found (looking for one of \"%s\")" , command , os . path . basename ( self . path ) , ', ' . join ( gen_sls_config_files ( self . context . env_name , self . context . env_region ) ) ) return response
Run Serverless.