runway.context package

Context objects.

class runway.context.CfnginContext[source]

Bases: runway.context._base.BaseContext

CFNgin context object.

bucket_region

Region where the S3 Bucket is located. The S3 Bucket being the Bucket configured for staging CloudFormation Templates.

Type

str

config

CFNgin configuration file that has been resolved & parsed into a python object.

Type

CfnginConfig

config_path

Path to the configuration file that has been resolved, parsed and made accessible via this object.

Type

Path

env

Deploy environment object containing information about the current deploy environment.

Type

DeployEnvironment

force_stacks

List of stacks to force.

Type

List[str]

hook_data

Values returned by hooks that are stored based on the data_key defined for the hook. Returned values are only stored if a data_key was provided AND the return value is a dict or pydantic.BaseModel.

Type

Dict[str, Any]

logger

Custom logger to use when logging messages.

Type

Union[PrefixAdaptor, RunwayLogger]

parameters

Parameters passed from Runway or read from a file.

Type

MutableMapping[str, Any]

stack_names

List of Stack names to operate on. If value is falsy, all Stacks defined in the config will be operated on.

Type

List[str]

__init__(*, config: typing.Optional[runway.config.CfnginConfig] = None, config_path: typing.Optional[pathlib.Path] = None, deploy_environment: typing.Optional[runway.core.components._deploy_environment.DeployEnvironment] = None, force_stacks: typing.Optional[typing.List[str]] = None, logger: typing.Union[runway._logging.PrefixAdaptor, runway._logging.RunwayLogger] = <RunwayLogger runway.context._cfngin (WARNING)>, parameters: typing.Optional[typing.MutableMapping[str, typing.Any]] = None, stack_names: typing.Optional[typing.List[str]] = None, work_dir: typing.Optional[pathlib.Path] = None, **_: typing.Any) None[source]

Instantiate class.

Parameters
  • config – The CFNgin configuration being operated on.

  • config_path – Path to the config file that was provided.

  • deploy_environment – The current deploy environment.

  • force_stacks – A list of stacks to force work on. Used to work on locked stacks.

  • logger – Custom logger.

  • parameters – Parameters passed from Runway or read from a file.

  • stack_names – A list of stack_names to operate on. If not passed, all stacks defined in the config will be operated on.

  • work_dir – Working directory used by Runway.

property base_fqn: str

Return namespace sanitized for use as an S3 Bucket name.

property bucket_name: Optional[str]

Return cfngin_bucket from config, calculated name, or None.

property mappings: Dict[str, Dict[str, Dict[str, Any]]]

Return mappings from config.

property namespace: str

Return namespace from config.

property namespace_delimiter: str

Return namespace_delimiter from config or default.

property persistent_graph_location: PersistentGraphLocation

Location of the persistent graph in s3.

property persistent_graph_locked: bool

Check if persistent graph is locked.

property persistent_graph_lock_code: Optional[str]

Code used to lock the persistent graph S3 object.

property persistent_graph_tags: Dict[str, str]

Cache of tags on the persistent graph object.

property persistent_graph: Optional[runway.cfngin.plan.Graph]

Graph if a persistent graph is being used.

Will create an “empty” object in S3 if one is not found.

property s3_bucket_verified: bool

Check CFNgin bucket exists and you have access.

If the CFNgin bucket does not exist, will try to create one.

property s3_client: S3Client

AWS S3 client.

property stacks_dict: Dict[str, runway.cfngin.stack.Stack]

Construct a dict of {stack.fqn: Stack} for easy access to stacks.

__new__(**kwargs)
property boto3_credentials: runway.type_defs.Boto3CredentialsTypeDef

Return a dict of boto3 credentials.

property current_aws_creds: EnvVarsAwsCredentialsTypeDef

AWS credentials from self.env_vars.

get_session(*, aws_access_key_id: Optional[str] = None, aws_secret_access_key: Optional[str] = None, aws_session_token: Optional[str] = None, profile: Optional[str] = None, region: Optional[str] = None) boto3.session.Session

Create a thread-safe boto3 session.

If profile is provided, it will take priority.

If no credential arguments are passed, will attempt to find them in environment variables.

Parameters
  • aws_access_key_id – AWS Access Key ID.

  • aws_secret_access_key – AWS secret Access Key.

  • aws_session_token – AWS session token.

  • profile – The profile for the session.

  • region – The region for the session.

Returns

A thread-safe boto3 session.

