@@ -23,6 +23,19 @@ import { Namer } from 'multi-convention-namer';
2323
2424import { Aurora , AuroraProps } from '../src' ;
2525
26+ // Define the shape of Lambda function properties we care about
27+ interface LambdaFunctionCfnProperties {
28+ Runtime : string ;
29+ [ key : string ] : any ;
30+ }
31+
32+ interface LambdaFunctionCfn {
33+ Properties : LambdaFunctionCfnProperties ;
34+ [ key : string ] : any ;
35+ }
36+
37+ const MINIMUM_NODEJS_MAJOR_VERSION = 20 ;
38+
2639const databaseName = 'fakeDbName' ;
2740
2841let app : App ;
@@ -47,7 +60,7 @@ describe('Aurora', () => {
4760 describe ( 'default' , ( ) => {
4861 beforeAll ( ( ) => {
4962 app = new App ( ) ;
50- stack = new Stack ( app , 'test' ) ;
63+ stack = new Stack ( app , 'test' , { env : { region : 'us-west-2' } } ) ; // We're using determineLatestNodeRuntime() which is region aware.
5164 kmsKey = new Key ( stack , 'Key' ) ;
5265 vpc = new Vpc ( stack , 'TestVpc' , {
5366 subnetConfiguration : [
@@ -65,7 +78,12 @@ describe('Aurora', () => {
6578 } ,
6679 ] ,
6780 } ) ;
68- defaultAuroraProps = { databaseName, kmsKey, vpc } ;
81+ defaultAuroraProps = {
82+ activityStream : true , // this will cause additional lambdas to be deployed, and we want to test them.
83+ databaseName,
84+ kmsKey,
85+ vpc,
86+ } ;
6987 createAurora ( ) ;
7088 } ) ;
7189 it ( 'creates resources' , ( ) => {
@@ -74,7 +92,7 @@ describe('Aurora', () => {
7492 [ 'AWS::SecretsManager::RotationSchedule' , 'AWS::SecretsManager::Secret' ] . forEach ( ( r ) =>
7593 template . resourceCountIs ( r , 3 ) ,
7694 ) ;
77- template . resourceCountIs ( 'AWS::Lambda::Function' , 5 ) ;
95+ template . resourceCountIs ( 'AWS::Lambda::Function' , 10 ) ;
7896 } ) ;
7997 describe ( 'cloudwatch logs' , ( ) => {
8098 it ( 'exports' , ( ) => {
@@ -96,6 +114,25 @@ describe('Aurora', () => {
96114 } ) ;
97115 template . hasResourceProperties ( 'Custom::AuroraDatabase' , { databaseName } ) ;
98116 } ) ;
117+
118+ it ( 'nodejs lambda runtime minimum version is >= 20' , ( ) => {
119+ const lambdaResources = template . findResources ( 'AWS::Lambda::Function' ) as { [ key : string ] : LambdaFunctionCfn } ;
120+ const nodeLambdasProperties = Object . entries ( lambdaResources ) . map ( ( [ key , value ] ) => {
121+ return {
122+ ...value . Properties ,
123+ key,
124+ } ;
125+ } ) ;
126+
127+ nodeLambdasProperties . forEach ( ( p ) => {
128+ const nodejsMatch = p . Runtime . match ( / ^ n o d e j s ( \d + ) \. x $ / ) ;
129+ if ( nodejsMatch ) {
130+ const version = parseInt ( nodejsMatch [ 1 ] , 10 ) ;
131+ expect ( version ) . toBeGreaterThanOrEqual ( MINIMUM_NODEJS_MAJOR_VERSION ) ;
132+ }
133+ } ) ;
134+ } ) ;
135+
99136 it ( 'performanceInsights' , ( ) => {
100137 template . hasResourceProperties ( 'AWS::RDS::DBInstance' , {
101138 PerformanceInsightsKMSKeyId : { 'Fn::GetAtt' : [ stack . getLogicalId ( kmsKey . node . defaultChild as CfnKey ) , 'Arn' ] } ,
@@ -141,18 +178,7 @@ describe('Aurora', () => {
141178 'kms:CallerAccount' : {
142179 Ref : 'AWS::AccountId' ,
143180 } ,
144- 'kms:ViaService' : {
145- 'Fn::Join' : [
146- '' ,
147- [
148- 'secretsmanager.' ,
149- {
150- Ref : 'AWS::Region' ,
151- } ,
152- '.amazonaws.com' ,
153- ] ,
154- ] ,
155- } ,
181+ 'kms:ViaService' : 'secretsmanager.us-west-2.amazonaws.com' ,
156182 } ,
157183 } ,
158184 Effect : 'Allow' ,
@@ -185,7 +211,7 @@ describe('Aurora', () => {
185211 describe ( 'options' , ( ) => {
186212 beforeEach ( ( ) => {
187213 app = new App ( ) ;
188- stack = new Stack ( app , 'test' ) ;
214+ stack = new Stack ( app , 'test' , { env : { region : 'us-west-2' } } ) ; // We're using determineLatestNodeRuntime() which is region aware.
189215 kmsKey = new Key ( stack , 'Key' ) ;
190216 vpc = new Vpc ( stack , 'TestVpc' , {
191217 subnetConfiguration : [
0 commit comments