Skip to content
v2.274.0

NodejsFunctionProps Struct ​

Properties for a NodejsFunction.

Example ​

ts
new nodejs.NodejsFunction(this, 'my-handler', {
 bundling: {
     network: 'host',
     securityOpt: 'no-new-privileges',
     user: 'user:group',
     volumesFrom: ['777f7dc92da7'],
     volumes: [{ hostPath: '/host-path', containerPath: '/container-path' }],
  },
});

Properties ​

adotInstrumentationoptionalAdotInstrumentationConfigadot_instrumentationoptionalAdotInstrumentationConfigadotInstrumentationoptionalAdotInstrumentationConfigAdotInstrumentationoptionalAdotInstrumentationConfigAdotInstrumentationoptionalAdotInstrumentationConfig#
Specify the configuration of AWS Distro for OpenTelemetry (ADOT) instrumentation.

Default: No ADOT instrumentation

allowAllIpv6Outboundoptionalbooleanallow_all_ipv6_outboundoptionalboolallowAllIpv6OutboundoptionalBooleanAllowAllIpv6OutboundoptionalboolAllowAllIpv6Outboundoptional*bool= false#
Whether to allow the Lambda to send all ipv6 network traffic.
notes

If set to true, there will only be a single egress rule which allows all outbound ipv6 traffic. If set to false, you must individually add traffic rules to allow the Lambda to connect to network targets using ipv6.

Do not specify this property if the securityGroups or securityGroup property is set. Instead, configure allowAllIpv6Outbound directly on the security group.

allowAllOutboundoptionalbooleanallow_all_outboundoptionalboolallowAllOutboundoptionalBooleanAllowAllOutboundoptionalboolAllowAllOutboundoptional*bool= true#
Whether to allow the Lambda to send all network traffic (except ipv6).
notes

If set to false, you must individually add traffic rules to allow the Lambda to connect to network targets.

Do not specify this property if the securityGroups or securityGroup property is set. Instead, configure allowAllOutbound directly on the security group.

allowPublicSubnetoptionalbooleanallow_public_subnetoptionalboolallowPublicSubnetoptionalBooleanAllowPublicSubnetoptionalboolAllowPublicSubnetoptional*bool= false#
Lambda Functions in a public subnet can NOT access the internet.

Use this property to acknowledge this limitation and still place the function in a public subnet.

applicationLogLeveloptionalstringapplication_log_leveloptionalstrapplicationLogLeveloptionalStringApplicationLogLeveloptionalstringApplicationLogLeveloptional*string= "INFO"deprecated#
Use `applicationLogLevelV2` as a property instead.
applicationLogLevelV2optionalApplicationLogLevelapplication_log_level_v2optionalApplicationLogLevelapplicationLogLevelV2optionalApplicationLogLevelApplicationLogLevelV2optionalApplicationLogLevelApplicationLogLevelV2optionalApplicationLogLevel= ApplicationLogLevel.INFO#
Sets the application log level for the function.
architectureoptionalArchitecturearchitectureoptionalArchitecturearchitectureoptionalArchitectureArchitectureoptionalArchitectureArchitectureoptionalArchitecture= Architecture.X86_64#
The system architectures compatible with this lambda function.
awsSdkConnectionReuseoptionalbooleanaws_sdk_connection_reuseoptionalboolawsSdkConnectionReuseoptionalBooleanAwsSdkConnectionReuseoptionalboolAwsSdkConnectionReuseoptional*bool#
The `AWS_NODEJS_CONNECTION_REUSE_ENABLED` environment variable does not exist in the AWS SDK for JavaScript v3.

Default: false (obsolete) for runtimes >= Node 18, true for runtimes <= Node 16.

notes

This prop will be deprecated when the Lambda Node16 runtime is deprecated on June 12, 2024. See https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html#runtime-support-policy

Info for Node 16 runtimes / SDK v2 users:

Whether to automatically reuse TCP connections when working with the AWS SDK for JavaScript v2.

This sets the AWS_NODEJS_CONNECTION_REUSE_ENABLED environment variable to 1.

