Skip to content

Latest commit

 

History

History
452 lines (272 loc) · 14.7 KB

API.md

File metadata and controls

452 lines (272 loc) · 14.7 KB

Constructs for AWS CDK

Usage

Add @elisasre/cdk-constructs as a dependency of your CDK project and import the desired construct.

Alarm with tags

Alarm with tags extends the standard CDK alarm construct by allowing tagging of alarms, which Cloudformation does not currently support out of the box.

Creating a tagged alarm

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');

Tagging an existing alarm

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');

API reference

API Reference

Constructs

AlarmWithTags

Initializers

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.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsRequired
  • Type: aws-cdk-lib.aws_cloudwatch.AlarmProps

Methods

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.

toString
public toString(): string

Returns a string representation of this construct.

applyRemovalPolicy
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).

policyRequired
  • Type: aws-cdk-lib.RemovalPolicy

addAlarmAction
public addAlarmAction(actions: IAlarmAction): void

Trigger this action if the alarm fires.

Typically SnsAcion or AutoScalingAction.

actionsRequired
  • Type: aws-cdk-lib.aws_cloudwatch.IAlarmAction

addInsufficientDataAction
public addInsufficientDataAction(actions: IAlarmAction): void

Trigger this action if there is insufficient data to evaluate the alarm.

Typically SnsAction or AutoScalingAction.

actionsRequired
  • Type: aws-cdk-lib.aws_cloudwatch.IAlarmAction

addOkAction
public addOkAction(actions: IAlarmAction): void

Trigger this action if the alarm returns from breaching state into ok state.

Typically SnsAction or AutoScalingAction.

actionsRequired
  • Type: aws-cdk-lib.aws_cloudwatch.IAlarmAction

renderAlarmRule
public renderAlarmRule(): string

AlarmRule indicating ALARM state for Alarm.

toAnnotation
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.

Static Functions

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.

isConstruct
import { AlarmWithTags } from '@elisasre/cdk-constructs'

AlarmWithTags.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


isOwnedResource
import { AlarmWithTags } from '@elisasre/cdk-constructs'

AlarmWithTags.isOwnedResource(construct: IConstruct)

Returns true if the construct was created by CDK, and false otherwise.

constructRequired
  • Type: constructs.IConstruct

isResource
import { AlarmWithTags } from '@elisasre/cdk-constructs'

AlarmWithTags.isResource(construct: IConstruct)

Check whether the given construct is a Resource.

constructRequired
  • Type: constructs.IConstruct

fromAlarmArn
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.

scopeRequired
  • Type: constructs.Construct

The parent creating construct (usually this).


idRequired
  • Type: string

The construct's name.


alarmArnRequired
  • Type: string

Alarm ARN (i.e. arn:aws:cloudwatch:::alarm:Foo).


fromAlarmName
import { AlarmWithTags } from '@elisasre/cdk-constructs'

AlarmWithTags.fromAlarmName(scope: Construct, id: string, alarmName: string)

Import an existing CloudWatch alarm provided an Name.

scopeRequired
  • Type: constructs.Construct

The parent creating construct (usually this).


idRequired
  • Type: string

The construct's name.


alarmNameRequired
  • Type: string

Alarm Name.


Properties

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.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


envRequired
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.


stackRequired
public readonly stack: Stack;
  • Type: aws-cdk-lib.Stack

The stack in which this resource is defined.


alarmArnRequired
public readonly alarmArn: string;
  • Type: string

ARN of this alarm.


alarmNameRequired
public readonly alarmName: string;
  • Type: string

Name of this alarm.


metricRequired
public readonly metric: IMetric;
  • Type: aws-cdk-lib.aws_cloudwatch.IMetric

The metric object this alarm was based on.


tagsRequired
public readonly tags: TagManager;
  • Type: aws-cdk-lib.TagManager