sceptre.resolvers package

class sceptre.resolvers.CustomYamlTagBase(argument=None, stack=None)[source]

Bases: object

A base class for custom Yaml Elements (i.e. hooks and resolvers).

This base class takes care of common functionality needed by subclasses: | * logging setup (associated with stacks) | * Creating unique clones associated with individual stacks (applied recursively down to all | resolvers in the argument) | * On-stack-connect setup that might be needed once connected to a Stack (applied recursively down to | all resolvers in the argument) | * Automatically resolving resolvers in the argument when accessing self.argument

property argument: Any

This is the resolver or hook’s argument.

This property will resolve all nested resolvers inside the argument, but only if this instance has been associated with a Stack.

Resolving nested resolvers will result in their values being replaced in the dict/list they were in with their resolved value, so we won’t have to resolve them again.

Any resolvers that “resolve to nothing” (i.e. return None) will be removed from the dict/list they were in.

If this property is accessed BEFORE the instance has a stack, it will return the raw argument value. This is to safeguard any __init__() behaviors from triggering resolution prematurely.

Return type

Any

clone_for_stack(stack)[source]

Obtains a clone of the current object, setup and ready for use for a given Stack instance.

Return type

TypeVar(Self)

logger = <Logger sceptre.resolvers (WARNING)>
setup()[source]

This method is called when the object is connected to a Stack instance. Implementation of this method in subclasses can be used to do any initial setup of the object.

exception sceptre.resolvers.RecursiveResolve[source]

Bases: Exception

class sceptre.resolvers.ResolvableContainerProperty(name, placeholder_type=PlaceholderType.explicit)[source]

Bases: ResolvableProperty

This is a descriptor class used to store an attribute that may CONTAIN Resolver objects. Resolvers will be resolved upon access of this property. When resolvers are resolved, they will be replaced in the container with their resolved value, in order to avoid redundant resolutions.

Supports nested dictionary and lists.

Parameters

name (str) – Attribute suffix used to store the property in the instance.

class ResolveLater(instance, name, key, resolution_function)[source]

Bases: object

Represents a value that could not yet be resolved but can be resolved in the future.

assign_value_to_stack(stack, value)[source]

Assigns a COPY of the specified value to the stack instance. This method copies the value rather than directly assigns it to avoid bugs related to shared objects in memory.

Parameters
  • stack (Stack) – The stack to assign the value to

  • value (Union[dict, list]) – The value to assign

get_resolved_value(stack, stack_class)[source]

Obtains the resolved value for this property. Any resolvers that resolve to None will have their key/index removed from their dict/list where they are. Other resolvers will have their key/index’s value replace with the resolved value to avoid redundant resolutions.

Parameters
  • stack (Stack) – The Stack instance to obtain the value for

  • stack_class (Type[Stack]) – The class of the Stack instance.

Return type

TypeVar(T_Container, bound= Union[dict, list])

Returns

The fully resolved container.

class sceptre.resolvers.ResolvableProperty(name, placeholder_type=PlaceholderType.explicit)[source]

Bases: ABC

This is an abstract base class for a descriptor used to store an attribute that have values associated with Resolver objects.

Parameters
  • name (str) – Attribute suffix used to store the property in the instance.

  • placeholder_type – The type of placeholder that should be returned, when placeholders are allowed, when a resolver can’t be resolved.

abstract assign_value_to_stack(stack, value)[source]

Implement this method to assign the value to the resolvable property.

abstract get_resolved_value(stack, stack_class)[source]

Implement this method to return the value of the resolvable_property.

Return type

Any

resolve_resolver_value(resolver)[source]

Returns the resolved parameter value.

If the resolver happens to raise an error and placeholders are currently allowed for resolvers, a placeholder will be returned instead of reraising the error.

Parameters

resolver (Resolver) – The resolver to resolve.

Return type

Any

Returns

The resolved value (or placeholder, in certain circumstances)

class sceptre.resolvers.ResolvableValueProperty(name, placeholder_type=PlaceholderType.explicit)[source]

Bases: ResolvableProperty

This is a descriptor class used to store an attribute that may BE a single Resolver object. If it is a resolver, it will be resolved upon access of this property. When resolved, the resolved value will replace the resolver on the stack in order to avoid redundant resolutions.

Parameters

name (str) – Attribute suffix used to store the property in the instance.

assign_value_to_stack(stack, value)[source]

