Add @elisasre/cdk-constructs as a dependency of your CDK project and import the desired construct.
Alarm with tags extends the standard CDK alarm construct by allowing tagging of alarms, which Cloudformation does not currently support out of the box.
declare const fn: lambda.Function;
const minuteErrorRate = fn.metricErrors({
statistic: cloudwatch.Stats.AVERAGE,
period: Duration.minutes(1),
label: 'Lambda failure rate'
});
const alarm = new AlarmWithTags(this, 'myalarm', {
evaluationPeriods: 3,
metric: minuteErrorRate,
threshold: 1,
comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
});
Tags.of(alarm).add('foo', 'bar');
declare const fn: lambda.Function;
const minuteErrorRate = fn.metricErrors({
statistic: cloudwatch.Stats.AVERAGE,
period: Duration.minutes(1),
label: 'Lambda failure rate'
});
const alarm = minuteErrorRate.createAlarm(this, 'myalarm', {
evaluationPeriods: 3,
threshold: 1,
comparisonOperator: cloudwatch.ComparisonOperator.GREATER_THAN_THRESHOLD,
});
const myTaggedAlarm = AlarmWithTags.fromArn(this, 'myalarmwithtags', alarm.alarmArn);
Tags.of(myTaggedAlarm).add('foo', 'bar');
import { AlarmWithTags } from '@elisasre/cdk-constructs'
new AlarmWithTags(scope: Construct, id: string, props: AlarmProps)
Name | Type | Description |
---|---|---|
scope |
constructs.Construct |
No description. |
id |
string |
No description. |
props |
aws-cdk-lib.aws_cloudwatch.AlarmProps |
No description. |
- Type: constructs.Construct
- Type: string
- Type: aws-cdk-lib.aws_cloudwatch.AlarmProps
Name | Description |
---|---|
toString |
Returns a string representation of this construct. |
applyRemovalPolicy |
Apply the given removal policy to this resource. |
addAlarmAction |
Trigger this action if the alarm fires. |
addInsufficientDataAction |
Trigger this action if there is insufficient data to evaluate the alarm. |
addOkAction |
Trigger this action if the alarm returns from breaching state into ok state. |
renderAlarmRule |
AlarmRule indicating ALARM state for Alarm. |
toAnnotation |
Turn this alarm into a horizontal annotation. |
public toString(): string
Returns a string representation of this construct.
public applyRemovalPolicy(policy: RemovalPolicy): void
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
- Type: aws-cdk-lib.RemovalPolicy
public addAlarmAction(actions: IAlarmAction): void
Trigger this action if the alarm fires.
Typically SnsAcion or AutoScalingAction.
- Type: aws-cdk-lib.aws_cloudwatch.IAlarmAction
public addInsufficientDataAction(actions: IAlarmAction): void
Trigger this action if there is insufficient data to evaluate the alarm.
Typically SnsAction or AutoScalingAction.
- Type: aws-cdk-lib.aws_cloudwatch.IAlarmAction
public addOkAction(actions: IAlarmAction): void
Trigger this action if the alarm returns from breaching state into ok state.
Typically SnsAction or AutoScalingAction.
- Type: aws-cdk-lib.aws_cloudwatch.IAlarmAction
public renderAlarmRule(): string
AlarmRule indicating ALARM state for Alarm.
public toAnnotation(): HorizontalAnnotation
Turn this alarm into a horizontal annotation.
This is useful if you want to represent an Alarm in a non-AlarmWidget.
An AlarmWidget
can directly show an alarm, but it can only show a
single alarm and no other metrics. Instead, you can convert the alarm to
a HorizontalAnnotation and add it as an annotation to another graph.
This might be useful if:
-
You want to show multiple alarms inside a single graph, for example if you have both a "small margin/long period" alarm as well as a "large margin/short period" alarm.
-
You want to show an Alarm line in a graph with multiple metrics in it.
Name | Description |
---|---|
isConstruct |
Checks if x is a construct. |
isOwnedResource |
Returns true if the construct was created by CDK, and false otherwise. |
isResource |
Check whether the given construct is a Resource. |
fromAlarmArn |
Import an existing CloudWatch alarm provided an ARN. |
fromAlarmName |
Import an existing CloudWatch alarm provided an Name. |
import { AlarmWithTags } from '@elisasre/cdk-constructs'
AlarmWithTags.isConstruct(x: any)
Checks if x
is a construct.
- Type: any
Any object.
import { AlarmWithTags } from '@elisasre/cdk-constructs'
AlarmWithTags.isOwnedResource(construct: IConstruct)
Returns true if the construct was created by CDK, and false otherwise.
- Type: constructs.IConstruct
import { AlarmWithTags } from '@elisasre/cdk-constructs'
AlarmWithTags.isResource(construct: IConstruct)
Check whether the given construct is a Resource.
- Type: constructs.IConstruct
import { AlarmWithTags } from '@elisasre/cdk-constructs'
AlarmWithTags.fromAlarmArn(scope: Construct, id: string, alarmArn: string)
Import an existing CloudWatch alarm provided an ARN.
Imported alarms can be tagged, but not modified.
- Type: constructs.Construct
The parent creating construct (usually this
).
- Type: string
The construct's name.
- Type: string
Alarm ARN (i.e. arn:aws:cloudwatch:::alarm:Foo).
import { AlarmWithTags } from '@elisasre/cdk-constructs'
AlarmWithTags.fromAlarmName(scope: Construct, id: string, alarmName: string)
Import an existing CloudWatch alarm provided an Name.
- Type: constructs.Construct
The parent creating construct (usually this
).
- Type: string
The construct's name.
- Type: string
Alarm Name.
Name | Type | Description |
---|---|---|
node |
constructs.Node |
The tree node. |
env |
aws-cdk-lib.ResourceEnvironment |
The environment this resource belongs to. |
stack |
aws-cdk-lib.Stack |
The stack in which this resource is defined. |
alarmArn |
string |
ARN of this alarm. |
alarmName |
string |
Name of this alarm. |
metric |
aws-cdk-lib.aws_cloudwatch.IMetric |
The metric object this alarm was based on. |
tags |
aws-cdk-lib.TagManager |
No description. |
public readonly node: Node;
- Type: constructs.Node
The tree node.
public readonly env: ResourceEnvironment;
- Type: aws-cdk-lib.ResourceEnvironment
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
public readonly stack: Stack;
- Type: aws-cdk-lib.Stack
The stack in which this resource is defined.
public readonly alarmArn: string;
- Type: string
ARN of this alarm.
public readonly alarmName: string;
- Type: string
Name of this alarm.
public readonly metric: IMetric;
- Type: aws-cdk-lib.aws_cloudwatch.IMetric
The metric object this alarm was based on.
public readonly tags: TagManager;
- Type: aws-cdk-lib.TagManager