class ConstructNode
Language | Type name |
---|---|
.NET | Amazon.CDK.ConstructNode |
Java | software.amazon.awscdk.core.ConstructNode |
Python | aws_cdk.core.ConstructNode |
TypeScript (source) | @aws-cdk/core » ConstructNode |
Represents the construct node in the scope tree.
Example
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import * as cdk from '@aws-cdk/core';
declare const construct: cdk.Construct;
const constructNode = new cdk.ConstructNode(construct, construct, 'id');
Initializer
new ConstructNode(host: Construct, scope: IConstruct, id: string)
Parameters
- host
Construct
- scope
IConstruct
- id
string
Properties
Name | Type | Description |
---|---|---|
addr | string | Returns an opaque tree-unique address for this construct. |
children | IConstruct [] | All direct children of this construct. |
dependencies | Dependency [] | Return all dependencies registered on this node or any of its children. |
id | string | The id of this construct within the current scope. |
locked | boolean | Returns true if this construct or the scopes in which it is defined are locked. |
metadata | Metadata [] | DEPRECATED. |
metadata | Metadata [] | An immutable array of metadata objects associated with this construct. |
path | string | The full, absolute path of this construct in the tree. |
root | IConstruct | |
scopes | IConstruct [] | All parent scopes of this construct. |
unique | string | A tree-global unique alphanumeric identifier for this construct. |
default | IConstruct | Returns the child construct that has the id Default or Resource" . |
scope? | IConstruct | Returns the scope in which this construct is defined. |
static PATH_SEP | string | Separator used to delimit construct path components. |
addr
Type:
string
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 value: c83a2846e506bcc5f10682b564084bca2d275709ee
children
Type:
IConstruct
[]
All direct children of this construct.
dependencies
Type:
Dependency
[]
Return all dependencies registered on this node or any of its children.
id
Type:
string
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
.
locked
Type:
boolean
Returns true if this construct or the scopes in which it is defined are locked.
metadata
⚠️ Deprecated: use metadataEntry
Type:
Metadata
[]
DEPRECATED.
metadataEntry
Type:
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.
path
Type:
string
The full, absolute path of this construct in the tree.
Components are separated by '/'.
root
Type:
IConstruct
scopes
Type:
IConstruct
[]
All parent scopes of this construct.
uniqueId
⚠️ Deprecated: use node.addr
to obtain a consistent 42 character address for
this node (see https://github.com/aws/constructs/pull/314).
Alternatively, to get a CloudFormation-compatible unique identifier, use
Names.uniqueId()
.
Type:
string
A tree-global unique alphanumeric identifier for this construct.
Includes all components of the tree.
defaultChild?
Type:
IConstruct
(optional)
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.
scope?
Type:
IConstruct
(optional)
Returns the scope in which this construct is defined.
The value is undefined
at the root of the construct scope tree.
static PATH_SEP
Type:
string
Separator used to delimit construct path components.
Methods
Name | Description |
---|---|
add | Add an ordering dependency on another Construct. |
add | DEPRECATED: Adds an { "error": |
add | DEPRECATED: Adds a { "info": |
add | Adds a metadata entry to this construct. |
add | Add a validator to this construct Node. |
add | DEPRECATED: Adds a { "warning": |
apply | DEPRECATED: Applies the aspect to this Constructs node. |
find | Return this construct and all of its children in the given order. |
find | Return a direct child by id. |
set | This can be used to set contextual values. |
try | Return a direct child by id, or undefined. |
try | Retrieves a value from tree context. |
try | Remove the child with the given name, if present. |
static prepare(node) | Invokes "prepare" on all constructs (depth-first, post-order) in the tree under node . |
static synth(node, options?) | Synthesizes a CloudAssembly from a construct tree. |
static validate(node) | Invokes "validate" on all constructs in the tree (depth-first, pre-order) and returns the list of all errors. |
addDependency(...dependencies)
public addDependency(...dependencies: IDependable[]): void
Parameters
- dependencies
IDependable
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.
addError(message)
public addError(message: string): void
⚠️ Deprecated: use Annotations.of(construct).addError()
Parameters
- message
string
— The error message.
DEPRECATED: Adds an { "error":
The toolkit will fail synthesis when errors are reported.
addInfo(message)
public addInfo(message: string): void
⚠️ Deprecated: use Annotations.of(construct).addInfo()
Parameters
- message
string
— The info message.
DEPRECATED: Adds a { "info":
The toolkit will display the info message when apps are synthesized.
addMetadata(type, data, fromFunction?)
public addMetadata(type: string, data: any, fromFunction?: any): void
Parameters
- type
string
— a string denoting the type of metadata. - data
any
— the value of the metadata (can be a Token). - fromFunction
any
— a function under which to restrict the metadata entry's stack trace (defaults to this.addMetadata).
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.
addValidation(validation)
public addValidation(validation: IValidation): void
Parameters
- validation
IValidation
Add a validator to this construct Node.
addWarning(message)
public addWarning(message: string): void
⚠️ Deprecated: use Annotations.of(construct).addWarning()
Parameters
- message
string
— The warning message.
DEPRECATED: Adds a { "warning":
The toolkit will display the warning when an app is synthesized, or fail if run in --strict mode.
applyAspect(aspect)
public applyAspect(aspect: IAspect): void
⚠️ Deprecated: This API is going to be removed in the next major version of
the AWS CDK. Please use Aspects.of(scope).add()
instead.
Parameters
- aspect
IAspect
DEPRECATED: Applies the aspect to this Constructs node.
findAll(order?)
public findAll(order?: ConstructOrder): IConstruct[]
Parameters
- order
Construct
Order
Returns
Return this construct and all of its children in the given order.
findChild(id)
public findChild(id: string): IConstruct
Parameters
- id
string
— Identifier of direct child.
Returns
Return a direct child by id.
Throws an error if the child is not found.
setContext(key, value)
public setContext(key: string, value: any): void
Parameters
- key
string
— The context key. - value
any
— The context 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.
tryFindChild(id)
public tryFindChild(id: string): IConstruct
Parameters
- id
string
— Identifier of direct child.
Returns
Return a direct child by id, or undefined.
tryGetContext(key)
public tryGetContext(key: string): any
Parameters
- key
string
— The context key.
Returns
any
Retrieves a value from tree context.
Context is usually initialized at the root, but can be overridden at any point in the tree.
tryRemoveChild(childName)
public tryRemoveChild(childName: string): boolean
Parameters
- childName
string
Returns
boolean
Remove the child with the given name, if present.
static prepare(node)
public static prepare(node: ConstructNode): void
⚠️ Deprecated: Use app.synth()
instead
Parameters
- node
Construct
— The root node.Node
Invokes "prepare" on all constructs (depth-first, post-order) in the tree under node
.
static synth(node, options?)
public static synth(node: ConstructNode, options?: SynthesisOptions): CloudAssembly
⚠️ Deprecated: Use app.synth()
or stage.synth()
instead
Parameters
- node
Construct
— The root of the construct tree.Node - options
Synthesis
— Synthesis options.Options
Returns
Synthesizes a CloudAssembly from a construct tree.
static validate(node)
public static validate(node: ConstructNode): ValidationError[]
Parameters
- node
Construct
— The root node.Node
Returns
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.