runway.cfngin.hooks.utils module

Hook utils.

class runway.cfngin.hooks.utils.BlankBlueprint[source]

Bases: runway.cfngin.blueprints.base.Blueprint

Blueprint that can be built programmatically.

create_template() None[source]

Create template without raising NotImplementedError.

__init__(name: str, context: runway.context.CfnginContext, *, description: Optional[str] = None, mappings: Optional[Dict[str, Dict[str, Any]]] = None, template: Optional[troposphere.Template] = None, **_: Any)

Instantiate class.

Parameters
  • name – A name for the blueprint.

  • context – Context the blueprint is being executed under.

  • description – The description of the CloudFormation template that will be generated by this blueprint.

  • mappings – CloudFormation Mappings to be used in the template during the rendering process.

  • template – Optionally, provide a preexisting Template.

Changed in version 2.0.0: Added template.

Changed in version 2.0.0: Class only takes 2 positional arguments. The rest are now keyword arguments.

__new__(**kwargs)
add_output(name: str, value: Any) None

Add an output to the template.

Wrapper for self.template.add_output(Output(name, Value=value)).

Parameters
  • name – The name of the output to create.

  • value – The value to put in the output.

property cfn_parameters: Dict[str, Union[List[Any], str]]

Return a dict of variables with type CFNType.

New in version 2.0.0.

Returns

Variables that need to be submitted as CloudFormation Parameters.

property defined_variables: Dict[str, BlueprintVariableTypeDef]

Return a copy of VARIABLES to avoid accidental modification of the ClassVar.

Changed in version 2.0.0: Changed from a method to a property.

get_cfn_parameters() Dict[str, Union[List[Any], str]]

Return a dictionary of variables with type CFNType.

Deprecated since version 2.0.0: Replaced by cfn_parameters.

Returns

Variables that need to be submitted as CloudFormation Parameters.

get_output_definitions() Dict[str, Dict[str, Any]]

Get the output definitions.

Deprecated since version 2.0.0: Replaced by output_definitions.

Returns

Output definitions. Keys are output names, the values are dicts containing key/values for various output properties.

get_parameter_definitions() Dict[str, BlueprintVariableTypeDef]

Get the parameter definitions to submit to CloudFormation.

Any variable definition whose type is an instance of CFNType will be returned as a CloudFormation Parameter.

Deprecated since version 2.0.0: Replaced by parameter_definitions.

Returns

Parameter definitions. Keys are parameter names, the values are dicts containing key/values for various parameter properties.

get_parameter_values() Dict[str, Union[List[Any], str]]

Return a dict of variables with type CFNType.

Deprecated since version 2.0.0: Replaced by parameter_values.

Returns

Variables that need to be submitted as CloudFormation Parameters. Will be a dictionary of <parameter name>: <parameter value>.

get_required_parameter_definitions() Dict[str, BlueprintVariableTypeDef]

Return all template parameters that do not have a default value.

Deprecated since version 2.0.0: Replaced by required_parameter_definitions.

Returns

Dict of required CloudFormation Parameters for the blueprint. Will be a dictionary of <parameter name>: <parameter attributes>.

get_variables() Dict[str, Any]

Return a dictionary of variables available to the template.

These variables will have been defined within VARIABLES or self.defined_variables. Any variable value that contains a lookup will have been resolved.

Deprecated since version 2.0.0: Replaced by variables.

Returns

Variables available to the template.

Raises

UnresolvedBlueprintVariables – If variables are unresolved.

import_mappings() None

Import mappings from CFNgin config to the blueprint.

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

Get the output definitions.

New in version 2.0.0.

Returns

Output definitions. Keys are output names, the values are dicts containing key/values for various output properties.

property parameter_definitions: Dict[str, BlueprintVariableTypeDef]

Get the parameter definitions to submit to CloudFormation.

Any variable definition whose type is an instance of CFNType will be returned as a CloudFormation Parameter.

New in version 2.0.0.

Returns

Parameter definitions. Keys are parameter names, the values are dicts containing key/values for various parameter properties.

property parameter_values: Dict[str, Union[List[Any], str]]

Return a dict of variables with type CFNType.

New in version 2.0.0.

Returns

Variables that need to be submitted as CloudFormation Parameters. Will be a dictionary of <parameter name>: <parameter value>.

read_user_data(user_data_path: str) str

Read and parse a user_data file.

Parameters

user_data_path – Path to the userdata file.

render_template() Tuple[str, str]

Render the Blueprint to a CloudFormation template.

property rendered: str

Return rendered blueprint.

