diff --git a/packages/@aws-cdk/aws-lambda-nodejs/lib/function.ts b/packages/@aws-cdk/aws-lambda-nodejs/lib/function.ts index a1c7611e64825..5e4e160eaa717 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/lib/function.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/lib/function.ts @@ -87,7 +87,10 @@ export class NodejsFunction extends lambda.Function { if (!fs.existsSync(props.depsLockFilePath)) { throw new Error(`Lock file at ${props.depsLockFilePath} doesn't exist`); } - depsLockFilePath = props.depsLockFilePath; + if (!fs.statSync(props.depsLockFilePath).isFile()) { + throw new Error('`depsLockFilePath` should point to a file'); + } + depsLockFilePath = path.resolve(props.depsLockFilePath); } else { const lockFile = findUp(LockFile.YARN) ?? findUp(LockFile.NPM); if (!lockFile) { diff --git a/packages/@aws-cdk/aws-lambda-nodejs/test/function.test.ts b/packages/@aws-cdk/aws-lambda-nodejs/test/function.test.ts index 743526d0e3899..d898d312be92c 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/test/function.test.ts @@ -107,6 +107,22 @@ test('throws with non existing lock file', () => { })).toThrow(/Lock file at \/does\/not\/exist.lock doesn't exist/); }); +test('throws when depsLockFilePath is not a file', () => { + expect(() => new NodejsFunction(stack, 'handler1', { + depsLockFilePath: __dirname, + })).toThrow(/\`depsLockFilePath\` should point to a file/); +}); + +test('resolves depsLockFilePath to an absolute path', () => { + new NodejsFunction(stack, 'handler1', { + depsLockFilePath: './package.json', + }); + + expect(Bundling.bundle).toHaveBeenCalledWith(expect.objectContaining({ + depsLockFilePath: expect.stringMatching(/@aws-cdk\/aws-lambda-nodejs\/package.json$/), + })); +}); + test('resolves entry to an absolute path', () => { // WHEN new NodejsFunction(stack, 'fn', {