Show / Hide Table of Contents

Class Annotations

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

Inheritance
object
Annotations
Namespace: Amazon.CDK
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Annotations : DeputyBase
Syntax (vb)
Public Class Annotations Inherits DeputyBase
Remarks

ExampleMetadata: nofixture infused

Examples
using Amazon.CDK;
            using Constructs;

            class MyAspect : IAspect
            {
                public void Visit(IConstruct node)
                {
                    if (node instanceof CfnResource && node.CfnResourceType == "Foo::Bar")
                    {
                        Error(node, "we do not want a Foo::Bar resource");
                    }
                }

                protected void Error(IConstruct node, string message)
                {
                    Annotations.Of(node).AddError(message);
                }
            }

            class MyStack : Stack
            {
                public MyStack(Construct scope, string id) : base(scope, id)
                {

                    var stack = new Stack();
                    new CfnResource(stack, "Foo", new CfnResourceProps {
                        Type = "Foo::Bar",
                        Properties = new Dictionary<string, object> {
                            { "Fred", "Thud" }
                        }
                    });
                    Aspects.Of(stack).Add(new MyAspect());
                }
            }

Synopsis

Methods

AcknowledgeInfo(string, string?)

Acknowledge a info. When a info is acknowledged for a scope all infos that match the id will be ignored.

AcknowledgeWarning(string, string?)

Acknowledge a warning. When a warning is acknowledged for a scope all warnings that match the id will be ignored.

AddDeprecation(string, string)

Adds a deprecation warning for a specific API.

AddError(string)

Adds an { "error": <message> } metadata entry to this construct.

AddInfo(string)

Adds an info metadata entry to this construct.

AddInfoV2(string, string)

Adds an acknowledgeable info metadata entry to this construct.

AddWarning(string)

Adds a warning metadata entry to this construct. Prefer using addWarningV2.

AddWarningV2(string, string)

Adds an acknowledgeable warning metadata entry to this construct.

Of(IConstruct)

Returns the annotations API for a construct scope.

Methods

AcknowledgeInfo(string, string?)

Acknowledge a info. When a info is acknowledged for a scope all infos that match the id will be ignored.

public virtual void AcknowledgeInfo(string id, string? message = null)
Parameters
id string
  • the id of the info message to acknowledge.
message string

optional message to explain the reason for acknowledgement.

Remarks

The acknowledgement will apply to all child scopes

Examples
Construct myConstruct;

            Annotations.Of(myConstruct).AcknowledgeInfo("SomeInfoId", "This info can be ignored because...");

AcknowledgeWarning(string, string?)

Acknowledge a warning. When a warning is acknowledged for a scope all warnings that match the id will be ignored.

public virtual void AcknowledgeWarning(string id, string? message = null)
Parameters
id string
  • the id of the warning message to acknowledge.
message string

optional message to explain the reason for acknowledgement.

Remarks

The acknowledgement will apply to all child scopes

Examples
Construct myConstruct;

            Annotations.Of(myConstruct).AcknowledgeWarning("SomeWarningId", "This warning can be ignored because...");

AddDeprecation(string, string)

Adds a deprecation warning for a specific API.

public virtual void AddDeprecation(string api, string message)
Parameters
api string

The API being deprecated in the format module.Class.property (e.g. @aws-cdk/core.Construct.node).

message string

The deprecation message to display, with information about alternatives.

Remarks

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.

AddError(string)

Adds an { "error": <message> } metadata entry to this construct.

public virtual void AddError(string message)
Parameters
message string

The error message.

Remarks

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

AddInfo(string)

Adds an info metadata entry to this construct.

public virtual void AddInfo(string message)
Parameters
message string

The info message.

Remarks

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

AddInfoV2(string, string)

Adds an acknowledgeable info metadata entry to this construct.

public virtual void AddInfoV2(string id, string message)
Parameters
id string

the unique identifier for the info.

message string

The info message.

Remarks

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.

Examples
Construct myConstruct;

             Annotations.Of(myConstruct).AddInfoV2("my-library:Construct.someInfo", "Some message explaining the info");

AddWarning(string)

Adds a warning metadata entry to this construct. Prefer using addWarningV2.

public virtual void AddWarning(string message)
Parameters
message string

The warning message.

Remarks

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.

AddWarningV2(string, string)

Adds an acknowledgeable warning metadata entry to this construct.

public virtual void AddWarningV2(string id, string message)
Parameters
id string

the unique identifier for the warning.

message string

The warning message.

Remarks

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.

Examples
Construct myConstruct;

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

Of(IConstruct)

Returns the annotations API for a construct scope.

public static Annotations Of(IConstruct scope)
Parameters
scope IConstruct

The scope.

Returns

Annotations

Remarks

ExampleMetadata: nofixture infused

Back to top Generated by DocFX