Skip to content
v2.275.0

Node Class ​

Represents the construct node in the scope tree.

Example ​

ts
import { Node } from 'constructs';

const node = new Node(host, scope, id);
python
from constructs import Node

node = Node(host, scope, id)
java
import software.constructs.Node;

Node node = new Node(host, scope, id);
csharp
// Install: dotnet add package Constructs
using Constructs;

var node = new Node(host, scope, id);
go
// Install: go get github.com/aws/constructs-go/constructs/v10
import "github.com/aws/constructs-go/constructs/v10"

node := constructs.NewNode(host, scope, id)

Initializer ​

ts
new Node(host: Construct, scope: IConstruct, id: string)
python
Node(host: Construct, scope: IConstruct, id: str)
java
new Node(Construct host, IConstruct scope, String id)
csharp
new Node(Construct host, IConstruct scope, string id)
go
NewNode(Host Construct, Scope IConstruct, Id *string)

Properties ​

addrstringaddrstraddrStringAddrstringAddr*string#
An opaque, deterministic address for this construct, derived from its path.
notes · example

The address is a 42 character string: the prefix "c8" followed by 40 lowercase hexadecimal characters (0-9a-f). It is a SHA-1 over the ids of the constructs on the path from the root of the tree down to this construct.

To enable refactoring of construct trees, constructs with the ID Default are excluded from the calculation. Within a tree, a/Default/b and a/b have the same address.

This means the address is not guaranteed to identify a construct uniquely:

  • Any construct whose path is made up of the same ids has the same address. Two trees that are shaped alike therefore hand out the same addresses.
  • As described above, a construct under a Default scope has the same address as its counterpart outside of that scope.
  • The digest is of fixed width, so even distinct paths can in principle hash to the same address. SHA-1 in particular is no longer collision resistant.

Use an address to derive stable, deterministic names from the location of a construct in the tree. Do not use it as the identity of a construct: instead, compare construct instances or use the path.

ts
c83a2846e506bcc5f10682b564084bca2d275709ee
childrenIConstruct[]childrentyping.List[IConstruct]childrenList<IConstruct>ChildrenIConstruct[]Children*[]IConstruct#
All direct children of this construct.
defaultChildmay be undefinedIConstructdefault_childmay be undefinedIConstructdefaultChildmay be undefinedIConstructDefaultChildmay be undefinedIConstructDefaultChildmay be undefinedIConstruct#
Returns the child construct that has the id `Default` or `Resource`.
notes

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.

dependenciesIConstruct[]dependenciestyping.List[IConstruct]dependenciesList<IConstruct>DependenciesIConstruct[]Dependencies*[]IConstruct#
Constructs that this construct depends on directly.

This expands the sets of Dependables to the set of Constructs that they represent.

idstringidstridStringIdstringId*string#
The id of this construct within the current scope.

This is a scope-unique id. To obtain an id that reflects the full location of this construct in the tree, use path or addr.

lockedbooleanlockedboollockedBooleanLockedboolLocked*bool#
Returns true if this construct or the scopes in which it is defined are locked.
metadataMetadataEntry[]metadatatyping.List[MetadataEntry]metadataList<MetadataEntry>MetadataMetadataEntry[]Metadata*[]MetadataEntry#
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.

pathstringpathstrpathStringPathstringPath*string#
The full, absolute path of this construct in the tree.

Components are separated by '/'.

PATH_SEPstringpath_sepstrPATH_SEPStringPATH_SEPstringPATH_SEP*stringstatic#
Separator used to delimit construct path components.
Returns the root of the construct tree.
scopemay be undefinedIConstructscopemay be undefinedIConstructscopemay be undefinedIConstructScopemay be undefinedIConstructScopemay be undefinedIConstruct#
Returns the scope in which this construct is defined.

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

scopesIConstruct[]scopestyping.List[IConstruct]scopesList<IConstruct>ScopesIConstruct[]Scopes*[]IConstruct#
All parent scopes of this construct.

Methods ​

addDependency(...deps: IDependable[]): voiddef add_dependency(self, deps: IDependable) -> Nonepublic void addDependency(IDependable deps)public void AddDependency(IDependable deps)func AddDependency(Deps IDependable)#
Add an ordering dependency on a Dependable (a construct or set of constructs).
notes

It is up to the target document language to decide what an ordering relationship means and how it should be rendered; for example, in the AWS CDK for CloudFormation it means a dependency from every resource in scope of the current construct to every resource in scope of the target set of constructs, that get realized as either stack dependencies or DependsOn relationships in the synthesized template.

IDependable is a marker interface that indicates that a class has used Dependable.implement() to implement the IDependable interface. It can be used to make the target object represent more than one set of constructs at a time. For example, a DependencyGroup uses this interface to represent an explicit list of 0 or more constructs that should be involved in the dependency relationship.

addMetadata(type: string, data: any, options?: MetadataOptions): voiddef add_metadata(self, type: str, data: Any, options: typing.Optional[MetadataOptions] = None) -> Nonepublic void addMetadata(String type, Object data, MetadataOptions options)public void AddMetadata(string type, object data, MetadataOptions? options = null)func AddMetadata(Type *string, Data interface{}, Options MetadataOptions)#
Adds a metadata entry to this construct.
notes · 3 parameters

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. Note that construct metadata is not the same as CloudFormation resource metadata and is never written to the CloudFormation template. The metadata entries are written to the Cloud Assembly Manifest if the treeMetadata property is specified in the props of the App that contains this Construct.

