Class Annotations
Includes API for attaching annotations such as warning messages to constructs.
Inheritance
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
Constructors
Annotations(ByRefValue) | Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Annotations(DeputyBase.DeputyProps) | Used by jsii to construct an instance of this class from DeputyProps |
Methods
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. |
AddWarning(String) | Adds a warning metadata entry to this construct. Prefer using |
AddWarningV2(String, String) | Adds an acknowledgeable warning metadata entry to this construct. |
Of(IConstruct) | Returns the annotations API for a construct scope. |
Constructors
Annotations(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected Annotations(ByRefValue reference)
Parameters
- reference Amazon.JSII.Runtime.Deputy.ByRefValue
The Javascript-owned object reference
Annotations(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected Annotations(DeputyBase.DeputyProps props)
Parameters
- props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps
The deputy props
Methods
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 System.String
- the id of the warning message to acknowledge.
- message System.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 System.String
The API being deprecated in the format
module.Class.property
(e.g.@aws-cdk/core.Construct.node
).- message System.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 System.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 System.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. Prefer using addWarningV2
.
public virtual void AddWarning(string message)
Parameters
- message System.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 System.String
the unique identifier for the warning.
- message System.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 Constructs.IConstruct
The scope.
Returns