property is_interactive: bool

Whether the user should be prompted or not.

Determined by the existed of CI in the environment.

property is_noninteractive: bool

Whether the user should be prompted or not.

Determined by the existed of CI in the environment. Inverse of is_interactive property.

property stacks: List[runway.cfngin.stack.Stack]

Stacks for the current action.

sys_info: SystemInfo

Information about the current system being used to run Runway.

work_dir: Path

Working directory used by Runway. Should always be a directory named .runway.

property tags: Dict[str, str]

Return tags from config.

property template_indent: int

Return template_indent from config or default.

property upload_to_s3: bool

Check if S3 should be used for caching/persistent graph.

copy() runway.context.CfnginContext[source]

Copy the contents of this object into a new instance.

get_fqn(name: Optional[str] = None) str[source]

Return the fully qualified name of an object within this context.

If the name passed already appears to be a fully qualified name, it will be returned with no further processing.

get_stack(name: str) Optional[runway.cfngin.stack.Stack][source]

Get a stack by name.

Parameters

name – Name of a Stack as defined in the config.

lock_persistent_graph(lock_code: str) None[source]

Locks the persistent graph in s3.

Parameters

lock_code – The code that will be used to lock the S3 object.

Raises
put_persistent_graph(lock_code: str) None[source]

Upload persistent graph to s3.

Parameters

lock_code (str) – The code that will be used to lock the S3 object.

Raises
set_hook_data(key: str, data: Any) None[source]

Set hook data for the given key.

Parameters
  • key – The key to store the hook data in.

  • data – A dictionary of data to store, as returned from a hook.

unlock_persistent_graph(lock_code: str) bool[source]

Unlocks the persistent graph in s3.

Parameters

lock_code – The code that will be used to lock the S3 object.

Raises

runway.cfngin.exceptions.PersistentGraphCannotUnlock

class runway.context.RunwayContext[source]

Bases: runway.context._base.BaseContext

Runway context object.

__init__(*, command: Optional[RunwayActionTypeDef] = None, deploy_environment: Optional[DeployEnvironment] = None, logger: Union[PrefixAdaptor, RunwayLogger] = <RunwayLogger runway.context._runway (WARNING)>, work_dir: Optional[Path] = None, **_: Any) None[source]

Instantiate class.

Parameters
  • command – Runway command/action being run.

  • deploy_environment – The current deploy environment.

  • logger – Custom logger.

  • work_dir – Working directory used by Runway.

command: Optional[RunwayActionTypeDef]

Runway command/action being run.

property no_color: bool

Whether to explicitly disable color output.

Primarily applies to IaC being wrapped by Runway.

property use_concurrent: bool

Whether to use concurrent.futures or not.

Noninteractive is required for concurrent execution to prevent weird user-input behavior.

Python 3 is required because backported futures has issues with ProcessPoolExecutor.

__new__(**kwargs)
property boto3_credentials: runway.type_defs.Boto3CredentialsTypeDef

Return a dict of boto3 credentials.

copy() runway.context.RunwayContext[source]

Copy the contents of this object into a new instance.

property current_aws_creds: EnvVarsAwsCredentialsTypeDef

AWS credentials from self.env_vars.

get_session(*, aws_access_key_id: Optional[str] = None, aws_secret_access_key: Optional[str] = None, aws_session_token: Optional[str] = None, profile: Optional[str] = None, region: Optional[str] = None) boto3.session.Session

Create a thread-safe boto3 session.

If profile is provided, it will take priority.

If no credential arguments are passed, will attempt to find them in environment variables.

Parameters
  • aws_access_key_id – AWS Access Key ID.

  • aws_secret_access_key – AWS secret Access Key.

  • aws_session_token – AWS session token.

  • profile – The profile for the session.

  • region – The region for the session.

Returns

A thread-safe boto3 session.

property is_interactive: bool

Whether the user should be prompted or not.

Determined by the existed of CI in the environment.

property is_noninteractive: bool

Whether the user should be prompted or not.

Determined by the existed of CI in the environment. Inverse of is_interactive property.

env: DeployEnvironment

Object containing information about the environment being deployed to.

logger: Union[PrefixAdaptor, RunwayLogger]

Custom logger.

sys_info: SystemInfo

Information about the current system being used to run Runway.

work_dir: Path

Working directory used by Runway. Should always be a directory named .runway.

echo_detected_environment() None[source]

Print a helper note about how the environment was determined.

Submodules