ConstructNode

class aws_cdk.core.ConstructNode(host, scope, id)

Bases: object

Represents the construct node in the scope tree.

__init__(host, scope, id)
Parameters
Return type

None

Methods

add_dependency(*dependencies)

Add an ordering dependency on another Construct.

All constructs in the dependency’s scope will be deployed before any construct in this construct’s scope.

Parameters

dependencies (IDependable) –

Return type

None

add_error(message)

Adds an { error: } metadata entry to this construct. The toolkit will fail synthesis when errors are reported.

Parameters

message (str) – The error message.

Return type

None

add_info(message)

Adds a { “aws:cdk:info”: } metadata entry to this construct. The toolkit will display the info message when apps are synthesized.

Parameters

message (str) – The info message.

Return type

None

add_metadata(type, data, from_=None)

Adds a metadata entry to this construct. Entries are arbitrary values and will also include a stack trace to allow tracing back to the code location for when the entry was added. It can be used, for example, to include source mapping in CloudFormation templates to improve diagnostics.

Parameters
  • type (str) – a string denoting the type of metadata.

  • data (Any) – the value of the metadata (can be a Token). If null/undefined, metadata will not be added.

  • from – a function under which to restrict the metadata entry’s stack trace (defaults to this.addMetadata).

Return type

None

add_warning(message)

Adds a { warning: } metadata entry to this construct. The toolkit will display the warning when an app is synthesized, or fail if run in –strict mode.

Parameters

message (str) – The warning message.

Return type

None

apply_aspect(aspect)

Applies the aspect to this Constructs node.

Parameters

aspect (IAspect) –

Return type

None

find_all(order=None)

Return this construct and all of its children in the given order.

Parameters

order (Optional[ConstructOrder]) –

Return type

List[IConstruct]

find_child(id)

Return a direct child by id.

Throws an error if the child is not found.

Parameters

id (str) – Identifier of direct child.

return :rtype: IConstruct :return: Child with the given id.

set_context(key, value)

This can be used to set contextual values. Context must be set before any children are added, since children may consult context info during construction. If the key already exists, it will be overridden.

Parameters
  • key (str) – The context key.

  • value (Any) – The context value.

Return type

None

try_find_child(id)

Return a direct child by id, or undefined.

Parameters

id (str) – Identifier of direct child.

return :rtype: Optional[IConstruct] :return: the child if found, or undefined

try_get_context(key)

Retrieves a value from tree context.

Context is usually initialized at the root, but can be overridden at any point in the tree.

Parameters

key (str) – The context key.

return :rtype: Any :return: The context value or undefined if there is no context value for thie key.

Attributes

PATH_SEP = '/'
children

All direct children of this construct.

Return type

List[IConstruct]

default_child

Returns the child construct that has the id Default or Resource". This is usually the construct that provides the bulk of the underlying functionality. Useful for modifications of the underlying construct that are not available at the higher levels. Override the defaultChild property.

This should only be used in the cases where the correct default child is not named ‘Resource’ or ‘Default’ as it should be.

If you set this to undefined, the default behavior of finding the child named ‘Resource’ or ‘Default’ will be used.

return :rtype: Optional[IConstruct] :return: a construct or undefined if there is no default child

throws: :throws:: if there is more than one child

dependencies

Return all dependencies registered on this node or any of its children.

Return type

List[Dependency]

id

The id of this construct within the current scope.

This is a a scope-unique id. To obtain an app-unique id for this construct, use uniqueId.

Return type

str

locked

Returns true if this construct or the scopes in which it is defined are locked.

Return type

bool

metadata

An immutable array of metadata objects associated with this construct. This can be used, for example, to implement support for deprecation notices, source mapping, etc.

Return type

List[MetadataEntry]

path

The full, absolute path of this construct in the tree.

Components are separated by ‘/’.

Return type

str

root

return :rtype: IConstruct :return: The root of the construct tree.

scope

Returns the scope in which this construct is defined.

The value is undefined at the root of the construct scope tree.

Return type

Optional[IConstruct]

scopes

All parent scopes of this construct.

return :rtype: List[IConstruct] :return:

a list of parent scopes. The last element in the list will always be the current construct and the first element will be the root of the tree.

unique_id

A tree-global unique alphanumeric identifier for this construct. Includes all components of the tree.

Return type

str

Static Methods

classmethod prepare(node)

Invokes “prepare” on all constructs (depth-first, post-order) in the tree under node.

Parameters

node (ConstructNode) – The root node.

Return type

None

classmethod synth(root, *, outdir=None, skip_validation=None, runtime_info=None)

Synthesizes a CloudAssembly from a construct tree.

Parameters
  • root (ConstructNode) – The root of the construct tree.

  • options – Synthesis options.

  • outdir (Optional[str]) – The output directory into which to synthesize the cloud assembly. Default: - creates a temporary directory

  • skip_validation (Optional[bool]) – Whether synthesis should skip the validation phase. Default: false

  • runtime_info (Optional[RuntimeInfo]) – Include the specified runtime information (module versions) in manifest. Default: - if this option is not specified, runtime info will not be included

Return type

CloudAssembly

classmethod validate(node)

Invokes “validate” on all constructs in the tree (depth-first, pre-order) and returns the list of all errors.

An empty list indicates that there are no errors.

Parameters

node (ConstructNode) – The root node.

Return type

List[ValidationError]