Skip to content

Latest commit

 

History

History
235 lines (149 loc) · 7.35 KB

API.md

File metadata and controls

235 lines (149 loc) · 7.35 KB

NPM version PyPI version Release

cdk-slack-chatbot

A CDK construct which creates an SNS AWS ChatBot (Slack) integration for CloudWatch alarms, AWS Config rules, ...
More information on how to use this construct can be found here.

Architecture

Screen Shot 2022-10-19 at 16 54 43

Example

In this example we create a CloudWatch alarm which integrates with our construct.

import * as cdk from 'aws-cdk-lib';
import * as cloudwatch from 'aws-cdk-lib/aws-cloudwatch';
import * as cloudwatch_actions from 'aws-cdk-lib/aws-cloudwatch-actions';
import * as sqs from 'aws-cdk-lib/aws-sqs';
import { CdkSlackChatBot } from 'cdk-slack-chatbot';

export class CdkDemoStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const queue = new sqs.Queue(this, 'HelloCdkQueue', {
      visibilityTimeout: cdk.Duration.seconds(300)
    });

    const qMetric = queue.metric('ApproximateNumberOfMessagesVisible');

    const alarm = new cloudwatch.Alarm(this, 'Alarm', {
      metric: qMetric,
      threshold: 100,
      evaluationPeriods: 3,
      datapointsToAlarm: 2
    });

    const slackIntegration = new CdkSlackChatBot(this, 'SlackIntegration', {
      topicName: 'slack-alarm',
      slackChannelId: 'xxx',
      slackWorkSpaceId: 'yyy',
      slackChannelConfigName: 'slack',
    });

    alarm.addAlarmAction(new cloudwatch_actions.SnsAction(slackIntegration.topic));
  }
}

Test Alarm:

$ aws cloudwatch set-alarm-state --alarm-name "xxx" --state-value ALARM --state-reason "testing purposes"

API Reference

Constructs

CdkSlackChatBot

Initializers

import { CdkSlackChatBot } from 'cdk-slack-chatbot'

new CdkSlackChatBot(scope: Construct, id: string, props: CdkSlackChatBotProps)
Name Type Description
scope constructs.Construct No description.
id string No description.
props CdkSlackChatBotProps No description.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsRequired

Methods

Name Description
toString Returns a string representation of this construct.

toString
public toString(): string

Returns a string representation of this construct.

Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
import { CdkSlackChatBot } from 'cdk-slack-chatbot'

CdkSlackChatBot.isConstruct(x: any)

Checks if x is a construct.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.
topic aws-cdk-lib.aws_sns.Topic No description.

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

The tree node.


topicRequired
public readonly topic: Topic;
  • Type: aws-cdk-lib.aws_sns.Topic

Structs

CdkSlackChatBotProps

Initializer

import { CdkSlackChatBotProps } from 'cdk-slack-chatbot'

const cdkSlackChatBotProps: CdkSlackChatBotProps = { ... }

Properties

Name Type Description
slackChannelConfigName string No description.
slackChannelId string No description.
slackWorkSpaceId string No description.
topicName string No description.

slackChannelConfigNameRequired
public readonly slackChannelConfigName: string;
  • Type: string

slackChannelIdRequired
public readonly slackChannelId: string;
  • Type: string

slackWorkSpaceIdRequired
public readonly slackWorkSpaceId: string;
  • Type: string

topicNameRequired
public readonly topicName: string;
  • Type: string