runway.module.serverless module

Serverless module.

runway.module.serverless.gen_sls_config_files(stage: str, region: str) List[str][source]

Generate possible SLS config files names.

class runway.module.serverless.Serverless[source]

Bases: runway.module.base.RunwayModuleNpm

Serverless Runway Module.

__init__(context: RunwayContext, *, explicitly_enabled: Optional[bool] = False, logger: RunwayLogger = <RunwayLogger runway.module.serverless (WARNING)>, module_root: Path, name: Optional[str] = None, options: Optional[Union[Dict[str, Any], ModuleOptions]] = None, parameters: Optional[Dict[str, Any]] = None, **_: Any) None[source]

Instantiate class.

Parameters
  • context – Runway context object for the current session.

  • explicitly_enabled – Whether or not the module is explicitly enabled. This is can be set in the event that the current environment being deployed to matches the defined environments of the module/deployment.

  • logger – Used to write logs.

  • module_root – Root path of the module.

  • name – Name of the module.

  • options – Options passed to the module class from the config as options or module_options if coming from the deployment level.

  • parameters – Values to pass to the underlying infrastructure as code tool that will alter the resulting infrastructure being deployed. Used to templatize IaC.

property cli_args: List[str]

Generate CLI args from self used in all Serverless commands.

property env_file: Optional[pathlib.Path]

Find the environment file for the module.

property skip: bool

Determine if the module should be skipped.

extend_serverless_yml(func: Callable[[...], None]) None[source]

Extend the Serverless config file with additional YAML from options.

Parameters

func – Callable to use after handling the Serverless config file.

gen_cmd(command: str, args_list: Optional[List[str]] = None) List[str][source]

Generate and log a Serverless command.

This does not execute the command, only prepares it for use.

Parameters
  • command – The Serverless command to be executed.

  • args_list – Additional arguments to include in the generated command.

Returns

The full command to be passed into a subprocess.

sls_deploy(*, package: Optional[AnyPath] = None, skip_install: bool = False) None[source]

Execute sls deploy command.

Parameters
  • package – Path to Serverless package to deploy.

  • skip_install – Skip npm ci|install before running the Serverless command.

sls_package(*, output_path: Optional[AnyPathConstrained] = None, skip_install: bool = False) Optional[AnyPathConstrained][source]

Execute sls package command.

Parameters
  • output_path – Path where the package should be output.

  • skip_install – Skip npm ci|install before running the Serverless command.

sls_print(*, item_path: Optional[str] = None, skip_install: bool = False) Dict[str, Any][source]

Execute sls print command.

Keyword Arguments
  • item_path – Period-separated path to print a sub-value (eg: “provider.name”).

  • skip_install – Skip npm ci|install before running the Serverless command.

Returns

Resolved Serverless config file.

Raises

SystemExit – If a runway-tmp.serverless.yml file already exists.

sls_remove(*, skip_install: bool = False) None[source]

Execute sls remove command.

Parameters

skip_install – Skip npm ci|install before running the Serverless command.

deploy() None[source]

Entrypoint for Runway’s deploy action.

destroy() None[source]

Entrypoint for Runway’s destroy action.

init() None[source]

Run init.

plan() None[source]

Entrypoint for Runway’s plan action.

__getitem__(key: str) Any

Make the object subscriptable.

Parameters

key – Attribute to get.

__new__(**kwargs)
static check_for_npm(*, logger: Union[logging.Logger, PrefixAdaptor, RunwayLogger] = <RunwayLogger runway.module.base (WARNING)>) None

Ensure npm is installed and in the current path.

Parameters

logger – Optionally provide a custom logger to use.

log_npm_command(command: List[str]) None

Log an npm command that is going to be run.

Parameters

command – List that will be passed into a subprocess.

npm_install() None

Run npm install.

package_json_missing() bool

Check for the existence for a package.json file in the module.

Returns

True if the file was not found.

Return type

bool

static warn_on_boto_env_vars(env_vars: Dict[str, str], *, logger: Union[logging.Logger, PrefixAdaptor, RunwayLogger] = <RunwayLogger runway.module.base (WARNING)>) None

Inform user if boto-specific environment variables are in use.

Parameters
  • env_vars – Environment variables to check.

  • logger – Optionally provide a custom logger to use.

class runway.module.serverless.ServerlessArtifact[source]

Bases: object

Object for interacting with a Serverless artifact directory.

__init__(context: RunwayContext, config: Dict[str, Any], *, logger: Union[PrefixAdaptor, RunwayLogger] = <RunwayLogger runway.module.serverless (WARNING)>, package_path: AnyPath, path: AnyPath) None[source]

Instantiate class.

Parameters
  • context – Runway context object.

  • config – Rendered Serverless config file.

  • logger – Logger this object will log to. If not provided, the logger in the local module will be used.

  • package_path – Local path to the artifact directory.

  • path – Root directory of the Serverless project.

property source_hash: Dict[str, str]

File hash(es) of each service’s source code.

sync_with_s3(bucket_name: str) None[source]

Sync local archive files with S3 bucket.

Parameters

bucket_name – Name of S3 bucket to upload files to.

__new__(**kwargs)
class runway.module.serverless.ServerlessOptions[source]

Bases: runway.module.base.ModuleOptions

Module options for Serverless Framework.

data

Options parsed into a data model.

extend_serverless_yml

If provided, the value of this option will be recursively merged into the module’s Serverless config file.

promotezip

If provided, promote Serverless Framework generated zip files between environments from a build AWS account.

skip_npm_ci

Skip running npm ci in the module directory prior to processing the module.

__init__(data: runway.config.models.runway.options.serverless.RunwayServerlessModuleOptionsDataModel) None[source]

Instantiate class.

Parameters

data – Options parsed into a data model.

property args: List[str]

List of CLI arguments/options to pass to the Serverless Framework CLI.

update_args(key: str, value: str) None[source]

Update a known CLI argument.

Parameters
  • key – Dict key to be updated.

  • value – New value

Raises

KeyError – The key provided for update is not a known arg.

classmethod parse_obj(obj: object) runway.module.serverless.ServerlessOptions[source]

Parse options definition and return an options object.

Parameters

obj – Object to parse.

__eq__(other: Any) bool

Assess equality.

__new__(**kwargs)
get(name: str, default: Any = None) Any

Get a value or return the default.