Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CloudWatch notifications and SNS subscriptions #695

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cdk/lib/app-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import type { Construct } from "constructs";
import * as ecs from "aws-cdk-lib/aws-ecs";
import * as ecsPatterns from "aws-cdk-lib/aws-ecs-patterns";
import * as ecrAssets from "aws-cdk-lib/aws-ecr-assets";
import * as cloudwatch from "aws-cdk-lib/aws-cloudwatch";
import * as logs from "aws-cdk-lib/aws-logs";
import * as ssm from "aws-cdk-lib/aws-ssm";
import * as sns from "aws-cdk-lib/aws-sns";
import * as iam from "aws-cdk-lib/aws-iam";
import * as snsSubscriptions from "aws-cdk-lib/aws-sns-subscriptions";

interface Props extends cdk.StackProps {
bucket: cdk.aws_s3.Bucket;
Expand Down Expand Up @@ -202,5 +205,29 @@ export class AppStack extends cdk.Stack {
);

this.loadbalancer = fargateService.loadBalancer;

// Cloudwatch notifications
const alarm = new cloudwatch.Alarm(this, "FargateServiceDownAlarm", {
alarmName: "FargateServiceDownAlarm",
alarmDescription: "Triggered when Fargate service is down",
metric: fargateService.service.metricCpuUtilization(),
threshold: 10,
evaluationPeriods: 1,
comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_THRESHOLD,
treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,
});

const snsTopic = new sns.Topic(this, "FargateServiceAlertTopic");
alarm.addAlarmAction(new cdk.aws_cloudwatch_actions.SnsAction(snsTopic));

snsTopic.addSubscription(
new snsSubscriptions.EmailSubscription(
ssm.StringParameter.fromStringParameterName(
this,
"alertEmail",
"/env/alertEmail",
).toString(),
),
);
}
}
16 changes: 0 additions & 16 deletions cdk/test/cdk-pipeline-codu.test.ts

This file was deleted.

Loading