runway.cfngin.lookups.handlers.ami module

AMI lookup.

exception runway.cfngin.lookups.handlers.ami.ImageNotFound(search_string: str)[source]

Bases: Exception

Image not found.

Instantiate class.


Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class runway.cfngin.lookups.handlers.ami.AmiLookup[source]

Bases: runway.lookups.handlers.base.LookupHandler

AMI lookup.

classmethod dependencies(_LookupHandler__lookup_query: VariableValue)Set[str]

Calculate any dependencies required to perform this lookup.

Note that lookup_query may not be (completely) resolved at this time.

classmethod format_results(value: Any, get: Optional[str] = None, load: Optional[str] = None, transform: Optional[str] = None, **kwargs: Any)Any

Format results to be returned by a lookup.

  • value – Data collected by the Lookup.

  • get – Nested value to get from a dictionary like object.

  • load – Parser to use to parse a formatted string before the get and transform method.

  • transform – Convert the final value to a different data type before returning it.


TypeError – If get is provided but the value value is not a dictionary like object.

Runs the following actions in order:

  1. load() if load is provided.

  2. runway.util.MutableMap.find() or dict.get() depending on the data type if get is provided.

  3. transform() if transform is provided.

classmethod handle(value: str, context: CfnginContext, *_AmiLookup__args: Any, **_AmiLookup__kwargs: Any)str[source]

Fetch the most recent AMI Id using a filter.

  • value – Parameter(s) given to this lookup.

  • context – Context instance.


The above fetches the most recent AMI where owner is self account or amazon and the ami name matches the regex described, the architecture will be either x64 or i386

You can also optionally specify the region in which to perform the AMI lookup.

Valid arguments:

owners (comma delimited) REQUIRED ONCE:

aws_account_id | amazon | self

name_regex (a regex) REQUIRED ONCE:

e.g. my-ubuntu-server-[0-9]+

executable_users (comma delimited) OPTIONAL ONCE:

aws_account_id | amazon | self

Any other arguments specified are sent as filters to the aws api For example, architecture:x86_64 will add a filter

classmethod load(value: Any, parser: Optional[str] = None, **kwargs: Any)Any

Load a formatted string or object into a python data type.

First action taken in format_results(). If a lookup needs to handling loading data to process it before it enters format_results(), is should use args.pop('load') to prevent the data from being loaded twice.

  • value – What is being loaded.

  • parser – Name of the parser to use.


The loaded value.

classmethod parse(value: str)Tuple[str, Dict[str, str]]

Parse the value passed to a lookup in a standardized way.


value – The raw value passed to a lookup.


The lookup query and a dict of arguments

classmethod transform(value: Any, *, to_type: Optional[str] = 'str', **kwargs: Any)Any

Transform the result of a lookup into another datatype.

Last action taken in format_results(). If a lookup needs to handling transforming the data in a way that the base class can’t support it should overwrite this method of the base class to register different transform methods.

  • value – What is to be transformed.

  • to_type – The type the value will be transformed into.


The transformed value.