class Annotations
Language | Type name |
---|---|
.NET | Amazon.CDK.Annotations |
Java | software.amazon.awscdk.core.Annotations |
Python | aws_cdk.core.Annotations |
TypeScript (source) | @aws-cdk/core » Annotations |
Includes API for attaching annotations such as warning messages to constructs.
Example
import * as cdk from '@aws-cdk/core';
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());
}
}
Methods
Name | Description |
---|---|
add | Adds a deprecation warning for a specific API. |
add | Adds an { "error": |
add | Adds an info metadata entry to this construct. |
add | Adds a warning metadata entry to this construct. |
static of(scope) | Returns the annotations API for a construct scope. |
Deprecation(api, message)
addpublic addDeprecation(api: string, message: string): void
Parameters
- api
string
— The API being deprecated in the formatmodule.Class.property
(e.g.@aws-cdk/core.Construct.node
). - message
string
— The deprecation message to display, with information about alternatives.
Adds a deprecation warning for a specific API.
Deprecations will be added only once per construct as a warning and will be
deduplicated based on the api
.
If the environment variable CDK_BLOCK_DEPRECATIONS
is set, this method
will throw an error instead with the deprecation message.
Error(message)
addpublic addError(message: string): void
Parameters
- message
string
— The error message.
Adds an { "error":
The toolkit will fail deployment of any stack that has errors reported against it.
Info(message)
addpublic addInfo(message: string): void
Parameters
- message
string
— The info message.
Adds an info metadata entry to this construct.
The CLI will display the info message when apps are synthesized.
Warning(message)
addpublic addWarning(message: string): void
Parameters
- message
string
— The warning message.
Adds a warning metadata entry to this construct.
The CLI will display the warning when an app is synthesized, or fail if run in --strict mode.
static of(scope)
public static of(scope: IConstruct): Annotations
Parameters
- scope
IConstruct
— The scope.
Returns
Returns the annotations API for a construct scope.