bundlingoptionalBundlingOptionsbundlingoptionalBundlingOptionsbundlingoptionalBundlingOptionsBundlingoptionalBundlingOptionsBundlingoptionalBundlingOptions#
Bundling options.

Default: use default bundling options: no minify, no sourcemap, all modules are bundled.

codeoptionalCodecodeoptionalCodecodeoptionalCodeCodeoptionalCodeCodeoptionalCode#
The code that will be deployed to the Lambda Handler.

Default: the code is bundled by esbuild

If included, then properties related to bundling of the code are ignored.

  • If the code field is specified, then you must include the handler property.
codeSigningConfigoptionalICodeSigningConfigRefcode_signing_configoptionalICodeSigningConfigRefcodeSigningConfigoptionalICodeSigningConfigRefCodeSigningConfigoptionalICodeSigningConfigRefCodeSigningConfigoptionalICodeSigningConfigRef#
Code signing config associated with this function.

Default: Not Sign the Code

currentVersionOptionsoptionalVersionOptionscurrent_version_optionsoptionalVersionOptionscurrentVersionOptionsoptionalVersionOptionsCurrentVersionOptionsoptionalVersionOptionsCurrentVersionOptionsoptionalVersionOptions#
Options for the `lambda.Version` resource automatically created by the `fn.currentVersion` method.

Default: default options as described in VersionOptions

deadLetterQueueoptionalIQueuedead_letter_queueoptionalIQueuedeadLetterQueueoptionalIQueueDeadLetterQueueoptionalIQueueDeadLetterQueueoptionalIQueue#
The SQS queue to use if DLQ is enabled.

Default: SQS queue with 14 day retention period if deadLetterQueueEnabled is true

If SNS topic is desired, specify deadLetterTopic property instead.

deadLetterQueueEnabledoptionalbooleandead_letter_queue_enabledoptionalbooldeadLetterQueueEnabledoptionalBooleanDeadLetterQueueEnabledoptionalboolDeadLetterQueueEnabledoptional*bool#
Enabled DLQ.

Default: false unless deadLetterQueue is set, which implies DLQ is enabled.

If deadLetterQueue is undefined, an SQS queue with default options will be defined for your Function.

deadLetterTopicoptionalITopicdead_letter_topicoptionalITopicdeadLetterTopicoptionalITopicDeadLetterTopicoptionalITopicDeadLetterTopicoptionalITopic#
The SNS topic to use as a DLQ.

Default: no SNS topic

Note that if deadLetterQueueEnabled is set to true, an SQS queue will be created rather than an SNS topic. Using an SNS topic as a DLQ requires this property to be set explicitly.

depsLockFilePathoptionalstringdeps_lock_file_pathoptionalstrdepsLockFilePathoptionalStringDepsLockFilePathoptionalstringDepsLockFilePathoptional*string#
The path to the dependencies lock file (`yarn.lock`, `pnpm-lock.yaml`, `bun.lockb`, `bun.lock` or `package-lock.json`).

Default: the path is found by walking up parent directories searching for a yarn.lock, pnpm-lock.yaml, bun.lockb, bun.lock or package-lock.json file

This will be used as the source for the volume mounted in the Docker container.

Modules specified in nodeModules will be installed using the right installer (yarn, pnpm, bun or npm) along with this lock file.

descriptionoptionalstringdescriptionoptionalstrdescriptionoptionalStringDescriptionoptionalstringDescriptionoptional*string#
A description of the function.

Default: No description.

durableConfigoptionalDurableConfigdurable_configoptionalDurableConfigdurableConfigoptionalDurableConfigDurableConfigoptionalDurableConfigDurableConfigoptionalDurableConfig#
The durable configuration for the function.

Default: No durable configuration

If durability is added to an existing function, a resource replacement will be triggered. See the 'durableConfig' section in the module README for more details.

entryoptionalstringentryoptionalstrentryoptionalStringEntryoptionalstringEntryoptional*string#
Path to the entry file (JavaScript or TypeScript).

Default: (Realible in Node projects only) derived from the defining file's name and construct ID as described in the documentation.

notes

If this is a relative path, it will be evaluated with respect to the JavaScript/TypeScript source file that instantiates the NodejsFunction construct. If the current project is not a Node project, relative paths are not reliable and absolute paths should be used.

