Skip to content

Commit 5fc6b09

Browse files
authored
fix(nodejs): no more nodejs18.x [INFRA-33946] (#122)
1 parent c4e38dc commit 5fc6b09

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

src/aurora.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ export class Aurora extends Construct {
396396
if (props.activityStream) {
397397
function activityStreamHandler(handler: string): aws_lambda_nodejs.NodejsFunction {
398398
const fn = new aws_lambda_nodejs.NodejsFunction(myConstruct, `ActivityStream${handler}`, {
399-
runtime: aws_lambda.Runtime.NODEJS_LATEST,
399+
runtime: aws_lambda.determineLatestNodeRuntime(myConstruct),
400400
bundling: {
401401
externalModules: ['@aws-sdk/client-secrets-manager', '@aws-sdk/client-rds'],
402402
},
@@ -450,7 +450,7 @@ export class Aurora extends Construct {
450450
}
451451

452452
const provisionerProps: aws_lambda_nodejs.NodejsFunctionProps = {
453-
runtime: aws_lambda.Runtime.NODEJS_LATEST,
453+
runtime: aws_lambda.determineLatestNodeRuntime(this),
454454
bundling: {
455455
externalModules: ['@aws-sdk/client-secrets-manager', '@aws-sdk/client-rds'],
456456
nodeModules: ['pg', 'pg-format'],

test/aurora.test.ts

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ import { Namer } from 'multi-convention-namer';
2323

2424
import { 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+
2639
const databaseName = 'fakeDbName';
2740

2841
let 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(/^nodejs(\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

Comments
 (0)