Tokenization

class aws_cdk.core.Tokenization(*args: Any, **kwargs)

Bases: object

Less oft-needed functions to manipulate Tokens.

Static Methods

classmethod is_resolvable(obj)

Return whether the given object is an IResolvable object.

This is different from Token.isUnresolved() which will also check for encoded Tokens, whereas this method will only do a type check on the given object.

Parameters:

obj (Any) –

Return type:

bool

classmethod resolve(obj, *, resolver, scope, preparing=None, remove_empty=None)

Resolves an object by evaluating all tokens and removing any undefined or empty objects or arrays.

Values can only be primitives, arrays or tokens. Other objects (i.e. with methods) will be rejected.

Parameters:
  • obj (Any) – The object to resolve.

  • resolver (ITokenResolver) – The resolver to apply to any resolvable tokens found.

  • scope (IConstruct) – The scope from which resolution is performed.

  • preparing (Optional[bool]) – Whether the resolution is being executed during the prepare phase or not. Default: false

  • remove_empty (Optional[bool]) – Whether to remove undefined elements from arrays and objects when resolving. Default: true

Return type:

Any

classmethod reverse(x, *, fail_concat=None)

Reverse any value into a Resolvable, if possible.

In case of a string, the string must not be a concatenation.

Parameters:
  • x (Any) –

  • fail_concat (Optional[bool]) – Fail if the given string is a concatenation. If false, just return undefined. Default: true

Return type:

Optional[IResolvable]

classmethod reverse_complete_string(s)

Un-encode a string which is either a complete encoded token, or doesn’t contain tokens at all.

It’s illegal for the string to be a concatenation of an encoded token and something else.

Parameters:

s (str) –

Return type:

Optional[IResolvable]

classmethod reverse_list(l)

Un-encode a Tokenized value from a list.

Parameters:

l (Sequence[str]) –

Return type:

Optional[IResolvable]

classmethod reverse_number(n)

Un-encode a Tokenized value from a number.

Parameters:

n (Union[int, float]) –

Return type:

Optional[IResolvable]

classmethod reverse_string(s)

Un-encode a string potentially containing encoded tokens.

Parameters:

s (str) –

Return type:

TokenizedStringFragments

classmethod stringify_number(x)

Stringify a number directly or lazily if it’s a Token.

If it is an object (i.e., { Ref: ‘SomeLogicalId’ }), return it as-is.

Parameters:

x (Union[int, float]) –

Return type:

str