NodejsFunctionProps Struct
Properties for a NodejsFunction.
Example
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
adotInstrumentationAdotInstrumentationConfigadot_instrumentationAdotInstrumentationConfigadotInstrumentationAdotInstrumentationConfigAdotInstrumentationAdotInstrumentationConfigAdotInstrumentationAdotInstrumentationConfig= No ADOT instrumentation#allowAllIpv6Outboundbooleanallow_all_ipv6_outboundboolallowAllIpv6OutboundBooleanAllowAllIpv6OutboundboolAllowAllIpv6Outbound*bool= false#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.
allowAllOutboundbooleanallow_all_outboundboolallowAllOutboundBooleanAllowAllOutboundboolAllowAllOutbound*bool= true#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.
allowPublicSubnetbooleanallow_public_subnetboolallowPublicSubnetBooleanAllowPublicSubnetboolAllowPublicSubnet*bool= false#Use this property to acknowledge this limitation and still place the function in a public subnet.
applicationLogLevelstringapplication_log_levelstrapplicationLogLevelStringApplicationLogLevelstringApplicationLogLevel*string= "INFO"deprecated#applicationLogLevelV2ApplicationLogLevelapplication_log_level_v2ApplicationLogLevelapplicationLogLevelV2ApplicationLogLevelApplicationLogLevelV2ApplicationLogLevelApplicationLogLevelV2ApplicationLogLevel= ApplicationLogLevel.INFO#architectureArchitecturearchitectureArchitecturearchitectureArchitectureArchitectureArchitectureArchitectureArchitecture= Architecture.X86_64#awsSdkConnectionReusebooleanaws_sdk_connection_reuseboolawsSdkConnectionReuseBooleanAwsSdkConnectionReuseboolAwsSdkConnectionReuse*bool= false (obsolete) for runtimes >=…#notes · default
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.
Default: false (obsolete) for runtimes >= Node 18, true for runtimes <= Node 16.
bundlingBundlingOptionsbundlingBundlingOptionsbundlingBundlingOptionsBundlingBundlingOptionsBundlingBundlingOptions= use default bundling options: no…#default
Default: use default bundling options: no minify, no sourcemap, all modules are bundled.
If included, then properties related to bundling of the code are ignored.
- If the
codefield is specified, then you must include thehandlerproperty.
codeSigningConfigICodeSigningConfigRefcode_signing_configICodeSigningConfigRefcodeSigningConfigICodeSigningConfigRefCodeSigningConfigICodeSigningConfigRefCodeSigningConfigICodeSigningConfigRef= Not Sign the Code#currentVersionOptionsVersionOptionscurrent_version_optionsVersionOptionscurrentVersionOptionsVersionOptionsCurrentVersionOptionsVersionOptionsCurrentVersionOptionsVersionOptions= default options as described in …#default
Default: default options as described in VersionOptions
deadLetterQueueIQueuedead_letter_queueIQueuedeadLetterQueueIQueueDeadLetterQueueIQueueDeadLetterQueueIQueue= SQS queue with 14 day retention …#If SNS topic is desired, specify deadLetterTopic property instead.
default
Default: SQS queue with 14 day retention period if deadLetterQueueEnabled is true
deadLetterQueueEnabledbooleandead_letter_queue_enabledbooldeadLetterQueueEnabledBooleanDeadLetterQueueEnabledboolDeadLetterQueueEnabled*bool= false unless `deadLetterQueue` i…#If deadLetterQueue is undefined, an SQS queue with default options will be defined for your Function.
default
Default: false unless deadLetterQueue is set, which implies DLQ is enabled.
deadLetterTopicITopicdead_letter_topicITopicdeadLetterTopicITopicDeadLetterTopicITopicDeadLetterTopicITopic= 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.
depsLockFilePathstringdeps_lock_file_pathstrdepsLockFilePathStringDepsLockFilePathstringDepsLockFilePath*string= the path is found by walking up …#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.
default
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
descriptionstringdescriptionstrdescriptionStringDescriptionstringDescription*string= No description.#durableConfigDurableConfigdurable_configDurableConfigdurableConfigDurableConfigDurableConfigDurableConfigDurableConfigDurableConfig= 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.
notes · default
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.
Default: (Realible in Node projects only) derived from the defining file's name and construct ID as described in the documentation.
environment{ [key: string]: string }environmenttyping.Mapping[str, str]environmentMap<String, String>EnvironmentIDictionary<string, string>Environment*map[string]*string= No environment variables.#Use environment variables to apply configuration changes, such as test and production environment configurations, without changing your Lambda function source code.
environmentEncryptionIKeyRefenvironment_encryptionIKeyRefenvironmentEncryptionIKeyRefEnvironmentEncryptionIKeyRefEnvironmentEncryptionIKeyRef= AWS Lambda creates and uses an A…#default
Default: AWS Lambda creates and uses an AWS managed customer master key (CMK).
ephemeralStorageSizeSizeephemeral_storage_sizeSizeephemeralStorageSizeSizeEphemeralStorageSizeSizeEphemeralStorageSizeSize= 512 MiB#eventsIEventSource[]eventstyping.List[IEventSource]eventsList<IEventSource>EventsIEventSource[]Events*[]IEventSource= No event sources.#You can also add event sources using addEventSource.
filesystemFileSystemfilesystemFileSystemfilesystemFileSystemFilesystemFileSystemFilesystemFileSystem= will not mount any filesystem#functionNamestringfunction_namestrfunctionNameStringFunctionNamestringFunctionName*string= AWS CloudFormation generates a u…#default
Default: AWS CloudFormation generates a unique physical ID and uses that ID for the function's name. For more information, see Name Type.
notes
If the
codeproperty is supplied, then you must include thehandlerproperty. 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 calledmyLambda.jsand the function to be invoked wasmyHandler, then you should inputhandlerproperty asmyLambda.myHandler.If the
codeproperty is not supplied and the handler input does not contain a., then the handler is prefixed withindex.(index period). Otherwise, the handler property is not modified.
initialPolicyPolicyStatement[]initial_policytyping.List[PolicyStatement]initialPolicyList<PolicyStatement>InitialPolicyPolicyStatement[]InitialPolicy*[]PolicyStatement= No policy statements are added t…#You can call addToRolePolicy to the created lambda to add statements post creation.
default
Default: No policy statements are added to the created Lambda role.
insightsVersionLambdaInsightsVersioninsights_versionLambdaInsightsVersioninsightsVersionLambdaInsightsVersionInsightsVersionLambdaInsightsVersionInsightsVersionLambdaInsightsVersion= No Lambda Insights#ipv6AllowedForDualStackbooleanipv6_allowed_for_dual_stackboolipv6AllowedForDualStackBooleanIpv6AllowedForDualStackboolIpv6AllowedForDualStack*bool= false#Only used if 'vpc' is supplied.
layersILayerVersion[]layerstyping.List[ILayerVersion]layersList<ILayerVersion>LayersILayerVersion[]Layers*[]ILayerVersion= 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.
loggingFormatLoggingFormatlogging_formatLoggingFormatloggingFormatLoggingFormatLoggingFormatLoggingFormatLoggingFormatLoggingFormat= LoggingFormat.TEXT#logGroupILogGroupReflog_groupILogGroupReflogGroupILogGroupRefLogGroupILogGroupRefLogGroupILogGroupRef= `/aws/lambda/${this.functionName…#notes · default
By default, Lambda functions send logs to an automatically created default log group named /aws/lambda/<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.
Default: /aws/lambda/${this.functionName} - default log group created by Lambda
logRemovalPolicyRemovalPolicylog_removal_policyRemovalPolicylogRemovalPolicyRemovalPolicyLogRemovalPolicyRemovalPolicyLogRemovalPolicyRemovalPolicy= RemovalPolicy.Retaindeprecated#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.
logRetentionRetentionDayslog_retentionRetentionDayslogRetentionRetentionDaysLogRetentionRetentionDaysLogRetentionRetentionDays= logs.RetentionDays.INFINITEdeprecated#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:
import * as logs from 'aws-cdk-lib/aws-logs';
declare const myLogGroup: logs.LogGroup;
myLogGroup.logGroupName;
logRetentionRetryOptionsLogRetentionRetryOptionslog_retention_retry_optionsLogRetentionRetryOptionslogRetentionRetryOptionsLogRetentionRetryOptionsLogRetentionRetryOptionsLogRetentionRetryOptionsLogRetentionRetryOptionsLogRetentionRetryOptions= 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.
logRetentionRoleIRolelog_retention_roleIRolelogRetentionRoleIRoleLogRetentionRoleIRoleLogRetentionRoleIRole= 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.
maxEventAgeDurationmax_event_ageDurationmaxEventAgeDurationMaxEventAgeDurationMaxEventAgeDuration= Duration.hours(6)#Minimum: 60 seconds Maximum: 6 hours
Lambda uses this value to proportionally allocate the amount of CPU power. For more information, see Resource Model in the AWS Lambda Developer Guide.
onFailureIDestinationon_failureIDestinationonFailureIDestinationOnFailureIDestinationOnFailureIDestination= no destination#onSuccessIDestinationon_successIDestinationonSuccessIDestinationOnSuccessIDestinationOnSuccessIDestination= no destination#paramsAndSecretsParamsAndSecretsLayerVersionparams_and_secretsParamsAndSecretsLayerVersionparamsAndSecretsParamsAndSecretsLayerVersionParamsAndSecretsParamsAndSecretsLayerVersionParamsAndSecretsParamsAndSecretsLayerVersion= No Parameters and Secrets Extens…#default
Default: No Parameters and Secrets Extension
profilingGroupIProfilingGroupprofiling_groupIProfilingGroupprofilingGroupIProfilingGroupProfilingGroupIProfilingGroupProfilingGroupIProfilingGroup= A new profiling group will be cr…#default
Default: A new profiling group will be created if profiling is set.
projectRootstringproject_rootstrprojectRootStringProjectRootstringProjectRoot*string= the directory containing the `de…#default
Default: the directory containing the depsLockFilePath
recursiveLoopRecursiveLooprecursive_loopRecursiveLooprecursiveLoopRecursiveLoopRecursiveLoopRecursiveLoopRecursiveLoopRecursiveLoop= RecursiveLoop.Terminate#It lets Lambda detect and terminate unintended recursive loops.
reservedConcurrentExecutionsnumberreserved_concurrent_executionsint | floatreservedConcurrentExecutionsNumberReservedConcurrentExecutionsdoubleReservedConcurrentExecutions*float64= No specific limit - account limi…#default
Default: No specific limit - account limit.
retryAttemptsnumberretry_attemptsint | floatretryAttemptsNumberRetryAttemptsdoubleRetryAttempts*float64= 2#Minimum: 0 Maximum: 2
notes · default
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".
Default: A unique role will be generated for this lambda function. Both supplied and generated roles can always be changed by calling addToRolePolicy.
runtimeRuntimeruntimeRuntimeruntimeRuntimeRuntimeRuntimeRuntimeRuntime= `Runtime.NODEJS_LATEST` if the `…#Only runtimes of the Node.js family are supported.
default
Default: Runtime.NODEJS_LATEST if the @aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion feature flag is enabled, otherwise Runtime.NODEJS_16_X
runtimeManagementModeRuntimeManagementModeruntime_management_modeRuntimeManagementModeruntimeManagementModeRuntimeManagementModeRuntimeManagementModeRuntimeManagementModeRuntimeManagementModeRuntimeManagementMode= Auto#securityGroupsISecurityGroup[]security_groupstyping.List[ISecurityGroup]securityGroupsList<ISecurityGroup>SecurityGroupsISecurityGroup[]SecurityGroups*[]ISecurityGroup= If the function is placed within…#Only used if 'vpc' is supplied.
default
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.
snapStartSnapStartConfsnap_startSnapStartConfsnapStartSnapStartConfSnapStartSnapStartConfSnapStartSnapStartConf= 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.
systemLogLevelstringsystem_log_levelstrsystemLogLevelStringSystemLogLevelstringSystemLogLevel*string= "INFO"deprecated#systemLogLevelV2SystemLogLevelsystem_log_level_v2SystemLogLevelsystemLogLevelV2SystemLogLevelSystemLogLevelV2SystemLogLevelSystemLogLevelV2SystemLogLevel= SystemLogLevel.INFO#tenancyConfigTenancyConfigtenancy_configTenancyConfigtenancyConfigTenancyConfigTenancyConfigTenancyConfigTenancyConfigTenancyConfig= Tenant isolation is not enabled#Because the execution time affects cost, set this value based on the function's expected execution time.
Specify this if the Lambda function needs to access resources in a VPC. This is required when vpcSubnets is specified.
default
Default: Function is not placed within a VPC.
vpcSubnetsSubnetSelectionvpc_subnetsSubnetSelectionvpcSubnetsSubnetSelectionVpcSubnetsSubnetSelectionVpcSubnetsSubnetSelection= the Vpc default strategy if not …#notes · default
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).
Default: the Vpc default strategy if not specified