Table of Contents

Class Annotations

Namespace
Amazon.CDK
Assembly
Amazon.CDK.dll

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

public class Annotations : DeputyBase
Inheritance
Annotations

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());
                }
            }

Remarks

ExampleMetadata: nofixture infused

Methods

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.

AddWarning(string)

Adds a warning metadata entry to this construct.

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.

Of(IConstruct)

Returns the annotations API for a construct scope.

public static Annotations Of(IConstruct scope)

Parameters

scope IConstruct

The scope.

Returns

Annotations