-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat: Add TypeScriptCodeCollection for building multiple Lambda functions #1701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v5
Are you sure you want to change the base?
Changes from all commits
38248db
f95c50a
2f659fb
f7bb156
59e5f21
1d8b1e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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', | ||
| code: codeCollection.getCode('notifications'), | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| const app = new cdk.App(); | ||
| new MultiLambdaStack(app, 'MultiLambdaStack'); | ||
| 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
|
||
| 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' }), | ||
| }; | ||
| } |
| 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' }), | ||
| }; | ||
| } |
| 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' }), | ||
| }; | ||
| } |
There was a problem hiding this comment.
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.