Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(lambda): update default node runtime for all partitions #26475

Merged
merged 6 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading