Skip to content
Open
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
273 changes: 273 additions & 0 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions examples/typescript/multi-lambda/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import * as cdk from 'aws-cdk-lib';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { TypeScriptCodeCollection } from '@mrgrain/cdk-esbuild';

export class MultiLambdaStack extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const codeCollection = new TypeScriptCodeCollection(this, 'MultiLambda', {
entryPoints: {
'api': './src/api.ts',
'auth': './src/auth.ts',
'notifications': './src/notifications.ts',
},
buildOptions: {
minify: true,
},
});

new lambda.Function(this, 'ApiFunction', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'api.handler',
code: codeCollection.getCode('api'),
});

new lambda.Function(this, 'AuthFunction', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'auth.handler',
code: codeCollection.getCode('auth'),
});

new lambda.Function(this, 'NotificationsFunction', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'notifications.handler',
Comment on lines +22 to +34
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The handler references ('api.handler', 'auth.handler', 'notifications.handler') are incorrect for the current implementation. Since each entry point is bundled separately using individual TypeScriptCode instances, the output will be 'index.js' for each bundle, not 'api.js', 'auth.js', or 'notifications.js'. The handler should be 'index.handler' for all three Lambda functions.

This handler naming would only work if all entry points were bundled together in a single esbuild invocation with a Record<string, string> of entry points, which would preserve the entry point names in the output.

Suggested change
handler: 'api.handler',
code: codeCollection.getCode('api'),
});
new lambda.Function(this, 'AuthFunction', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'auth.handler',
code: codeCollection.getCode('auth'),
});
new lambda.Function(this, 'NotificationsFunction', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'notifications.handler',
handler: 'index.handler',
code: codeCollection.getCode('api'),
});
new lambda.Function(this, 'AuthFunction', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',
code: codeCollection.getCode('auth'),
});
new lambda.Function(this, 'NotificationsFunction', {
runtime: lambda.Runtime.NODEJS_18_X,
handler: 'index.handler',

Copilot uses AI. Check for mistakes.
code: codeCollection.getCode('notifications'),
});
}
}

const app = new cdk.App();
new MultiLambdaStack(app, 'MultiLambdaStack');
18 changes: 18 additions & 0 deletions examples/typescript/multi-lambda/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "multi-lambda-example",
"version": "1.0.0",
"description": "Example of building multiple Lambda functions with cdk-esbuild",
"main": "app.ts",
"scripts": {
"deploy": "cdk deploy",
"synth": "cdk synth"
},
"dependencies": {
"aws-cdk-lib": "^2.0.0",
"constructs": "^10.0.0",
"@mrgrain/cdk-esbuild": "^5.0.0"
},
"devDependencies": {
"typescript": "^5.0.0"
}
}
Comment on lines +1 to +18
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example is missing several files that are present in other TypeScript examples and are necessary for the example to be functional:

  1. cdk.json - Required for CDK CLI to know how to execute the app. Without this, running cdk deploy or cdk synth won't work.
  2. tsconfig.json - Required for TypeScript compilation
  3. README.md - Helpful for users to understand how to use the example
  4. .gitignore - Standard practice for examples

For reference, see the examples/typescript/lambda/ directory which includes all these files.

Copilot uses AI. Check for mistakes.
6 changes: 6 additions & 0 deletions examples/typescript/multi-lambda/src/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export async function handler(event: any) {
return {
statusCode: 200,
body: JSON.stringify({ message: 'API Handler' }),
};
}
6 changes: 6 additions & 0 deletions examples/typescript/multi-lambda/src/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export async function handler(event: any) {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Auth Handler' }),
};
}
6 changes: 6 additions & 0 deletions examples/typescript/multi-lambda/src/notifications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export async function handler(event: any) {
return {
statusCode: 200,
body: JSON.stringify({ message: 'Notifications Handler' }),
};
}
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ export {
TypeScriptSource,
TypeScriptSourceProps,
} from './source';

export {
TypeScriptCodeCollection,
TypeScriptCodeCollectionProps,
} from './typescript-code-collection';
Loading
Loading