Node¶
-
class
constructs.
Node
(host, scope, id)¶ Bases:
object
Represents the construct node in the scope tree.
- Parameters
host (
Construct
) –scope (
IConstruct
) –id (
str
) –
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 (
IConstruct
) –- 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 { “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_function=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_function (
Optional
[Any
]) – a function under which to restrict the metadata entry’s stack trace (defaults to this.addMetadata).
- Return type
None
-
add_validation
(validation)¶ Adds a validation to this construct.
When
node.validate()
is called, thevalidate()
method will be called on all validations and all errors will be returned.- Parameters
validation (
IValidation
) –- 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 type
- Returns
Child with the given id.
-
prepare
()¶ Invokes “prepare” on all constructs (depth-first, post-order) in the tree under
node
.- Return type
None
-
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
-
synthesize
(*, outdir, session_context=None, skip_validation=None)¶ Synthesizes a CloudAssembly from a construct tree.
- Parameters
outdir (
str
) – The output directory into which to synthesize the cloud assembly. Default: - creates a temporary directorysession_context (
Optional
[Mapping
[str
,Any
]]) – Additional context passed into the synthesis session object whenconstruct.synth
is called. Default: - no additional context is passed toonSynthesize
skip_validation (
Optional
[bool
]) – Whether synthesis should skip the validation phase. Default: false
- Return type
None
-
try_find_child
(id)¶ Return a direct child by id, or undefined.
- Parameters
id (
str
) – Identifier of direct child.- Return type
Optional
[IConstruct
]- Returns
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 type
Any
- Returns
The context value or
undefined
if there is no context value for thie key.
-
try_remove_child
(child_name)¶ (experimental) Remove the child with the given name, if present.
- Parameters
child_name (
str
) –- Return type
bool
- Returns
Whether a child with the given name was deleted.
- Stability
experimental
-
validate
()¶ Validates tree (depth-first, pre-order) and returns the list of all errors.
An empty list indicates that there are no errors.
- Return type
List
[ValidationError
]
Attributes
-
PATH_SEP
= '/'¶
-
addr
¶ Returns an opaque tree-unique address for this construct.
Addresses are 42 characters hexadecimal strings. They begin with “c8” followed by 40 lowercase hexadecimal characters (0-9a-f).
Addresses are calculated using a SHA-1 of the components of the construct path.
To enable refactorings of construct trees, constructs with the ID
Default
will be excluded from the calculation. In those cases constructs in the same tree may have the same addreess.Example:
c83a2846e506bcc5f10682b564084bca2d275709ee
- Return type
str
-
children
¶ All direct children of this construct.
- Return type
List
[IConstruct
]
-
default_child
¶ Returns the child construct that has the id
Default
orResource"
.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 type
Optional
[IConstruct
]- Returns
a construct or undefined if there is no default child
- 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
¶ Returns the root of the construct tree.
- Return type
- Returns
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 type
List
[IConstruct
]- Returns
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
¶ (deprecated) A tree-global unique alphanumeric identifier for this construct.
Includes all components of the tree.
- Deprecated
please avoid using this property and use
addr
to form unique names. This algorithm uses MD5, which is not FIPS-complient and also excludes the identity of the root construct from the calculation.- Stability
deprecated
- Return type
str
Static Methods
-
classmethod
of
(construct)¶ Returns the node associated with a construct.
- Parameters
construct (
IConstruct
) – the construct.- Return type