Class Annotations

java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.Annotations
All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.102.0 (build e354887)", date="2024-08-23T05:56:09.928Z") @Stability(Stable) public class Annotations extends software.amazon.jsii.JsiiObject
Includes API for attaching annotations such as warning messages to constructs.

Example:

 import software.amazon.awscdk.*;
 import software.constructs.Construct;
 import software.constructs.IConstruct;
 public class MyAspect implements IAspect {
     public void visit(IConstruct node) {
         if (node instanceof CfnResource && node.getCfnResourceType() == "Foo::Bar") {
             this.error(node, "we do not want a Foo::Bar resource");
         }
     }
     public void error(IConstruct node, String message) {
         Annotations.of(node).addError(message);
     }
 }
 public class MyStack extends Stack {
     public MyStack(Construct scope, String id) {
         super(scope, id);
         Stack stack = new Stack();
         CfnResource.Builder.create(stack, "Foo")
                 .type("Foo::Bar")
                 .properties(Map.of(
                         "Fred", "Thud"))
                 .build();
         Aspects.of(stack).add(new MyAspect());
     }
 }
 
  • Nested Class Summary

    Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject

    software.amazon.jsii.JsiiObject.InitializationMode
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Annotations(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
     
    protected
    Annotations(software.amazon.jsii.JsiiObjectRef objRef)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Acknowledge a warning.
    void
    Acknowledge a warning.
    void
    addDeprecation(String api, String message)
    Adds a deprecation warning for a specific API.
    void
    addError(String message)
    Adds an { "error": } metadata entry to this construct.
    void
    addInfo(String message)
    Adds an info metadata entry to this construct.
    void
    addWarning(String message)
    Adds a warning metadata entry to this construct.
    void
    addWarningV2(String id, String message)
    Adds an acknowledgeable warning metadata entry to this construct.
    of(software.constructs.IConstruct scope)
    Returns the annotations API for a construct scope.

    Methods inherited from class software.amazon.jsii.JsiiObject

    jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface software.amazon.jsii.JsiiSerializable

    $jsii$toJson
  • Constructor Details

    • Annotations

      protected Annotations(software.amazon.jsii.JsiiObjectRef objRef)
    • Annotations

      protected Annotations(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
  • Method Details

    • of

      @Stability(Stable) @NotNull public static Annotations of(@NotNull software.constructs.IConstruct scope)
      Returns the annotations API for a construct scope.

      Parameters:
      scope - The scope. This parameter is required.
    • acknowledgeWarning

      @Stability(Stable) public void acknowledgeWarning(@NotNull String id, @Nullable String message)
      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

      Example:

       Construct myConstruct;
       Annotations.of(myConstruct).acknowledgeWarning("SomeWarningId", "This warning can be ignored because...");
       

      Parameters:
      id -
      • the id of the warning message to acknowledge.
      This parameter is required.
      message - optional message to explain the reason for acknowledgement.
    • acknowledgeWarning

      @Stability(Stable) public void acknowledgeWarning(@NotNull String id)
      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

      Example:

       Construct myConstruct;
       Annotations.of(myConstruct).acknowledgeWarning("SomeWarningId", "This warning can be ignored because...");
       

      Parameters:
      id -
      • the id of the warning message to acknowledge.
      This parameter is required.
    • addDeprecation

      @Stability(Stable) public void addDeprecation(@NotNull String api, @NotNull String message)
      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). This parameter is required.
      message - The deprecation message to display, with information about alternatives. This parameter is required.
    • addError

      @Stability(Stable) public void addError(@NotNull String message)
      Adds an { "error": } metadata entry to this construct.

      The toolkit will fail deployment of any stack that has errors reported against it.

      Parameters:
      message - The error message. This parameter is required.
    • addInfo

      @Stability(Stable) public void addInfo(@NotNull String message)
      Adds an info metadata entry to this construct.

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

      Parameters:
      message - The info message. This parameter is required.
    • addWarning

      @Stability(Stable) public void addWarning(@NotNull String message)
      Adds a warning metadata entry to this construct. Prefer using addWarningV2.

      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. This parameter is required.
    • addWarningV2

      @Stability(Stable) public void addWarningV2(@NotNull String id, @NotNull String message)
      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.

      Example:

       Construct myConstruct;
       Annotations.of(myConstruct).addWarningV2("my-library:Construct.someWarning", "Some message explaining the warning");
       

      Parameters:
      id - the unique identifier for the warning. This parameter is required.
      message - The warning message. This parameter is required.