Skip to content

Commit

Permalink
chore(lambda): update default node runtime for all partitions (#26475)
Browse files Browse the repository at this point in the history
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*
  • Loading branch information
lpizzinidev authored Aug 4, 2023
1 parent 54e64c7 commit a35fcc5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
3 changes: 2 additions & 1 deletion packages/aws-cdk-lib/aws-logs/lib/log-retention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as iam from '../../aws-iam';
import * as s3_assets from '../../aws-s3-assets';
import * as cdk from '../../core';
import { ArnFormat } from '../../core';
import { FactName } from '../../region-info';

/**
* Construction properties for a LogRetention.
Expand Down Expand Up @@ -170,7 +171,7 @@ class LogRetentionFunction extends Construct implements cdk.ITaggable {
type: 'AWS::Lambda::Function',
properties: {
Handler: 'index.handler',
Runtime: 'nodejs18.x', // cannot use Runtime class here to prevent circular dependency
Runtime: cdk.Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs18.x'), // Equivalent to Runtime.NODEJS_18_X
Code: {
S3Bucket: asset.s3BucketName,
S3Key: asset.s3ObjectKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export const INLINE_CUSTOM_RESOURCE_CONTEXT = '@aws-cdk/core:inlineCustomResourc
* based on region.
*/
export function builtInCustomResourceProviderNodeRuntime(scope: Construct): CustomResourceProviderRuntime {
const runtimeName = Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs16.x');
return Object.values(CustomResourceProviderRuntime).find(value => value === runtimeName) ?? CustomResourceProviderRuntime.NODEJS_16_X;
const runtimeName = Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs18.x');
return Object.values(CustomResourceProviderRuntime).find(value => value === runtimeName) ?? CustomResourceProviderRuntime.NODEJS_18_X;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,20 +458,20 @@ describe('custom resource provider', () => {

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

const rt = builtInCustomResourceProviderNodeRuntime(stack);
expect(rt).toEqual(CustomResourceProviderRuntime.NODEJS_16_X);
expect(rt).toEqual(CustomResourceProviderRuntime.NODEJS_18_X);
});

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

const rt = builtInCustomResourceProviderNodeRuntime(stack);
expect(rt).toEqual(CustomResourceProviderRuntime.NODEJS_14_X);
expect(rt).toEqual(CustomResourceProviderRuntime.NODEJS_18_X);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { FactName } from '../../../region-info';
export function builtInCustomResourceNodeRuntime(scope: Construct): lambda.Runtime {
// Runtime regional fact should always return a known runtime string that lambda.Runtime
// can index off, but for type safety we also default it here.
const runtimeName = cdk.Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs16.x');
const runtimeName = cdk.Stack.of(scope).regionalFact(FactName.DEFAULT_CR_NODE_VERSION, 'nodejs18.x');
return runtimeName
? new lambda.Runtime(runtimeName, lambda.RuntimeFamily.NODEJS, { supportsInlineCode: true })
: lambda.Runtime.NODEJS_16_X;
: lambda.Runtime.NODEJS_18_X;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1282,20 +1282,20 @@ test('can specify removal policy', () => {
});

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

const rt = builtInCustomResourceNodeRuntime(stack);
expect(rt).toEqual(lambda.Runtime.NODEJS_16_X);
expect(rt).toEqual(lambda.Runtime.NODEJS_18_X);
});

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

const rt = builtInCustomResourceNodeRuntime(stack);
expect(rt).toEqual(lambda.Runtime.NODEJS_14_X);
expect(rt).toEqual(lambda.Runtime.NODEJS_18_X);
});
});

10 changes: 5 additions & 5 deletions packages/aws-cdk-lib/region-info/build-tools/fact-tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ export const PARTITION_MAP: { [region: string]: Region } = {
};

export const CR_DEFAULT_RUNTIME_MAP: Record<Partition, string> = {
[Partition.Default]: 'nodejs16.x',
[Partition.Cn]: 'nodejs16.x',
[Partition.UsGov]: 'nodejs16.x',
[Partition.UsIso]: 'nodejs14.x',
[Partition.UsIsoB]: 'nodejs14.x',
[Partition.Default]: 'nodejs18.x',
[Partition.Cn]: 'nodejs18.x',
[Partition.UsGov]: 'nodejs18.x',
[Partition.UsIso]: 'nodejs18.x',
[Partition.UsIsoB]: 'nodejs18.x',
};

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

0 comments on commit a35fcc5

Please sign in to comment.