Skip to content

Commit a35fcc5

Browse files
authored
chore(lambda): update default node runtime for all partitions (#26475)
Node18 is the default runtime environment for lambdas in the [default](https://aws.amazon.com/it/blogs/compute/node-js-18-x-runtime-now-available-in-aws-lambda/), [China](https://www.amazonaws.cn/en/new/2023/amazon-lambda-adds-support-for-node-js-18-in-amazon-web-services-china-regions/), and [GovCloud](https://aws.amazon.com/it/about-aws/whats-new/2023/04/aws-lambda-node-js-18-govcloud-regions/) regions. This fix updates the runtime default versions for constructs that were still using older versions, in particular: - `LogRetention` - `AwsCustomResource` - `CustomResourceProvider` Also, it updates the `DefaultCrNodeVersionMap` in the fact tables to reflect the updated values. Closes #26461. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 54e64c7 commit a35fcc5

File tree

6 files changed

+19
-18
lines changed

6 files changed

+19
-18
lines changed

packages/aws-cdk-lib/aws-logs/lib/log-retention.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as iam from '../../aws-iam';
55
import * as s3_assets from '../../aws-s3-assets';
66
import * as cdk from '../../core';
77
import { ArnFormat } from '../../core';
8+
import { FactName } from '../../region-info';
89

910
/**
1011
* Construction properties for a LogRetention.
@@ -170,7 +171,7 @@ class LogRetentionFunction extends Construct implements cdk.ITaggable {
170171
type: 'AWS::Lambda::Function',
171172
properties: {
172173
Handler: 'index.handler',
173-
Runtime: 'nodejs18.x', // cannot use Runtime class here to prevent circular dependency
174+
Runtime: cdk.Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs18.x'), // Equivalent to Runtime.NODEJS_18_X
174175
Code: {
175176
S3Bucket: asset.s3BucketName,
176177
S3Key: asset.s3ObjectKey,

packages/aws-cdk-lib/core/lib/custom-resource-provider/custom-resource-provider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export const INLINE_CUSTOM_RESOURCE_CONTEXT = '@aws-cdk/core:inlineCustomResourc
2323
* based on region.
2424
*/
2525
export function builtInCustomResourceProviderNodeRuntime(scope: Construct): CustomResourceProviderRuntime {
26-
const runtimeName = Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs16.x');
27-
return Object.values(CustomResourceProviderRuntime).find(value => value === runtimeName) ?? CustomResourceProviderRuntime.NODEJS_16_X;
26+
const runtimeName = Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs18.x');
27+
return Object.values(CustomResourceProviderRuntime).find(value => value === runtimeName) ?? CustomResourceProviderRuntime.NODEJS_18_X;
2828
}
2929

3030
/**

packages/aws-cdk-lib/core/test/custom-resource-provider/custom-resource-provider.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -458,20 +458,20 @@ describe('custom resource provider', () => {
458458

459459
});
460460
describe('builtInCustomResourceProviderNodeRuntime', () => {
461-
test('returns node16 for commercial region', () => {
461+
test('returns node18 for commercial region', () => {
462462
const app = new App();
463463
const stack = new Stack(app, 'MyStack', { env: { region: 'us-east-1' } });
464464

465465
const rt = builtInCustomResourceProviderNodeRuntime(stack);
466-
expect(rt).toEqual(CustomResourceProviderRuntime.NODEJS_16_X);
466+
expect(rt).toEqual(CustomResourceProviderRuntime.NODEJS_18_X);
467467
});
468468

469-
test('returns node14 for iso region', () => {
469+
test('returns node18 for iso region', () => {
470470
const app = new App();
471471
const stack = new Stack(app, 'MyStack', { env: { region: 'us-iso-east-1' } });
472472

473473
const rt = builtInCustomResourceProviderNodeRuntime(stack);
474-
expect(rt).toEqual(CustomResourceProviderRuntime.NODEJS_14_X);
474+
expect(rt).toEqual(CustomResourceProviderRuntime.NODEJS_18_X);
475475
});
476476
});
477477
});

packages/aws-cdk-lib/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import { FactName } from '../../../region-info';
1818
export function builtInCustomResourceNodeRuntime(scope: Construct): lambda.Runtime {
1919
// Runtime regional fact should always return a known runtime string that lambda.Runtime
2020
// can index off, but for type safety we also default it here.
21-
const runtimeName = cdk.Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs16.x');
21+
const runtimeName = cdk.Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs18.x');
2222
return runtimeName
2323
? new lambda.Runtime(runtimeName, lambda.RuntimeFamily.NODEJS, { supportsInlineCode: true })
24-
: lambda.Runtime.NODEJS_16_X;
24+
: lambda.Runtime.NODEJS_18_X;
2525
}
2626

2727
/**

packages/aws-cdk-lib/custom-resources/test/aws-custom-resource/aws-custom-resource.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1282,20 +1282,20 @@ test('can specify removal policy', () => {
12821282
});
12831283

12841284
describe('builtInCustomResourceNodeRuntime', () => {
1285-
test('returns node16 for commercial region', () => {
1285+
test('returns node18 for commercial region', () => {
12861286
const app = new App();
12871287
const stack = new Stack(app, 'MyStack', { env: { region: 'us-east-1' } });
12881288

12891289
const rt = builtInCustomResourceNodeRuntime(stack);
1290-
expect(rt).toEqual(lambda.Runtime.NODEJS_16_X);
1290+
expect(rt).toEqual(lambda.Runtime.NODEJS_18_X);
12911291
});
12921292

1293-
test('returns node14 for iso region', () => {
1293+
test('returns node18 for iso region', () => {
12941294
const app = new App();
12951295
const stack = new Stack(app, 'MyStack', { env: { region: 'us-iso-east-1' } });
12961296

12971297
const rt = builtInCustomResourceNodeRuntime(stack);
1298-
expect(rt).toEqual(lambda.Runtime.NODEJS_14_X);
1298+
expect(rt).toEqual(lambda.Runtime.NODEJS_18_X);
12991299
});
13001300
});
13011301

packages/aws-cdk-lib/region-info/build-tools/fact-tables.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ export const PARTITION_MAP: { [region: string]: Region } = {
123123
};
124124

125125
export const CR_DEFAULT_RUNTIME_MAP: Record<Partition, string> = {
126-
[Partition.Default]: 'nodejs16.x',
127-
[Partition.Cn]: 'nodejs16.x',
128-
[Partition.UsGov]: 'nodejs16.x',
129-
[Partition.UsIso]: 'nodejs14.x',
130-
[Partition.UsIsoB]: 'nodejs14.x',
126+
[Partition.Default]: 'nodejs18.x',
127+
[Partition.Cn]: 'nodejs18.x',
128+
[Partition.UsGov]: 'nodejs18.x',
129+
[Partition.UsIso]: 'nodejs18.x',
130+
[Partition.UsIsoB]: 'nodejs18.x',
131131
};
132132

133133
// https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#access-logging-bucket-permissions

0 commit comments

Comments
 (0)