This file should be located underneath the projectRoot directory (by default, the directory containing the package manager's lock file).

If omitted, the entry file will be derived from the TypeScript/JavaScript file that instantiates the NodejsFunction construct, and the construct identifier of the NodejsFunction construct, in the following way:

<filename>.<construct-id>.(ts|js)

// Example, if stack.ts contains the following:
new NodejsFunction(this, 'my-handler', { ... });

// Then the implicit entry point(s) will be
stack.my-handler.ts
stack.my-handler.js

Again: if the current project is not a Node project this is not reliable, and instead explicit, absolute paths should be used.

environmentoptional{ [key: string]: string }environmentoptionaltyping.Mapping[str, str]environmentoptionalMap<String, String>EnvironmentoptionalIDictionary<string, string>Environmentoptional*map[string]*string#
Key-value pairs that Lambda caches and makes available for your Lambda functions.

Default: No environment variables.

Use environment variables to apply configuration changes, such as test and production environment configurations, without changing your Lambda function source code.

environmentEncryptionoptionalIKeyRefenvironment_encryptionoptionalIKeyRefenvironmentEncryptionoptionalIKeyRefEnvironmentEncryptionoptionalIKeyRefEnvironmentEncryptionoptionalIKeyRef#
The AWS KMS key that's used to encrypt your function's environment variables.

Default: AWS Lambda creates and uses an AWS managed customer master key (CMK).

ephemeralStorageSizeoptionalSizeephemeral_storage_sizeoptionalSizeephemeralStorageSizeoptionalSizeEphemeralStorageSizeoptionalSizeEphemeralStorageSizeoptionalSize#
The size of the function’s /tmp directory in MiB.

Default: 512 MiB

eventsoptionalIEventSource[]eventsoptionaltyping.List[IEventSource]eventsoptionalList<IEventSource>EventsoptionalIEventSource[]Eventsoptional*[]IEventSource#
Event sources for this function.

Default: No event sources.

You can also add event sources using addEventSource.

filesystemoptionalFileSystemfilesystemoptionalFileSystemfilesystemoptionalFileSystemFilesystemoptionalFileSystemFilesystemoptionalFileSystem#
The filesystem configuration for the lambda function.

Default: will not mount any filesystem

functionNameoptionalstringfunction_nameoptionalstrfunctionNameoptionalStringFunctionNameoptionalstringFunctionNameoptional*string#
A name for the function.

Default: AWS CloudFormation generates a unique physical ID and uses that ID for the function's name. For more information, see Name Type.

handleroptionalstringhandleroptionalstrhandleroptionalStringHandleroptionalstringHandleroptional*string= handler#
The name of the exported handler in the entry file.
notes
  • If the code property is supplied, then you must include the handler property. The handler should be the name of the file that contains the exported handler and the function that should be called when the AWS Lambda is invoked. For example, if you had a file called myLambda.js and the function to be invoked was myHandler, then you should input handler property as myLambda.myHandler.

  • If the code property is not supplied and the handler input does not contain a ., then the handler is prefixed with index. (index period). Otherwise, the handler property is not modified.

initialPolicyoptionalPolicyStatement[]initial_policyoptionaltyping.List[PolicyStatement]initialPolicyoptionalList<PolicyStatement>InitialPolicyoptionalPolicyStatement[]InitialPolicyoptional*[]PolicyStatement#
Initial policy statements to add to the created Lambda Role.

Default: No policy statements are added to the created Lambda role.

You can call addToRolePolicy to the created lambda to add statements post creation.

insightsVersionoptionalLambdaInsightsVersioninsights_versionoptionalLambdaInsightsVersioninsightsVersionoptionalLambdaInsightsVersionInsightsVersionoptionalLambdaInsightsVersionInsightsVersionoptionalLambdaInsightsVersion#
Specify the version of CloudWatch Lambda insights to use for monitoring.

Default: No Lambda Insights

ipv6AllowedForDualStackoptionalbooleanipv6_allowed_for_dual_stackoptionalboolipv6AllowedForDualStackoptionalBooleanIpv6AllowedForDualStackoptionalboolIpv6AllowedForDualStackoptional*bool= false#
Allows outbound IPv6 traffic on VPC functions that are connected to dual-stack subnets.

Only used if 'vpc' is supplied.

layersoptionalILayerVersion[]layersoptionaltyping.List[ILayerVersion]layersoptionalList<ILayerVersion>LayersoptionalILayerVersion[]Layersoptional*[]ILayerVersion#
A list of layers to add to the function's execution environment.

Default: No layers.

You can configure your Lambda function to pull in additional code during initialization in the form of layers. Layers are packages of libraries or other dependencies that can be used by multiple functions.

logFormatoptionalstringlog_formatoptionalstrlogFormatoptionalStringLogFormatoptionalstringLogFormatoptional*string= "Text"deprecated#
Use `loggingFormat` as a property instead.
loggingFormatoptionalLoggingFormatlogging_formatoptionalLoggingFormatloggingFormatoptionalLoggingFormatLoggingFormatoptionalLoggingFormatLoggingFormatoptionalLoggingFormat= LoggingFormat.TEXT#
Sets the loggingFormat for the function.
logGroupoptionalILogGroupReflog_groupoptionalILogGroupReflogGroupoptionalILogGroupRefLogGroupoptionalILogGroupRefLogGroupoptionalILogGroupRef#
The log group the function sends logs to.

Default: /aws/lambda/${this.functionName} - default log group created by Lambda

notes

By default, Lambda functions send logs to an automatically created default log group named /aws/lambda/&lt;function name>. However you cannot change the properties of this auto-created log group using the AWS CDK, e.g. you cannot set a different log retention.

Use the logGroup property to create a fully customizable LogGroup ahead of time, and instruct the Lambda function to send logs to it.

Providing a user-controlled log group was rolled out to commercial regions on 2023-11-16. If you are deploying to another type of region, please check regional availability first.

logRemovalPolicyoptionalRemovalPolicylog_removal_policyoptionalRemovalPolicylogRemovalPolicyoptionalRemovalPolicyLogRemovalPolicyoptionalRemovalPolicyLogRemovalPolicyoptionalRemovalPolicy= RemovalPolicy.Retaindeprecated#
use `logGroup` instead

Normally you want to retain the log group so you can diagnose issues from logs even after a deployment that no longer includes the log group. In that case, use the normal date-based retention policy to age out your logs.

logRetentionoptionalRetentionDayslog_retentionoptionalRetentionDayslogRetentionoptionalRetentionDaysLogRetentionoptionalRetentionDaysLogRetentionoptionalRetentionDays= logs.RetentionDays.INFINITEdeprecated#
use `logGroup` instead
notes

When updating this property, unsetting it doesn't remove the log retention policy. To remove the retention policy, set the value to INFINITE.

This is a legacy API and we strongly recommend you move away from it if you can. Instead create a fully customizable log group with logs.LogGroup and use the logGroup property to instruct the Lambda function to send logs to it. Migrating from logRetention to logGroup will cause the name of the log group to change. Users and code and referencing the name verbatim will have to adjust.

In AWS CDK code, you can access the log group name directly from the LogGroup construct:

ts
import * as logs from 'aws-cdk-lib/aws-logs';

declare const myLogGroup: logs.LogGroup;
myLogGroup.logGroupName;
logRetentionRetryOptionsoptionalLogRetentionRetryOptionslog_retention_retry_optionsoptionalLogRetentionRetryOptionslogRetentionRetryOptionsoptionalLogRetentionRetryOptionsLogRetentionRetryOptionsoptionalLogRetentionRetryOptionsLogRetentionRetryOptionsoptionalLogRetentionRetryOptions#
When log retention is specified, a custom resource attempts to create the CloudWatch log group.

Default: Default AWS SDK retry options.

notes

These options control the retry policy when interacting with CloudWatch APIs.

This is a legacy API and we strongly recommend you migrate to logGroup if you can. logGroup allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.

logRetentionRoleoptionalIRolelog_retention_roleoptionalIRolelogRetentionRoleoptionalIRoleLogRetentionRoleoptionalIRoleLogRetentionRoleoptionalIRole#
The IAM role for the Lambda function associated with the custom resource that sets the retention policy.

Default: A new role is created.

This is a legacy API and we strongly recommend you migrate to logGroup if you can. logGroup allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.

maxEventAgeoptionalDurationmax_event_ageoptionalDurationmaxEventAgeoptionalDurationMaxEventAgeoptionalDurationMaxEventAgeoptionalDuration= Duration.hours(6)#
The maximum age of a request that Lambda sends to a function for processing.

Minimum: 60 seconds Maximum: 6 hours

memorySizeoptionalnumbermemory_sizeoptionalint | floatmemorySizeoptionalNumberMemorySizeoptionaldoubleMemorySizeoptional*float64= 128#
The amount of memory, in MB, that is allocated to your Lambda function.

Lambda uses this value to proportionally allocate the amount of CPU power. For more information, see Resource Model in the AWS Lambda Developer Guide.

onFailureoptionalIDestinationon_failureoptionalIDestinationonFailureoptionalIDestinationOnFailureoptionalIDestinationOnFailureoptionalIDestination#
The destination for failed invocations.

Default: no destination

onSuccessoptionalIDestinationon_successoptionalIDestinationonSuccessoptionalIDestinationOnSuccessoptionalIDestinationOnSuccessoptionalIDestination#
The destination for successful invocations.

Default: no destination

paramsAndSecretsoptionalParamsAndSecretsLayerVersionparams_and_secretsoptionalParamsAndSecretsLayerVersionparamsAndSecretsoptionalParamsAndSecretsLayerVersionParamsAndSecretsoptionalParamsAndSecretsLayerVersionParamsAndSecretsoptionalParamsAndSecretsLayerVersion#
Specify the configuration of Parameters and Secrets Extension.

Default: No Parameters and Secrets Extension

profilingoptionalbooleanprofilingoptionalboolprofilingoptionalBooleanProfilingoptionalboolProfilingoptional*bool#
Enable profiling.

Default: No profiling.

profilingGroupoptionalIProfilingGroupprofiling_groupoptionalIProfilingGroupprofilingGroupoptionalIProfilingGroupProfilingGroupoptionalIProfilingGroupProfilingGroupoptionalIProfilingGroup#
Profiling Group.

Default: A new profiling group will be created if profiling is set.

projectRootoptionalstringproject_rootoptionalstrprojectRootoptionalStringProjectRootoptionalstringProjectRootoptional*string#
The path to the directory containing project config files (`package.json` or `tsconfig.json`).

Default: the directory containing the depsLockFilePath

recursiveLoopoptionalRecursiveLooprecursive_loopoptionalRecursiveLooprecursiveLoopoptionalRecursiveLoopRecursiveLoopoptionalRecursiveLoopRecursiveLoopoptionalRecursiveLoop= RecursiveLoop.Terminate#
Sets the Recursive Loop Protection for Lambda Function.

It lets Lambda detect and terminate unintended recursive loops.

reservedConcurrentExecutionsoptionalnumberreserved_concurrent_executionsoptionalint | floatreservedConcurrentExecutionsoptionalNumberReservedConcurrentExecutionsoptionaldoubleReservedConcurrentExecutionsoptional*float64#
The maximum of concurrent executions you want to reserve for the function.

Default: No specific limit - account limit.

retryAttemptsoptionalnumberretry_attemptsoptionalint | floatretryAttemptsoptionalNumberRetryAttemptsoptionaldoubleRetryAttemptsoptional*float64= 2#
The maximum number of times to retry when the function returns an error.

Minimum: 0 Maximum: 2

roleoptionalIRoleroleoptionalIRoleroleoptionalIRoleRoleoptionalIRoleRoleoptionalIRole#
Lambda execution role.

Default: A unique role will be generated for this lambda function. Both supplied and generated roles can always be changed by calling addToRolePolicy.

notes

This is the role that will be assumed by the function upon execution. It controls the permissions that the function will have. The Role must be assumable by the 'lambda.amazonaws.com' service principal.

The default Role automatically has permissions granted for Lambda execution. If you provide a Role, you must add the relevant AWS managed policies yourself.

The relevant managed policies are "service-role/AWSLambdaBasicExecutionRole" and "service-role/AWSLambdaVPCAccessExecutionRole".

runtimeoptionalRuntimeruntimeoptionalRuntimeruntimeoptionalRuntimeRuntimeoptionalRuntimeRuntimeoptionalRuntime#
The runtime environment.

Default: Runtime.NODEJS_LATEST if the @aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion feature flag is enabled, otherwise Runtime.NODEJS_16_X

Only runtimes of the Node.js family are supported.

runtimeManagementModeoptionalRuntimeManagementModeruntime_management_modeoptionalRuntimeManagementModeruntimeManagementModeoptionalRuntimeManagementModeRuntimeManagementModeoptionalRuntimeManagementModeRuntimeManagementModeoptionalRuntimeManagementMode= Auto#
Sets the runtime management configuration for a function's version.
securityGroupsoptionalISecurityGroup[]security_groupsoptionaltyping.List[ISecurityGroup]securityGroupsoptionalList<ISecurityGroup>SecurityGroupsoptionalISecurityGroup[]SecurityGroupsoptional*[]ISecurityGroup#
The list of security groups to associate with the Lambda's network interfaces.

Default: If the function is placed within a VPC and a security group is not specified, either by this or securityGroup prop, a dedicated security group will be created for this function.

Only used if 'vpc' is supplied.

snapStartoptionalSnapStartConfsnap_startoptionalSnapStartConfsnapStartoptionalSnapStartConfSnapStartoptionalSnapStartConfSnapStartoptionalSnapStartConf#
Enable SnapStart for Lambda Function.

Default: No snapstart

SnapStart is currently supported for Java 11, Java 17, Python 3.12, Python 3.13, and .NET 8 runtime, as well as container image (OCI) deployments.

systemLogLeveloptionalstringsystem_log_leveloptionalstrsystemLogLeveloptionalStringSystemLogLeveloptionalstringSystemLogLeveloptional*string= "INFO"deprecated#
Use `systemLogLevelV2` as a property instead.
systemLogLevelV2optionalSystemLogLevelsystem_log_level_v2optionalSystemLogLevelsystemLogLevelV2optionalSystemLogLevelSystemLogLevelV2optionalSystemLogLevelSystemLogLevelV2optionalSystemLogLevel= SystemLogLevel.INFO#
Sets the system log level for the function.
tenancyConfigoptionalTenancyConfigtenancy_configoptionalTenancyConfigtenancyConfigoptionalTenancyConfigTenancyConfigoptionalTenancyConfigTenancyConfigoptionalTenancyConfig#
The tenancy configuration for the function.

Default: Tenant isolation is not enabled

timeoutoptionalDurationtimeoutoptionalDurationtimeoutoptionalDurationTimeoutoptionalDurationTimeoutoptionalDuration= Duration.seconds(3)#
The function execution time (in seconds) after which Lambda terminates the function.

Because the execution time affects cost, set this value based on the function's expected execution time.

tracingoptionalTracingtracingoptionalTracingtracingoptionalTracingTracingoptionalTracingTracingoptionalTracing= Tracing.Disabled#
Enable AWS X-Ray Tracing for Lambda Function.
vpcoptionalIVpcvpcoptionalIVpcvpcoptionalIVpcVpcoptionalIVpcVpcoptionalIVpc#
VPC network to place Lambda network interfaces.

Default: Function is not placed within a VPC.

Specify this if the Lambda function needs to access resources in a VPC. This is required when vpcSubnets is specified.

vpcSubnetsoptionalSubnetSelectionvpc_subnetsoptionalSubnetSelectionvpcSubnetsoptionalSubnetSelectionVpcSubnetsoptionalSubnetSelectionVpcSubnetsoptionalSubnetSelection#
Where to place the network interfaces within the VPC.

Default: the Vpc default strategy if not specified

notes

This requires vpc to be specified in order for interfaces to actually be placed in the subnets. If vpc is not specify, this will raise an error.

Note: Internet access for Lambda Functions requires a NAT Gateway, so picking public subnets is not allowed (unless allowPublicSubnet is set to true).