runway.cfngin.context module

CFNgin context.

runway.cfngin.context.get_fqn(base_fqn, delimiter, name=None)[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.

class runway.cfngin.context.Context(environment=None, boto3_credentials=None, stack_names=None, config=None, config_path=None, region=None, force_stacks=None)[source]

Bases: object

The context under which the current stacks are being executed.

The CFNgin Context is responsible for translating the values passed in via the command line and specified in the config to Stack objects.

Instantiate class.

Parameters
  • boto3_credentials (Optional[Dict[str, str]]) – Credentials to use when creating a boto3 session from context.

  • environment (dict) – A dictionary used to pass in information about the environment. Useful for templating.

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

  • config (runway.cfngin.config.Config) – The CFNgin configuration being operated on.

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

  • region (str) – Name of an AWS region if provided as a CLI argument.

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

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

Graph if a persistent graph is being used.

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

Returns

runway.cfngin.plan.Graph

property persistent_graph_location

Location of the persistent graph in s3.

Returns

Dict[str, str] Bucket and Key for the object in S3.

property persistent_graph_lock_code

Code used to lock the persistent graph S3 object.

Returns

Optional[str]

property persistent_graph_locked

Check if persistent graph is locked.

Returns

bool

property s3_bucket_verified

Check CFNgin bucket exists and you have access.

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

Returns

bool

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.

Returns

(bool)

get_targets()[source]

Return the named targets that are specified in the config.

Returns

a list of runway.cfngin.target.Target objects

Return type

list

get_session(profile=None, region=None)[source]

Create a thread-safe boto3 session.

Parameters
  • profile (Optional[str]) – The profile for the session.

  • region (Optional[str]) – The region for the session.

Returns

A thread-safe boto3 session.

Return type

boto3.session.Session

get_stack(name)[source]

Get a stack by name.

Parameters

name (str) – Name of a stack to retrieve.

get_stacks()[source]

Get the stacks for the current action.

Handles configuring the runway.cfngin.stack.Stack objects that will be used in the current action.

Returns

a list of runway.cfngin.stack.Stack objects

Return type

list

get_stacks_dict()[source]

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

get_fqn(name=None)[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.

lock_persistent_graph(lock_code)[source]

Locks the persistent graph in s3.

Parameters

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

Raises
put_persistent_graph(lock_code)[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, data)[source]

Set hook data for the given key.

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

  • data (collections.Mapping) – A dictionary of data to store, as returned from a hook.

unlock_persistent_graph(lock_code)[source]

Unlocks the persistent graph in s3.

Parameters

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

Raises

runway.cfngin.exceptions.PersistentGraphCannotUnlock