interface NodeJsLambdaOptions {
    entry: string;
    handler: string;
    runtime?: Runtime;
    memorySize?: number;
    timeout?: Duration;
    environment?: {
        [key: string]: string;
    };
    concurrentExecutions?: number;
    inlineCode?: InlineCode;
    bundling?: Partial<BundlingOptions>;
    props?: Partial<NodejsFunctionProps>;
}

Properties

entry: string

The file path to the entry file for your Lambda function's handler, relative to the root of your project.

This is the TypeScript or JavaScript file that exports the handler function.

const entry = './src/index.ts';
handler: string

The name of the handler function exported from your entry file.

This should match the name of the function exported in your entry file that will be invoked by AWS Lambda.

// In your entry file, you might have:
export const handle = async (event) => { ... };

// Then, specify:
const handler = 'handle';
runtime?: Runtime

The Node.js runtime environment to use for the Lambda function.

Defaults to NODEJS_20_X.

import * as lambda from 'aws-cdk-lib/aws-lambda';

const runtime = lambda.Runtime.NODEJS_20_X;
memorySize?: number

The amount of memory, in MB, allocated to your Lambda function.

Any number divisible by 64 between 128 and 10240 (10GB),

Defaults to 128.

timeout?: Duration

The maximum time (in seconds) that the Lambda function can run before it is terminated by AWS.

Defaults to 30 seconds.

import { Duration } from 'aws-cdk-lib';

const timeout = Duration.seconds(20);
environment?: {
    [key: string]: string;
}

Key-value pairs that are set as environment variables for the Lambda function.

These can be accessed in your handler code using process.env.

const environment = {
STAGE: 'production',
API_KEY: 'my-secret-key',
};
concurrentExecutions?: number

The maximum number of concurrent executions for the Lambda function.

This limits the number of instances of the function that can be running at the same time.

const concurrentExecutions = 10;
inlineCode?: InlineCode

Inline Lambda code. (Mostly used just for testing...)

bundling?: Partial<BundlingOptions>

Additional bundling options to customize the esbuild bundling process.

These options will be merged with the default bundling configuration.

const bundlingOptions = {
minify: true,
target: 'es2020',
define: {
'process.env.NODE_ENV': '"production"'
},
external: ['aws-sdk']
};
props?: Partial<NodejsFunctionProps>

Any other available props to configure your Lambda.