property required_parameter_definitions: Dict[str, BlueprintVariableTypeDef]

Return all template parameters that do not have a default value.

New in version 2.0.0.

Returns

Dict of required CloudFormation Parameters for the blueprint. Will be a dictionary of <parameter name>: <parameter attributes>.

property requires_change_set: bool

Return true if the underlying template has transforms.

reset_template() None

Reset template.

resolve_variables(provided_variables: List[runway.variables.Variable]) None

Resolve the values of the blueprint variables.

This will resolve the values of the VARIABLES with values from the env file, the config, and any lookups resolved.

Parameters

provided_variables – List of provided variables.

set_template_description(description: str) None

Add a description to the Template.

Parameters

description – A description to be added to the resulting template.

setup_parameters() None

Add any CloudFormation parameters to the template.

to_json(variables: Optional[Dict[str, Any]] = None) str

Render the blueprint and return the template in json form.

Parameters

variables – Dictionary providing/overriding variable values.

property variables: Dict[str, Any]

Return a Dict of variables available to the Template.

These variables will have been defined within VARIABLES or defined_variables. Any variable value that contains a Lookup will have been resolved.

New in version 2.0.0.

Returns

Variables available to the Template.

Raises

UnresolvedBlueprintVariables – If variables are unresolved.

property version: str

Template version.

class runway.cfngin.hooks.utils.TagDataModel[source]

Bases: runway.utils.BaseModel

AWS Resource Tag data model.

class Config[source]

Bases: object

Model configuration.

__init__()
__new__(**kwargs)
__contains__(name: object) bool

Implement evaluation of ‘in’ conditional.

Parameters

name – The name to check for existence in the model.

__getitem__(name: str) Any

Implement evaluation of self[name].

Parameters

name – Attribute name to return the value for.

Returns

The value associated with the provided name/attribute name.

Raises

AttributeError – If attribute does not exist on this object.

__init__(**data: Any) None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be parsed to form a valid model.

__iter__() TupleGenerator

so dict(model) works

__new__(**kwargs)
__pretty__(fmt: Callable[[Any], Any], **kwargs: Any) Generator[Any, None, None]

Used by devtools (https://python-devtools.helpmanual.io/) to provide a human readable representations of objects

__repr_name__() unicode

Name of the instance’s class, used in __repr__.

__rich_repr__() RichReprResult

Get fields for Rich library

__setitem__(name: str, value: Any) None

Implement item assignment (e.g. self[name] = value).

Parameters
  • name – Attribute name to set.

  • value – Value to assign to the attribute.

classmethod __try_update_forward_refs__(**localns: Any) None

Same as update_forward_refs but will not raise exception when forward references are not defined.

classmethod construct(_fields_set: Optional[SetStr] = None, **values: Any) Model

Creates a new model setting __dict__ and __fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed. Behaves as if Config.extra = ‘allow’ was set since it adds all passed values

copy(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, update: Optional[DictStrAny] = None, deep: bool = False) Model

Duplicate a model, optionally choose which fields to include, exclude and change.

Parameters
  • include – fields to include in new model

  • exclude – fields to exclude from new model, as with values this takes precedence over include

  • update – values to change/add in the new model. Note: the data is not validated before creating the new model: you should trust this data

  • deep – set to True to make a deep copy of the model

Returns

new model instance

dict(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) DictStrAny

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

get(name: str, default: Optional[Any] = None) Any

Safely get the value of an attribute.

Parameters
  • name – Attribute name to return the value for.

  • default – Value to return if attribute is not found.

json(*, include: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, exclude: Optional[Union[AbstractSetIntStr, MappingIntStrAny]] = None, by_alias: bool = False, skip_defaults: Optional[bool] = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Optional[Callable[[Any], Any]] = None, models_as_dict: bool = True, **dumps_kwargs: Any) unicode

Generate a JSON representation of the model, include and exclude arguments as per dict().

encoder is an optional function to supply as default to json.dumps(), other arguments as per json.dumps().

classmethod update_forward_refs(**localns: Any) None

Try to update ForwardRefs on fields based on this Model, globalns and localns.

runway.cfngin.hooks.utils.full_path(path: str) str[source]

Return full path.

runway.cfngin.hooks.utils.handle_hooks(stage: str, hooks: List[CfnginHookDefinitionModel], provider: Provider, context: CfnginContext)[source]

Handle pre/post_deploy hooks.

These are pieces of code that we want to run before/after deploying stacks.

Parameters
  • stage – The current stage (pre_run, post_run, etc).

  • hooks – Hooks to execute.

  • provider – Provider instance.

  • context – Context instance.