Skip to content
v2.273.0

Validations Class ​

Manages validations for CDK constructs.

Example ​

ts
/// fixture=validation-plugin
declare const myApp: App;
declare const plugin: IPolicyValidationPlugin;
Validations.of(myApp).addPlugins(plugin);

Properties ​

ACKNOWLEDGED_RULES_METADATA_KEYstringacknowledged_rules_metadata_keystrACKNOWLEDGED_RULES_METADATA_KEYStringACKNOWLEDGED_RULES_METADATA_KEYstringACKNOWLEDGED_RULES_METADATA_KEY*stringrequiredstatic#
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 ​

acknowledge(...rules: Acknowledgment[]): voiddef acknowledge(self, rules: Acknowledgment) -> Nonepublic void acknowledge(Acknowledgment rules)public void Acknowledge(Acknowledgment rules)func Acknowledge(Rules Acknowledgment)#
Acknowledge one or more rules, suppressing them from validation output.
notes · 1 parameter

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.

Parameters

  • rulesrulesrulesrulesRules — the rules to acknowledge.
addError(id: string, message: string): voiddef add_error(self, id: str, message: str) -> Nonepublic void addError(String id, String message)public void AddError(string id, string message)func AddError(Id *string, Message *string)#
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.

2 parameters

Parameters

  • ididididId — unique identifier for the error.
  • messagemessagemessagemessageMessage — the error message.
addPlugins(...plugins: IPolicyValidationPlugin[]): voiddef add_plugins(self, plugins: IPolicyValidationPlugin) -> Nonepublic void addPlugins(IPolicyValidationPlugin plugins)public void AddPlugins(IPolicyValidationPlugin plugins)func AddPlugins(Plugins IPolicyValidationPlugin)#
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.

1 parameter

Parameters

  • pluginspluginspluginspluginsPlugins — the validation plugins to add.
addWarning(id: string, message: string): voiddef add_warning(self, id: str, message: str) -> Nonepublic void addWarning(String id, String message)public void AddWarning(string id, string message)func AddWarning(Id *string, Message *string)#
Adds a warning metadata entry to this construct that can be acknowledged.
notes · 2 parameters

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.

Parameters

  • ididididId — unique identifier for the warning, used for acknowledgement.
  • messagemessagemessagemessageMessage — the warning message.
of(scope: IConstruct): Validations // chainable@staticmethod def of(scope: IConstruct) -> Validationspublic static Validations of(IConstruct scope)public static Validations Of(IConstruct scope)func Of(Scope IConstruct) Validationsstatic#
Returns the Validations for the given construct scope.
1 parameter

Parameters

  • scopescopescopescopeScope — any construct.