Validations

class aws_cdk.Validations(*args: Any, **kwargs)

Bases: object

Manages validations for CDK constructs.

Example:

# my_app: App
# plugin: IPolicyValidationPlugin

Validations.of(my_app).add_plugins(plugin)

Methods

acknowledge(*rules)

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.

Parameters:

rules (Acknowledgment) – the rules to acknowledge.

Return type:

None

add_error(id, 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.

Parameters:
  • id (str) – unique identifier for the error.

  • message (str) – the error message.

Return type:

None

add_plugins(*plugins)

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.

Parameters:

plugins (IPolicyValidationPlugin) – the validation plugins to add.

Return type:

None

add_warning(id, 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.

Parameters:
  • id (str) – unique identifier for the warning, used for acknowledgement.

  • message (str) – the warning message.

Return type:

None

Attributes

ACKNOWLEDGED_RULES_METADATA_KEY = 'aws:cdk:acknowledged-rules'

Static Methods

classmethod of(scope)

Returns the Validations for the given construct scope.

Parameters:

scope (IConstruct) – any construct.

Return type:

Validations