# Annotations

Includes API for attaching annotations such as warning messages to constructs.

- Source: [`core/lib/annotations.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/core/lib/annotations.ts#L11)
- Type last changed: v2.207.0 · 24 Jul 2025

## Example

```ts
import * as cdk from 'aws-cdk-lib';
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

- `acknowledgeInfo(id: string, message?: string): void` — Acknowledge a info. When a info is acknowledged for a scope all infos that match the id will be ignored.

  The acknowledgement will apply to all child scopes

  **Parameters**

  - `id` — - the id of the info message to acknowledge.
  - `message` — optional message to explain the reason for acknowledgement.

  ```ts
  declare const myConstruct: Construct;
  Annotations.of(myConstruct).acknowledgeInfo('SomeInfoId', 'This info can be ignored because...');
  ```

- `acknowledgeWarning(id: string, message?: string): void` — Acknowledge a warning. When a warning is acknowledged for a scope all warnings that match the id will be ignored.

  The acknowledgement will apply to all child scopes

  **Parameters**

  - `id` — - the id of the warning message to acknowledge.
  - `message` — optional message to explain the reason for acknowledgement.

  ```ts
  declare const myConstruct: Construct;
  Annotations.of(myConstruct).acknowledgeWarning('SomeWarningId', 'This warning can be ignored because...');
  ```

- `addDeprecation(api: string, message: string): void` — 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.

  **Parameters**

  - `api` — The API being deprecated in the format `module.Class.property` (e.g. `@aws-cdk/core.Construct.node`).
  - `message` — The deprecation message to display, with information about alternatives.

- `addError(message: string): void` — Adds an { "error": <message> } metadata entry to this construct.

  The toolkit will fail deployment of any stack that has errors reported against it.
  Prefer using `Validations.of(scope).addError()` instead.

  **Parameters**

  - `message` — The error message.

- `addInfo(message: string): void` — Adds an info metadata entry to this construct.

  The CLI will display the info message when apps are synthesized.

  **Parameters**

  - `message` — The info message.

- `addInfoV2(id: string, message: string): void` — Adds an acknowledgeable info metadata entry to this construct.

  The CLI will display the info when an app is synthesized.

  If the info is acknowledged using `acknowledgeInfo()`, it will not be shown by the CLI.

  **Parameters**

  - `id` — the unique identifier for the info.
  - `message` — The info message.

  ```ts
  declare const myConstruct: Construct;
  Annotations.of(myConstruct).addInfoV2('my-library:Construct.someInfo', 'Some message explaining the info');
  ```

- `addWarning(message: string): void` — Adds a warning metadata entry to this construct. Prefer using `Validations.of(scope).addWarning()`.

  The CLI will display the warning when an app is synthesized, or fail if run
  in `--strict` mode.

  Warnings added by this call cannot be acknowledged. This will block users from
  running in `--strict` mode until the deal with the warning, which makes it
  effectively not very different from `addError`. Prefer using `addWarningV2` instead.

  **Parameters**

  - `message` — The warning message.

- `addWarningV2(id: string, message: string): void` — Adds an acknowledgeable warning metadata entry to this construct.

  The CLI will display the warning when an app is synthesized, or fail if run
  in `--strict` mode.

  If the warning is acknowledged using `acknowledgeWarning()`, it will not be shown by
  the CLI, and will not cause `--strict` mode to fail synthesis.

  Prefer using `Validations.of(scope).addWarning()` instead.

  **Parameters**

  - `id` — the unique identifier for the warning.
  - `message` — The warning message.

  ```ts
  declare const myConstruct: Construct;
  Annotations.of(myConstruct).addWarningV2('my-library:Construct.someWarning', 'Some message explaining the warning');
  ```

- `of(scope: IConstruct): Annotations // chainable` (static) — Returns the annotations API for a construct scope.

  **Parameters**

  - `scope` — The scope.
