@@ -12,7 +12,7 @@ import { AlarmWithAnnotation, LambdaFunctionMonitoring } from "../../../lib";
1212import { addMonitoringDashboardsToStack } from "../../utils/SnapshotUtil" ;
1313import { TestMonitoringScope } from "../TestMonitoringScope" ;
1414
15- test ( "snapshot test: no alarms" , ( ) => {
15+ test ( "snapshot test: default iterator and no alarms" , ( ) => {
1616 const stack = new Stack ( ) ;
1717
1818 const scope = new TestMonitoringScope ( stack , "Scope" ) ;
@@ -24,14 +24,14 @@ test("snapshot test: no alarms", () => {
2424 handler : "Dummy::handler" ,
2525 } ) ;
2626
27- new LambdaFunctionMonitoring ( scope , {
27+ const monitoring = new LambdaFunctionMonitoring ( scope , {
2828 lambdaFunction,
2929 humanReadableName : "Dummy Lambda for testing" ,
3030 alarmFriendlyName : "DummyLambda" ,
3131 } ) ;
32+ addMonitoringDashboardsToStack ( stack , monitoring ) ;
3233
3334 // alternative: use reference
34-
3535 new LambdaFunctionMonitoring ( scope , {
3636 lambdaFunction : Function . fromFunctionAttributes ( stack , "DummyFunctionRef" , {
3737 functionArn :
@@ -42,6 +42,29 @@ test("snapshot test: no alarms", () => {
4242 expect ( Template . fromStack ( stack ) ) . toMatchSnapshot ( ) ;
4343} ) ;
4444
45+ test ( "snapshot test: non-iterator and no alarms" , ( ) => {
46+ const stack = new Stack ( ) ;
47+
48+ const scope = new TestMonitoringScope ( stack , "Scope" ) ;
49+
50+ const lambdaFunction = new Function ( stack , "Function" , {
51+ functionName : "DummyLambda" ,
52+ runtime : Runtime . NODEJS_18_X ,
53+ code : InlineCode . fromInline ( "{}" ) ,
54+ handler : "Dummy::handler" ,
55+ } ) ;
56+
57+ const monitoring = new LambdaFunctionMonitoring ( scope , {
58+ lambdaFunction,
59+ humanReadableName : "Dummy Lambda for testing" ,
60+ alarmFriendlyName : "DummyLambda" ,
61+ isIterator : false ,
62+ } ) ;
63+
64+ addMonitoringDashboardsToStack ( stack , monitoring ) ;
65+ expect ( Template . fromStack ( stack ) ) . toMatchSnapshot ( ) ;
66+ } ) ;
67+
4568test ( "snapshot test: all alarms" , ( ) => {
4669 const stack = new Stack ( ) ;
4770
@@ -483,6 +506,36 @@ test("snapshot test: all alarms, alarmPrefix on latency dedupeString", () => {
483506 expect ( Template . fromStack ( stack ) ) . toMatchSnapshot ( ) ;
484507} ) ;
485508
509+ test ( "throws error if attempting to create iterator age alarm if not an iterator" , ( ) => {
510+ const stack = new Stack ( ) ;
511+
512+ const scope = new TestMonitoringScope ( stack , "Scope" ) ;
513+
514+ const lambdaFunction = new Function ( stack , "Function" , {
515+ functionName : "DummyLambda" ,
516+ runtime : Runtime . NODEJS_18_X ,
517+ code : InlineCode . fromInline ( "{}" ) ,
518+ handler : "Dummy::handler" ,
519+ } ) ;
520+
521+ expect (
522+ ( ) =>
523+ new LambdaFunctionMonitoring ( scope , {
524+ lambdaFunction,
525+ humanReadableName : "Dummy Lambda for testing" ,
526+ alarmFriendlyName : "DummyLambda" ,
527+ isIterator : false ,
528+ addMaxIteratorAgeAlarm : {
529+ Warning : {
530+ maxAgeInMillis : 1_000_000 ,
531+ } ,
532+ } ,
533+ } ) ,
534+ ) . toThrow (
535+ "addMaxIteratorAgeAlarm is not applicable if isIterator is not true" ,
536+ ) ;
537+ } ) ;
538+
486539test ( "doesn't create alarms for enhanced Lambda Insights metrics if not enabled" , ( ) => {
487540 const stack = new Stack ( ) ;
488541
0 commit comments