Parameters

  • typetypetypetypeType — a string denoting the type of metadata.
  • datadatadatadataData — the value of the metadata (can be a Token).
  • optionsoptionsoptionsoptionsOptions — options.
addValidation(validation: IValidation): voiddef add_validation(self, validation: IValidation) -> Nonepublic void addValidation(IValidation validation)public void AddValidation(IValidation validation)func AddValidation(Validation IValidation)#
Adds a validation to this construct.

When node.validate() is called, the validate() method will be called on all validations and all errors will be returned.

1 parameter

Parameters

  • validationvalidationvalidationvalidationValidation — The validation object.
findAll(order?: ConstructOrder): IConstruct[]def find_all(self, order: typing.Optional[ConstructOrder] = None) -> typing.List[IConstruct]public List<IConstruct> findAll(ConstructOrder order)public IConstruct[] FindAll(ConstructOrder? order = null)func FindAll(Order ConstructOrder) *[]IConstruct#
Return this construct and all of its children in the given order.
findChild(id: string): IConstructdef find_child(self, id: str) -> IConstructpublic IConstruct findChild(String id)public IConstruct FindChild(string id)func FindChild(Id *string) IConstruct#
Return a direct child by id.

Throws an error if the child is not found.

1 parameter · returns

Parameters

  • ididididId — Identifier of direct child.

Returns: Child with the given id.

getAllContext(defaults?: json): anydef get_all_context(self, defaults: typing.Optional[Any] = None) -> Anypublic Object getAllContext(Object defaults)public object GetAllContext(object? defaults = null)func GetAllContext(Defaults interface{}) interface{}#
Retrieves the all context of a node from tree context.

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

1 parameter · returns

Parameters

  • defaultsdefaultsdefaultsdefaultsDefaults — Any keys to override the retrieved context.

Returns: The context object or an empty object if there is discovered context

getContext(key: string): anydef get_context(self, key: str) -> Anypublic Object getContext(String key)public object GetContext(string key)func GetContext(Key *string) interface{}#
Retrieves a value from tree context if present. Otherwise, would throw an error.

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

1 parameter · returns

Parameters

  • keykeykeykeyKey — The context key.

Returns: The context value or throws error if there is no context value for this key

lock(): voiddef lock(self, ) -> Nonepublic void lock()public void Lock()func Lock()#
Locks this construct from allowing more children to be added.

After this call, no more children can be added to this construct or to any children.

of(construct: IConstruct): Node // chainable@staticmethod def of(construct: IConstruct) -> Nodepublic static Node of(IConstruct construct)public static Node Of(IConstruct construct)func Of(Construct IConstruct) Nodestaticdeprecated#
use `construct.node` instead
1 parameter

Parameters

  • constructconstructconstructconstructConstruct — the construct.
removeDependency(...deps: IDependable[]): voiddef remove_dependency(self, deps: IDependable) -> Nonepublic void removeDependency(IDependable deps)public void RemoveDependency(IDependable deps)func RemoveDependency(Deps IDependable)#
Remove an ordering dependency on a Dependenable (a construct or set of constructs).

This removes any dependency added using node.addDependency(). It must use the exact same object that was involved in the addDependency() call.

setContext(key: string, value: any): voiddef set_context(self, key: str, value: Any) -> Nonepublic void setContext(String key, Object value)public void SetContext(string key, object value)func SetContext(Key *string, Value interface{})#
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.

2 parameters

Parameters

  • keykeykeykeyKey — The context key.
  • valuevaluevaluevalueValue — The context value.
tryFindChild(id: string): IConstructdef try_find_child(self, id: str) -> IConstructpublic IConstruct tryFindChild(String id)public IConstruct TryFindChild(string id)func TryFindChild(Id *string) IConstruct#
Return a direct child by id, or undefined.
1 parameter · returns

Parameters

  • ididididId — Identifier of direct child.

Returns: the child if found, or undefined

tryGetContext(key: string): anydef try_get_context(self, key: str) -> Anypublic Object tryGetContext(String key)public object TryGetContext(string key)func TryGetContext(Key *string) interface{}#
Retrieves a value from tree context.

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

1 parameter · returns

Parameters

  • keykeykeykeyKey — The context key.

Returns: The context value or undefined if there is no context value for this key.

tryRemoveChild(childName: string): booleandef try_remove_child(self, child_name: str) -> boolpublic Boolean tryRemoveChild(String childName)public bool TryRemoveChild(string childName)func TryRemoveChild(ChildName *string) *bool#
Remove the child with the given name, if present.
returns

Returns: Whether a child with the given name was deleted.

validate(): string[]def validate(self, ) -> typing.List[str]public List<String> validate()public string[] Validate()func Validate() *[]*string#
Validates this construct.

Invokes the validate() method on all validations added through addValidation().

returns

Returns: an array of validation error messages associated with this construct.

with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func With(Mixins IMixin) IConstruct#
Applies one or more mixins to this construct.

Mixins are applied in order. The list of constructs is captured at the start of the call, so constructs added by a mixin will not be visited. Use multiple with() calls if subsequent mixins should apply to added constructs.

1 parameter · returns

Parameters

  • mixinsmixinsmixinsmixinsMixins — The mixins to apply.

Returns: This construct for chaining