Classes
Name|Description ----|----------- Construct|Represents the building block of the construct graph. ConstructMetadata|Metadata keys used by constructs. Node|Represents the construct node in the scope tree.
Structs
Name|Description ----|----------- ConstructOptions|Options for creating constructs. Dependency|A single dependency. MetadataEntry|An entry in the construct metadata table. SynthesisOptions|Options for synthesis. ValidationError|An error returned during the validation phase.
Interfaces
Name|Description
----|-----------
IAspect|Represents an Aspect.
IConstruct|Represents a construct.
INodeFactory|A factory for attaching Node
s to the construct.
ISynthesisSession|Represents a single session of synthesis.
IValidation|Implement this interface in order for the construct to be able to validate itself.
Enums
Name|Description ----|----------- ConstructOrder|In what order to return constructs.
Represents the building block of the construct graph.
All constructs besides the root construct must be created within the scope of another construct.
Implements: IConstruct
Creates a new construct node.
new Construct(scope: Construct, id: string, options?: ConstructOptions)
Construct
) The scope in which to define this construct.string
) The scoped construct ID.ConstructOptions
) Options.INodeFactory
) A factory for attaching Node
s to the construct. Default: the default Node
is associatedReturns a string representation of this construct.
toString(): string
Returns:
* string
Perform final modifications before synthesis.
This method can be implemented by derived constructs in order to perform final changes before synthesis. prepare() will be called after child constructs have been prepared.
This is an advanced framework feature. Only use this if you understand the implications.
protected onPrepare(): void
Allows this construct to emit artifacts into the cloud assembly during synthesis.
This method is usually implemented by framework-level constructs such as Stack
and Asset
as they participate in synthesizing the cloud assembly.
protected onSynthesize(session: ISynthesisSession): void
ISynthesisSession
) The synthesis session.Validate the current construct.
This method can be implemented by derived constructs in order to perform validation logic. It is called on all constructs before synthesis.
protected onValidate(): Array<string>
Returns:
* Array
Metadata keys used by constructs.
Name | Type | Description
-----|------|-------------
static DISABLE_STACK_TRACE_IN_METADATA | string
| If set in the construct's context, omits stack traces from metadata entries.
static ERROR_METADATA_KEY | string
| Context type for error level messages.
static INFO_METADATA_KEY | string
| Context type for info level messages.
static WARNING_METADATA_KEY | string
| Context type for warning level messages.
Represents the construct node in the scope tree.
new Node(host: Construct, scope: IConstruct, id: string)
Construct
) No descriptionIConstruct
) No descriptionstring
) No descriptionName | Type | Description
-----|------|-------------
addr | string
| Returns an opaque tree-unique address for this construct.
children | Array<IConstruct>
| All direct children of this construct.
dependencies | Array<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 | Array<MetadataEntry>
| An immutable array of metadata objects associated with this construct.
path | string
| The full, absolute path of this construct in the tree.
root | IConstruct
| Returns the root of the construct tree.
scopes | Array<IConstruct>
| All parent scopes of this construct.
uniqueId⚠️ | string
| A tree-global unique alphanumeric identifier for this construct.
defaultChild? | IConstruct
| Returns the child construct that has the id Default
or Resource"
.Optional
scope? | IConstruct
| Returns the scope in which this construct is defined.Optional
static PATH_SEP | string
| Separator used to delimit construct path components.
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.
addDependency(...dependencies: IConstruct[]): void
IConstruct
) No descriptionAdds an { "error": } metadata entry to this construct.
The toolkit will fail synthesis when errors are reported.
addError(message: string): void
string
) The error message.Adds a { "info": } metadata entry to this construct.
The toolkit will display the info message when apps are synthesized.
addInfo(message: string): void
string
) The info message.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.
addMetadata(type: string, data: any, fromFunction?: any): void
string
) a string denoting the type of metadata.any
) the value of the metadata (can be a Token).any
) a function under which to restrict the metadata entry's stack trace (defaults to this.addMetadata).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.
addValidation(validation: IValidation): void
IValidation
) No descriptionAdds 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.
addWarning(message: string): void
string
) The warning message.Applies the aspect to this Constructs node.
applyAspect(aspect: IAspect): void
IAspect
) No descriptionReturn this construct and all of its children in the given order.
findAll(order?: ConstructOrder): Array<IConstruct>
ConstructOrder
) No descriptionReturns:
* Array<IConstruct>
Return a direct child by id.
Throws an error if the child is not found.
findChild(id: string): IConstruct
string
) Identifier of direct child.Returns:
* IConstruct
Invokes "prepare" on all constructs (depth-first, post-order) in the tree under node
.
prepare(): void
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.
setContext(key: string, value: any): void
string
) The context key.any
) The context value.Synthesizes a CloudAssembly from a construct tree.
synthesize(options: SynthesisOptions): void
SynthesisOptions
) Synthesis options.string
) The output directory into which to synthesize the cloud assembly. Map
) Additional context passed into the synthesis session object when construct.synth
is called. Default: no additional context is passed to onSynthesize
boolean
) Whether synthesis should skip the validation phase. Default: falseReturn a direct child by id, or undefined.
tryFindChild(id: string): IConstruct
string
) Identifier of direct child.Returns:
* IConstruct
Retrieves a value from tree context.
Context is usually initialized at the root, but can be overridden at any point in the tree.
tryGetContext(key: string): any
string
) The context key.Returns:
* any
Remove the child with the given name, if present.
tryRemoveChild(childName: string): boolean
string
) No descriptionReturns:
* boolean
Validates tree (depth-first, pre-order) and returns the list of all errors.
An empty list indicates that there are no errors.
validate(): Array<ValidationError>
Returns:
* Array<ValidationError>
Returns the node associated with a construct.
static of(construct: IConstruct): Node
IConstruct
) the construct.Returns:
* Node
Options for creating constructs.
Name | Type | Description
-----|------|-------------
nodeFactory? | INodeFactory
| A factory for attaching Node
s to the construct.Default: the default Node
is associated
A single dependency.
Name | Type | Description
-----|------|-------------
source | IConstruct
| Source the dependency.
target | IConstruct
| Target of the dependency.
Represents an Aspect.
All aspects can visit an IConstruct.
visit(node: IConstruct): void
IConstruct
) No descriptionImplemented by: Construct Obtainable from: Node.findChild(), Node.tryFindChild()
Represents a construct.
A factory for attaching Node
s to the construct.
Returns a new Node
associated with host
.
createNode(host: Construct, scope: IConstruct, id: string): Node
Construct
) the associated construct.IConstruct
) the construct's scope (parent).string
) the construct id.Returns:
* Node
Represents a single session of synthesis.
Passed into construct.onSynthesize()
methods.
Name | Type | Description
-----|------|-------------
outdir | string
| The output directory for this synthesis session.
Implement this interface in order for the construct to be able to validate itself.
Validate the current construct.
This method can be implemented by derived constructs in order to perform validation logic. It is called on all constructs before synthesis.
validate(): Array<string>
Returns:
* Array
An entry in the construct metadata table.
Name | Type | Description
-----|------|-------------
data | any
| The data.
type | string
| The metadata entry type.
trace? | Array
| Stack trace.Default: no trace information
Options for synthesis.
Name | Type | Description
-----|------|-------------
outdir | string
| The output directory into which to synthesize the cloud assembly.
sessionContext? | Map
| Additional context passed into the synthesis session object when construct.synth
is called.Default: no additional context is passed to onSynthesize
skipValidation? | boolean
| Whether synthesis should skip the validation phase.Default: false
An error returned during the validation phase.
Name | Type | Description
-----|------|-------------
message | string
| The error message.
source | Construct
| The construct which emitted the error.
In what order to return constructs.
Name | Description -----|----- PREORDER |Depth-first, pre-order. POSTORDER |Depth-first, post-order (leaf nodes first).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.