Assigns the value to the Stack instance passed, setting up and cloning the value if it is a Resolver.

Parameters
  • stack (Stack) – The Stack instance to set the value on

  • value (Any) – The value to set

get_resolved_value(stack, stack_class)[source]

Gets the fully-resolved value from the property. Resolvers will be replaced on the stack instance with their resolved value to avoid redundant resolutions.

Parameters
  • stack (Stack) – The Stack instance to obtain the value from

  • stack_class (Type[Stack]) – The class of the Stack instance

Return type

Any

Returns

The fully resolved value

class sceptre.resolvers.Resolver(argument=None, stack=None)[source]

Bases: CustomYamlTagBase

Resolver is an abstract base class that should be subclassed by all Resolvers.

raise_invalid_argument_error(message, from_=None)[source]
abstract resolve()[source]

An abstract method which must be overwritten by all inheriting classes. This method is called to retrieve the final desired value. Implementation of this method in subclasses must return a suitable object or primitive type.

Submodules

sceptre.resolvers.environment_variable module

class sceptre.resolvers.environment_variable.EnvironmentVariable(*args, **kwargs)[source]

Bases: Resolver

Resolver for shell environment variables.

Parameters

argument (str) – Name of the environment variable to return.

resolve()[source]

Retrieves the value of a named environment variable.

Returns

Value of the environment variable.

Return type

str

sceptre.resolvers.file_contents module

class sceptre.resolvers.file_contents.FileContents(*args, **kwargs)[source]

Bases: Resolver

Resolver for the contents of a file.

Parameters

argument (str) – Absolute path to file.

resolve()[source]

Retrieves the contents of a file at a given absolute file path.

Returns

Contents of file.

Return type

str

sceptre.resolvers.join module

class sceptre.resolvers.join.Join(argument=None, stack=None)[source]

Bases: Resolver

This resolver allows you to join multiple strings together to form a single string. This is great for combining the outputs of multiple resolvers. This resolver works just like CloudFormation’s !Join intrinsic function.

The argument for this resolver should be a list with two elements: (1) A string to join the elements on and (2) a list of items to join.

Example:

parameters:
BaseUrl: !join
  • “:”

    • !stack_output my/app/stack.yaml::HostName

    • !stack_output my/other/stack.yaml::Port

resolve()[source]

An abstract method which must be overwritten by all inheriting classes. This method is called to retrieve the final desired value. Implementation of this method in subclasses must return a suitable object or primitive type.

sceptre.resolvers.no_value module

class sceptre.resolvers.no_value.NoValue(argument=None, stack=None)[source]

Bases: Resolver

This resolver resolves to nothing, functioning just like the AWS::NoValue special value. When assigned to a resolvable Stack property, it will remove the config key/value from the stack or the container on the stack where it has been assigned, as if this value wasn’t assigned at all.

This is mostly useful for simplifying conditional logic on Stack and StackGroup config files where, if a certain condition is met, a value is passed, otherwise it’s not passed at all.

resolve()[source]

An abstract method which must be overwritten by all inheriting classes. This method is called to retrieve the final desired value. Implementation of this method in subclasses must return a suitable object or primitive type.

Return type

None

sceptre.resolvers.placeholders module

class sceptre.resolvers.placeholders.PlaceholderType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

alphanum = 2
explicit = 1
none = 3
sceptre.resolvers.placeholders.are_placeholders_enabled()[source]

Indicates whether placeholders have been globally enabled or not.

Return type

bool

sceptre.resolvers.placeholders.create_placeholder_value(resolver, placeholder_type)[source]
Return type

Any

sceptre.resolvers.placeholders.use_resolver_placeholders_on_error()[source]

A context manager that toggles on placeholders for resolvers that error out. This should NOT be used while creating/launching stacks, but it is often required when validating or diffing stacks whose dependencies haven’t yet been deployed and that reference those dependencies with resolvers, especially in the sceptre_user_data.

sceptre.resolvers.select module

class sceptre.resolvers.select.Select(argument=None, stack=None)[source]

Bases: Resolver

This resolver allows you to select a specific index from a list of items or a specific key from a dict.. This is great for combining with the !split resolver to obtain part of a string. This function works almost the same as CloudFormation’s !Select intrinsic function, except (1) you can use this with negative indexes to select with a reverse index and (2) you can select keys from a dict.

