A construct that simplifies the creation and configuration of a Node.js-based AWS Lambda function.

The NodeJsLambda construct uses the AWS CDK's aws-lambda-nodejs module to bundle and deploy a Node.js Lambda function, with sensible defaults and support for customizing runtime settings, memory, timeout, and environment variables.

This construct is ideal for projects where you need to deploy a TypeScript or JavaScript Lambda function with minimal configuration, while still allowing for detailed customization when necessary.

import { Stack, Duration } from 'aws-cdk-lib';
import { lambda } from '@reuters-graphics/structs';
import { Construct } from 'constructs';

export class MyLambdaStack extends Stack {
constructor(scope: Construct, id: string) {
super(scope, id);

// Define a Node.js Lambda function with specific entry and handler
const myLambda = new lambda.NodeJsLambda(this, 'MyLambdaFunction', {
entry: './src/index.ts',
handler: 'handle',
runtime: lambda.Runtime.NODEJS_20_X,
memorySize: 256,
timeout: Duration.seconds(15),
environment: {
NODE_ENV: 'production',
API_URL: 'https://api.example.com',
},
});

// Access the underlying Lambda function
const lambdaFunction = myLambda.lambda;
}
}

Hierarchy

  • Construct
    • NodeJsLambda

Constructors

Properties

Methods

Constructors

  • Creates a new NodeJsLambda construct.

    Parameters

    • scope: Construct

      The scope in which this construct is defined.

    • id: string

      The scoped construct ID.

    • props: NodeJsLambdaOptions

      Configuration options for the Lambda function.

    Returns NodeJsLambda

Properties

lambda: Function

The underlying AWS Lambda function created by this construct.

node: Node

The tree node.

Methods

  • Checks if x is a construct.

    Use this method instead of instanceof to properly detect Construct instances, even when the construct library is symlinked.

    Explanation: in JavaScript, multiple copies of the constructs library on disk are seen as independent, completely different libraries. As a consequence, the class Construct in each copy of the constructs library is seen as a different class, and an instance of one class will not test as instanceof the other class. npm install will not create installations like this, but users may manually symlink construct libraries together or use a monorepo tool: in those cases, multiple copies of the constructs library can be accidentally installed, and instanceof will behave unpredictably. It is safest to avoid using instanceof, and using this type-testing method instead.

    Parameters

    • x: any

      Any object

    Returns x is Construct

    true if x is an object created from a class which extends Construct.

  • Returns a string representation of this construct.

    Returns string