-
Notifications
You must be signed in to change notification settings - Fork 1
/
alarmStack.ts
37 lines (30 loc) · 1.44 KB
/
alarmStack.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { CommonStackProps } from '../types'
import * as cdk from 'aws-cdk-lib'
import { Construct } from 'constructs'
import * as sns from 'aws-cdk-lib/aws-sns'
import * as lambda from 'aws-cdk-lib/aws-lambda'
import * as path from 'path'
import * as subscriptions from 'aws-cdk-lib/aws-sns-subscriptions'
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
export class AlarmStack extends cdk.Stack {
readonly alarmSnsTopic
constructor(scope: Construct, id: string, props: CommonStackProps) {
super(scope, id, props)
this.alarmSnsTopic = new sns.Topic(this, 'AlarmSnsTopic')
const slackWebhookUrlSecretName = `/${props.envNameCapitalized}LudosStack/LudosApplicationStack/SlackWebhookUrl`
const slackNotifierLambda = new lambda.Function(this, 'SlackNotifierLambda', {
runtime: lambda.Runtime.NODEJS_20_X,
handler: 'index.handler',
timeout: cdk.Duration.seconds(60),
code: lambda.Code.fromAsset(path.join(__dirname, 'lambdas/slackNotifierLambda')),
environment: {
SLACK_WEBHOOK_URL_SECRET_NAME: slackWebhookUrlSecretName
}
})
this.alarmSnsTopic.addSubscription(new subscriptions.LambdaSubscription(slackNotifierLambda))
this.alarmSnsTopic.addSubscription(new subscriptions.UrlSubscription(process.env['PAGERDUTY_ENDPOINT']!))
secretsmanager.Secret.fromSecretNameV2(this, 'SlackWebhookUrlSecret', slackWebhookUrlSecretName).grantRead(
slackNotifierLambda
)
}
}