Created
December 19, 2022 20:46
-
-
Save shotty1/0aed90b20b1217a6b0ae43bb00f41b88 to your computer and use it in GitHub Desktop.
Use visitor pattern to create an alarm for every lambda with cdk-monitoring-constructs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { IAspect } from "aws-cdk-lib"; | |
import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs"; | |
import { MonitoringFacade } from "cdk-monitoring-constructs"; | |
import { IConstruct } from "constructs"; | |
export class LambdaAlarms implements IAspect { | |
monitoringFacade: MonitoringFacade; | |
constructor(monitoringFacade: MonitoringFacade) { | |
this.monitoringFacade = monitoringFacade | |
} | |
visit(node: IConstruct): void { | |
if (node instanceof NodejsFunction) { | |
this.monitoringFacade.monitorLambdaFunction({ | |
lambdaFunction: node, | |
addFaultCountAlarm: { | |
Critical: { | |
maxErrorCount: 0 | |
} | |
} | |
}) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment