runway.context package

Context objects.

class runway.context.CfnginContext(*, config: Optional[CfnginConfig] = None, config_path: Optional[Path] = None, deploy_environment: Optional[DeployEnvironment] = None, force_stacks: Optional[List[str]] = None, logger: Union[PrefixAdaptor, RunwayLogger] = <RunwayLogger runway.context._cfngin (WARNING)>, parameters: Optional[MutableMapping[str, Any]] = None, stack_names: Optional[List[str]] = None, **_: Any)[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 accessable 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]

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.

property base_fqn

Return namespace sanitized for use as an S3 Bucket name.

property bucket_name

Return cfngin_bucket from config, calculated name, or None.

property mappings

Return mappings from config.

property namespace

Return namespace from config.

property namespace_delimiter

Return namespace_delimiter from config or default.

property persistent_graph_location

Location of the persistent graph in s3.

property persistent_graph_locked

Check if persistent graph is locked.

property persistent_graph_lock_code

Code used to lock the persistent graph S3 object.

property persistent_graph_tags

Cache of tags on the persistent graph object.

property persistent_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

Check CFNgin bucket exists and you have access.

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

property s3_client

AWS S3 client.

property stacks_dict

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

property boto3_credentials

Return a dict of boto3 credentials.

property current_aws_creds

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

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

Whether the user should be prompted or not.

Determined by the existed of CI in the environment.

property is_noninteractive

Whether the user should be prompted or not.

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

property stacks

Stacks for the current action.

property tags

Return tags from config.

property template_indent

Return template_indent from config or default.

property upload_to_s3

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

copy()runway.context._cfngin.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[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: typing.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(*, command: Optional[RunwayActionTypeDef] = None, deploy_environment: Optional[DeployEnvironment] = None, logger: Union[PrefixAdaptor, RunwayLogger] = <RunwayLogger runway.context._runway (WARNING)>, **_: Any)[source]

Bases: runway.context._base.BaseContext

Runway context object.

Instantiate class.

Parameters
  • command – Runway command/action being run.

  • deploy_environment – The current deploy environment.

  • logger – Custom logger.

property no_color

Whether to explicitly disable color output.

Primarily applies to IaC being wrapped by Runway.

property use_concurrent

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.

copy()runway.context._runway.RunwayContext[source]

Copy the contents of this object into a new instance.

property boto3_credentials

Return a dict of boto3 credentials.

property current_aws_creds

AWS credentials from self.env_vars.

echo_detected_environment()None[source]

Print a helper note about how the environment was determined.

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

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

Whether the user should be prompted or not.

Determined by the existed of CI in the environment.

property is_noninteractive

Whether the user should be prompted or not.

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