Aspects
- class aws_cdk.Aspects(*args: Any, **kwargs)
Bases:
object
Aspects can be applied to CDK tree scopes and can operate on the tree before synthesis.
- ExampleMetadata:
nofixture infused
Example:
import aws_cdk as cdk from constructs import Construct, IConstruct @jsii.implements(cdk.IAspect) class MyAspect: def visit(self, node): if node instanceof cdk.CfnResource && node.cfn_resource_type == "Foo::Bar": self.error(node, "we do not want a Foo::Bar resource") def error(self, node, message): cdk.Annotations.of(node).add_error(message) class MyStack(cdk.Stack): def __init__(self, scope, id): super().__init__(scope, id) stack = cdk.Stack() cdk.CfnResource(stack, "Foo", type="Foo::Bar", properties={ "Fred": "Thud" } ) cdk.Aspects.of(stack).add(MyAspect())
Methods
- add(aspect, *, priority=None)
Adds an aspect to apply this scope before synthesis.
- Parameters:
aspect (
IAspect
) – The aspect to add.priority (
Union
[int
,float
,None
]) – The priority value to apply on an Aspect. Priority must be a non-negative integer. Aspects that have same priority value are not guaranteed to be executed in a consistent order. Default: AspectPriority.DEFAULT
- Return type:
None
Attributes
- all
The list of aspects which were directly applied on this scope.
- applied
The list of aspects with priority which were directly applied on this scope.
Also returns inherited Aspects of this node.
Static Methods
- classmethod of(scope)
Returns the
Aspects
object associated with a construct scope.- Parameters:
scope (
IConstruct
) – The scope for which these aspects will apply.- Return type: