class Validations
| Language | Type name |
|---|---|
.NET | Amazon.CDK.Validations |
Go | github.com/aws/aws-cdk-go/awscdk/v2#Validations |
Java | software.amazon.awscdk.Validations |
Python | aws_cdk.Validations |
TypeScript (source) | aws-cdk-lib » Validations |
Manages validations for CDK constructs.
Example
/// fixture=validation-plugin
declare const myApp: App;
declare const plugin: IPolicyValidationPlugin;
Validations.of(myApp).addPlugins(plugin);
Properties
| Name | Type | Description |
|---|---|---|
| static ACKNOWLEDGED_RULES_METADATA_KEY | string | Metadata key used to store acknowledged rules on construct nodes. |
static ACKNOWLEDGED_RULES_METADATA_KEY
Type:
string
Metadata key used to store acknowledged rules on construct nodes.
Plugin authors can read this metadata to build audit trails from
acknowledgments recorded via acknowledge().
Methods
| Name | Description |
|---|---|
| acknowledge(...rules) | Acknowledge one or more rules, suppressing them from validation output. |
| add | Adds an error metadata entry to this construct. |
| add | Register one or more validation plugins that will be executed during synthesis. |
| add | Adds a warning metadata entry to this construct that can be acknowledged. |
| static of(scope) | Returns the Validations for the given construct scope. |
acknowledge(...rules)
public acknowledge(...rules: Acknowledgment[]): void
Parameters
- rules
Acknowledgment— the rules to acknowledge.
Acknowledge one or more rules, suppressing them from validation output.
Acknowledgments are recorded to construct metadata so that downstream plugins (e.g. CDK Nag) can read them for audit trails.
Currently only annotation warnings can be suppressed. Annotation errors are not yet acknowledgeable.
If an ID has no well-known prefix, it is assumed to be an annotation rule for backwards compatibility.
addError(id, message)
public addError(id: string, message: string): void
Parameters
- id
string— unique identifier for the error. - message
string— the error message.
Adds an error metadata entry to this construct.
Synthesis will be interrupted when errors are reported.
Note: Annotation errors are not currently acknowledgeable. The ID is
recorded for identification purposes but acknowledge() will not
suppress errors added via this method.
addPlugins(...plugins)
public addPlugins(...plugins: IPolicyValidationPlugin[]): void
Parameters
- plugins
IPolicy— the validation plugins to add.Validation Plugin
Register one or more validation plugins that will be executed during synthesis.
Plugins can only be registered within a Stage or App scope. If any plugin reports a violation, synthesis will be interrupted and the report displayed to the user.
addWarning(id, message)
public addWarning(id: string, message: string): void
Parameters
- id
string— unique identifier for the warning, used for acknowledgement. - message
string— the warning message.
Adds a warning metadata entry to this construct that can be acknowledged.
The CLI will display the warning when an app is synthesized, or fail if run
in --strict mode.
The ID will be stored with the annotation prefix (e.g. annotation::MyWarning).
Use this prefixed ID when calling acknowledge() to suppress the warning.
static of(scope)
public static of(scope: IConstruct): Validations
Parameters
- scope
IConstruct— any construct.
Returns
Returns the Validations for the given construct scope.

.NET
Go
Java
Python
TypeScript (