diff --git a/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts index fd0c17a3be465..4c4d17d9a6dda 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/lib/bundling.ts @@ -410,5 +410,5 @@ function isSdkV2Runtime(runtime: Runtime): boolean { Runtime.NODEJS_14_X, Runtime.NODEJS_16_X, ]; - return sdkV2RuntimeList.includes(runtime); + return sdkV2RuntimeList.some((r) => {return r.family === runtime.family && r.name === runtime.name;}); } diff --git a/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts b/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts index 9679530a01189..e5248724a0aaa 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts @@ -1,7 +1,7 @@ import * as child_process from 'child_process'; import * as os from 'os'; import * as path from 'path'; -import { Architecture, Code, Runtime } from '@aws-cdk/aws-lambda'; +import { Architecture, Code, Runtime, RuntimeFamily } from '@aws-cdk/aws-lambda'; import { AssetHashType, DockerImage } from '@aws-cdk/core'; import { version as delayVersion } from 'delay/package.json'; import { Bundling } from '../lib/bundling'; @@ -329,6 +329,30 @@ test('esbuild bundling source map inline', () => { }); }); +test('esbuild bundling is correctly done with custom runtime matching predefined runtime', () => { + Bundling.bundle({ + entry, + projectRoot, + depsLockFilePath, + runtime: new Runtime('nodejs14.x', RuntimeFamily.NODEJS, { supportsInlineCode: true }), + architecture: Architecture.X86_64, + sourceMapMode: SourceMapMode.INLINE, + }); + + expect(Code.fromAsset).toHaveBeenCalledWith(path.dirname(depsLockFilePath), { + assetHashType: AssetHashType.OUTPUT, + bundling: expect.objectContaining({ + command: [ + 'bash', '-c', + [ + 'esbuild --bundle "/asset-input/lib/handler.ts" --target=node14 --platform=node --outfile="/asset-output/index.js"', + '--sourcemap=inline --external:aws-sdk', + ].join(' '), + ], + }), + }); +}); + test('esbuild bundling source map enabled when only source map mode exists', () => { Bundling.bundle({ entry,