in src/lambda.ts [48:95]
constructor(scope: Construct, id: string, props: WatchLambdaFunctionProps) {
super(scope, id);
const cfnFunction = props.fn.node.defaultChild as lambda.CfnFunction;
const timeoutSec = cfnFunction.timeout || 3;
this.watchful = props.watchful;
this.fn = props.fn;
this.metrics = new LambdaMetricFactory();
this.watchful.addSection(props.title, {
links: [
{ title: 'AWS Lambda Console', url: linkForLambdaFunction(this.fn) },
{ title: 'CloudWatch Logs', url: linkForLambdaLogs(this.fn) },
],
});
const { errorsMetric, errorsAlarm } = this.createErrorsMonitor(props.errorsPerMinuteThreshold);
const { throttlesMetric, throttlesAlarm } = this.createThrottlesMonitor(props.throttlesPerMinuteThreshold);
const { durationMetric, durationAlarm } = this.createDurationMonitor(timeoutSec, props.durationThresholdPercent);
const invocationsMetric = this.metrics.metricInvocations(this.fn.functionName);
this.watchful.addWidgets(
new cloudwatch.GraphWidget({
title: `Invocations/${invocationsMetric.period.toMinutes()}min`,
width: 6,
left: [invocationsMetric],
}),
new cloudwatch.GraphWidget({
title: `Errors/${errorsMetric.period.toMinutes()}min`,
width: 6,
left: [errorsMetric],
leftAnnotations: [errorsAlarm.toAnnotation()],
}),
new cloudwatch.GraphWidget({
title: `Throttles/${throttlesMetric.period.toMinutes()}min`,
width: 6,
left: [throttlesMetric],
leftAnnotations: [throttlesAlarm.toAnnotation()],
}),
new cloudwatch.GraphWidget({
title: `Duration/${durationMetric.period.toMinutes()}min`,
width: 6,
left: [durationMetric],
leftAnnotations: [durationAlarm.toAnnotation()],
}),
);
}