@@ -23,6 +23,19 @@ import { Namer } from 'multi-convention-namer';
23
23
24
24
import { Aurora , AuroraProps } from '../src' ;
25
25
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
+
26
39
const databaseName = 'fakeDbName' ;
27
40
28
41
let app : App ;
@@ -47,7 +60,7 @@ describe('Aurora', () => {
47
60
describe ( 'default' , ( ) => {
48
61
beforeAll ( ( ) => {
49
62
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.
51
64
kmsKey = new Key ( stack , 'Key' ) ;
52
65
vpc = new Vpc ( stack , 'TestVpc' , {
53
66
subnetConfiguration : [
@@ -65,7 +78,12 @@ describe('Aurora', () => {
65
78
} ,
66
79
] ,
67
80
} ) ;
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
+ } ;
69
87
createAurora ( ) ;
70
88
} ) ;
71
89
it ( 'creates resources' , ( ) => {
@@ -74,7 +92,7 @@ describe('Aurora', () => {
74
92
[ 'AWS::SecretsManager::RotationSchedule' , 'AWS::SecretsManager::Secret' ] . forEach ( ( r ) =>
75
93
template . resourceCountIs ( r , 3 ) ,
76
94
) ;
77
- template . resourceCountIs ( 'AWS::Lambda::Function' , 5 ) ;
95
+ template . resourceCountIs ( 'AWS::Lambda::Function' , 10 ) ;
78
96
} ) ;
79
97
describe ( 'cloudwatch logs' , ( ) => {
80
98
it ( 'exports' , ( ) => {
@@ -96,6 +114,25 @@ describe('Aurora', () => {
96
114
} ) ;
97
115
template . hasResourceProperties ( 'Custom::AuroraDatabase' , { databaseName } ) ;
98
116
} ) ;
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
+
99
136
it ( 'performanceInsights' , ( ) => {
100
137
template . hasResourceProperties ( 'AWS::RDS::DBInstance' , {
101
138
PerformanceInsightsKMSKeyId : { 'Fn::GetAtt' : [ stack . getLogicalId ( kmsKey . node . defaultChild as CfnKey ) , 'Arn' ] } ,
@@ -141,18 +178,7 @@ describe('Aurora', () => {
141
178
'kms:CallerAccount' : {
142
179
Ref : 'AWS::AccountId' ,
143
180
} ,
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' ,
156
182
} ,
157
183
} ,
158
184
Effect : 'Allow' ,
@@ -185,7 +211,7 @@ describe('Aurora', () => {
185
211
describe ( 'options' , ( ) => {
186
212
beforeEach ( ( ) => {
187
213
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.
189
215
kmsKey = new Key ( stack , 'Key' ) ;
190
216
vpc = new Vpc ( stack , 'TestVpc' , {
191
217
subnetConfiguration : [
0 commit comments