diff --git a/src/frameworks/cdkFramework.ts b/src/frameworks/cdkFramework.ts index fffa98b2..94b171bc 100755 --- a/src/frameworks/cdkFramework.ts +++ b/src/frameworks/cdkFramework.ts @@ -476,29 +476,40 @@ export class CdkFramework implements IFramework { .then(() => true) .catch(() => false), ); - - if (!codePath) { - throw new Error( - `Code file not found for Lambda function ${lambda.code.path}`, - ); - } } - const packageJsonPath = await findPackageJson(codePath); - Logger.verbose(`[CDK] package.json path: ${packageJsonPath}`); + let packageJsonPath: string | undefined; + if (codePath) { + packageJsonPath = await findPackageJson(codePath); + Logger.verbose(`[CDK] package.json path: ${packageJsonPath}`); + } return { cdkPath: lambda.cdkPath, stackName: lambda.stackName, packageJsonPath, - codePath, + codePath: codePath, handler, bundling: lambda.bundling, }; }), ); - return list; + const filteredList = list.filter((lambda) => lambda.codePath); + const noCodeList = list.filter((lambda) => !lambda.codePath); + + if (noCodeList.length > 0) { + Logger.warn( + `[CDK] For the following Lambda functions the code file could not be determined and they will be ignored. Inline code is not supported.\n - ${noCodeList + .map((l) => `${l.cdkPath}`) + .join('\n - ')}`, + ); + } + + return filteredList.map((lambda) => ({ + ...lambda, + codePath: lambda.codePath!, + })); } /** diff --git a/test/cdk-basic/lib/cdk-basic-stack.ts b/test/cdk-basic/lib/cdk-basic-stack.ts index 9f43edeb..eabb6273 100644 --- a/test/cdk-basic/lib/cdk-basic-stack.ts +++ b/test/cdk-basic/lib/cdk-basic-stack.ts @@ -46,6 +46,24 @@ export class CdkbasicStack extends cdk.Stack { }, ); + const functionInlineCode = new lambda.Function(this, 'TestInlineCode', { + runtime: lambda.Runtime.NODEJS_22_X, + handler: 'index.handler', + code: lambda.Code.fromInline(` + exports.handler = async (event) => { + const response = { + statusCode: 200, + body: JSON.stringify({ + message: 'Hello from inline Lambda function!', + timestamp: new Date().toISOString(), + event: event + }), + }; + }; + `), + logRetention: log.RetentionDays.ONE_DAY, + }); + new cdk.CfnOutput(this, 'FunctionNameTestTsCommonJs', { value: functionTestTsCommonJs.functionName, }); @@ -57,5 +75,9 @@ export class CdkbasicStack extends cdk.Stack { new cdk.CfnOutput(this, 'FunctionNameTestJsCommonJs', { value: functionTestJsCommonJs.functionName, }); + + new cdk.CfnOutput(this, 'FunctionNameTestInlineCode', { + value: functionInlineCode.functionName, + }); } }