Skip to content
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
31 changes: 21 additions & 10 deletions src/frameworks/cdkFramework.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
}));
}

/**
Expand Down
22 changes: 22 additions & 0 deletions test/cdk-basic/lib/cdk-basic-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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,
});
}
}
Loading