The argument for this resolver should be a list with two elements: (1) A numerical index or string key and (2) a list or dict of items to select out of. If the index is negative, it will select from the end of the list. For example, “-1” would select the last element and “-2” would select the second-to-last element.

Example:

parameters:

# This selects the last element after you split the connection string on “/” DatabaseName: !select

  • -1

  • !split [“/”, !stack_output my/database/stack.yaml::ConnectionString]

resolve()[source]

An abstract method which must be overwritten by all inheriting classes. This method is called to retrieve the final desired value. Implementation of this method in subclasses must return a suitable object or primitive type.

sceptre.resolvers.split module

class sceptre.resolvers.split.Split(argument=None, stack=None)[source]

Bases: Resolver

This resolver will split a value on a given delimiter string. This is great when combining with the !select resolver. This function works the same as CloudFormation’s !Split intrinsic function.

Note: The return value of this resolver is a list, not a string. This will not work to set Stack configurations that expect strings, but it WILL work to set Stack configurations that expect lists.

The argument for this resolver should be a list with two elements: (1) The delimiter to split on and (2) a string to split.

Example:
notifications: !split
  • “;”

  • !stack_output my/sns/topics.yaml::SemicolonDelimitedArns

resolve()[source]

An abstract method which must be overwritten by all inheriting classes. This method is called to retrieve the final desired value. Implementation of this method in subclasses must return a suitable object or primitive type.

sceptre.resolvers.stack_attr module

class sceptre.resolvers.stack_attr.StackAttr(argument=None, stack=None)[source]

Bases: Resolver

Resolves to the value of another field on the Stack Config, including other resolvers.

The argument for this resolver should be the “key path” from the stack object, which can access nested keys/indexes using a “.” to separate segments.

For example, given this Stack Config structure…

sceptre_user_data:
nested_list:
  • first

  • second

Using “!stack_attr sceptre_user_data.nested_list.1” on your stack would resolve to “second”.

STACK_ATTR_MAP = {'protect': 'protected', 'stack_name': 'external_name', 'stack_tags': 'tags', 'template': 'template_handler_config'}
resolve()[source]

Returns the resolved value of the field referenced by the resolver’s argument.

Return type

Any

sceptre.resolvers.stack_output module

class sceptre.resolvers.stack_output.StackOutput(*args, **kwargs)[source]

Bases: StackOutputBase

Resolver for retrieving the value of a Stack output within the current Sceptre StackGroup. Adds the target Stack to the dependencies of the Stack using the Resolver.

Parameters

argument (str in the format "<stack name>::<output key>") – The Stack name and output name to get.

resolve()[source]

Retrieves the value of an output of an internal Stack.

Returns

The value of the Stack output.

Return type

str

setup()[source]

Adds dependency to a Stack.

class sceptre.resolvers.stack_output.StackOutputBase(*args, **kwargs)[source]

Bases: Resolver

A abstract base class which provides methods for getting Stack outputs.

class sceptre.resolvers.stack_output.StackOutputExternal(*args, **kwargs)[source]

Bases: StackOutputBase

Resolver for retrieving the value of an output of any Stack within the current Sceptre stack_group’s account and region.

Parameters

argument (str in the format "<full stack name>::<output key>") – The Stack name and output name to get.

resolve()[source]

Retrieves the value of CloudFormation output of the external Stack

Returns

The value of the Stack output.

Return type

str

sceptre.resolvers.sub module

class sceptre.resolvers.sub.Sub(argument=None, stack=None)[source]

Bases: Resolver

This resolver allows you to create a string using Python string format syntax. This is a great way to combine together a number of resolver outputs into a single string. This functions very similarly to Cloudformation’s !Sub intrinsic function.

The argument to this resolver should be a two-element list: (1) Is the format string, using curly-brace templates to indicate variables, and (2) a dictionary where the keys are the format string’s variable names and the values are the variable values.

Example:

parameters:
ConnectionString: !sub
  • “postgres://{username}:{password}@{hostname}:{port}/{database}”

  • username: {{ var.username }} password: !ssm /my/ssm/password hostname: !stack_output my/database/stack.yaml::HostName port: !stack_output my/database/stack.yaml::Port database: {{var.database}}

resolve()[source]

An abstract method which must be overwritten by all inheriting classes. This method is called to retrieve the final desired value. Implementation of this method in subclasses must return a suitable object or primitive type.