class Aspects
| Language | Type name |
|---|---|
.NET | Amazon.CDK.Aspects |
Go | github.com/aws/aws-cdk-go/awscdk/v2#Aspects |
Java | software.amazon.awscdk.Aspects |
Python | aws_cdk.Aspects |
TypeScript (source) | aws-cdk-lib » Aspects |
Aspects can be applied to CDK tree scopes and can operate on the tree before synthesis.
Example
import * as cdk from 'aws-cdk-lib';
import { Construct, IConstruct } from 'constructs';
class MyAspect implements cdk.IAspect {
public visit(node: IConstruct): void {
if (node instanceof cdk.CfnResource && node.cfnResourceType === 'Foo::Bar') {
this.error(node, 'we do not want a Foo::Bar resource');
}
}
protected error(node: IConstruct, message: string): void {
cdk.Annotations.of(node).addError(message);
}
}
class MyStack extends cdk.Stack {
constructor(scope: Construct, id: string) {
super(scope, id);
const stack = new cdk.Stack();
new cdk.CfnResource(stack, 'Foo', {
type: 'Foo::Bar',
properties: {
Fred: 'Thud',
},
});
cdk.Aspects.of(stack).add(new MyAspect());
}
}
Properties
| Name | Type | Description |
|---|---|---|
| all | IAspect[] | The list of aspects which were directly applied on this scope. |
| applied | Aspect[] | The list of aspects with priority which were directly applied on this scope. |
all
Type:
IAspect[]
The list of aspects which were directly applied on this scope.
applied
Type:
Aspect[]
The list of aspects with priority which were directly applied on this scope.
Also returns inherited Aspects of this node.
Methods
| Name | Description |
|---|---|
| add(aspect, options?) | Adds an aspect to apply this scope before synthesis. |
| static of(scope) | Returns the Aspects object associated with a construct scope. |
add(aspect, options?)
public add(aspect: IAspect, options?: AspectOptions): void
Parameters
- aspect
IAspect— The aspect to add. - options
Aspect— Options to apply on this aspect.Options
Adds an aspect to apply this scope before synthesis.
static of(scope)
public static of(scope: IConstruct): Aspects
Parameters
- scope
IConstruct— The scope for which these aspects will apply.
Returns
Returns the Aspects object associated with a construct scope.

.NET
Go
Java
Python
TypeScript (