interface NodejsFunctionProps
Language | Type name |
---|---|
![]() | Amazon.CDK.AWS.Lambda.Nodejs.NodejsFunctionProps |
![]() | software.amazon.awscdk.services.lambda.nodejs.NodejsFunctionProps |
![]() | aws_cdk.aws_lambda_nodejs.NodejsFunctionProps |
![]() | @aws-cdk/aws-lambda-nodejs » NodejsFunctionProps |
Properties for a NodejsFunction.
Example
new lambda.NodejsFunction(this, 'my-handler', {
bundling: {
minify: true, // minify code, defaults to false
sourceMap: true, // include source map, defaults to false
sourceMapMode: lambda.SourceMapMode.INLINE, // defaults to SourceMapMode.DEFAULT
sourcesContent: false, // do not include original source into source map, defaults to true
target: 'es2020', // target environment for the generated JavaScript code
loader: { // Use the 'dataurl' loader for '.png' files
'.png': 'dataurl',
},
define: { // Replace strings during build time
'process.env.API_KEY': JSON.stringify('xxx-xxxx-xxx'),
'process.env.PRODUCTION': JSON.stringify(true),
'process.env.NUMBER': JSON.stringify(123),
},
logLevel: lambda.LogLevel.SILENT, // defaults to LogLevel.WARNING
keepNames: true, // defaults to false
tsconfig: 'custom-tsconfig.json', // use custom-tsconfig.json instead of default,
metafile: true, // include meta file, defaults to false
banner: '/* comments */', // requires esbuild >= 0.9.0, defaults to none
footer: '/* comments */', // requires esbuild >= 0.9.0, defaults to none
charset: lambda.Charset.UTF8, // do not escape non-ASCII characters, defaults to Charset.ASCII
format: lambda.OutputFormat.ESM, // ECMAScript module output format, defaults to OutputFormat.CJS (OutputFormat.ESM requires Node.js 14.x)
mainFields: ['module', 'main'], // prefer ECMAScript versions of dependencies
inject: ['./my-shim.js', './other-shim.js'], // allows to automatically replace a global variable with an import from another file
esbuildArgs: { // Pass additional arguments to esbuild
"--log-limit": "0",
"--splitting": true,
},
},
});
Properties
Name | Type | Description |
---|---|---|
allow | boolean | Whether to allow the Lambda to send all network traffic. |
allow | boolean | Lambda Functions in a public subnet can NOT access the internet. |
architecture? | Architecture | The system architectures compatible with this lambda function. |
architectures? | Architecture [] | DEPRECATED. |
aws | boolean | Whether to automatically reuse TCP connections when working with the AWS SDK for JavaScript. |
bundling? | Bundling | Bundling options. |
code | ICode | Code signing config associated with this function. |
current | Version | Options for the lambda.Version resource automatically created by the fn.currentVersion method. |
dead | IQueue | The SQS queue to use if DLQ is enabled. |
dead | boolean | Enabled DLQ. |
dead | ITopic | The SNS topic to use as a DLQ. |
deps | string | The path to the dependencies lock file (yarn.lock or package-lock.json ). |
description? | string | A description of the function. |
entry? | string | Path to the entry file (JavaScript or TypeScript). |
environment? | { [string]: string } | Key-value pairs that Lambda caches and makes available for your Lambda functions. |
environment | IKey | The AWS KMS key that's used to encrypt your function's environment variables. |
ephemeral | Size | The size of the function’s /tmp directory in MiB. |
events? | IEvent [] | Event sources for this function. |
filesystem? | File | The filesystem configuration for the lambda function. |
function | string | A name for the function. |
handler? | string | The name of the exported handler in the entry file. |
initial | Policy [] | Initial policy statements to add to the created Lambda Role. |
insights | Lambda | Specify the version of CloudWatch Lambda insights to use for monitoring. |
layers? | ILayer [] | A list of layers to add to the function's execution environment. |
log | Retention | The number of days log events are kept in CloudWatch Logs. |
log | Log | When log retention is specified, a custom resource attempts to create the CloudWatch log group. |
log | IRole | The IAM role for the Lambda function associated with the custom resource that sets the retention policy. |
max | Duration | The maximum age of a request that Lambda sends to a function for processing. |
memory | number | The amount of memory, in MB, that is allocated to your Lambda function. |
on | IDestination | The destination for failed invocations. |
on | IDestination | The destination for successful invocations. |
profiling? | boolean | Enable profiling. |
profiling | IProfiling | Profiling Group. |
project | string | The path to the directory containing project config files (package.json or tsconfig.json ). |
reserved | number | The maximum of concurrent executions you want to reserve for the function. |
retry | number | The maximum number of times to retry when the function returns an error. |
role? | IRole | Lambda execution role. |
runtime? | Runtime | The runtime environment. |
security | ISecurity | What security group to associate with the Lambda's network interfaces. This property is being deprecated, consider using securityGroups instead. |
security | ISecurity [] | The list of security groups to associate with the Lambda's network interfaces. |
timeout? | Duration | The function execution time (in seconds) after which Lambda terminates the function. |
tracing? | Tracing | Enable AWS X-Ray Tracing for Lambda Function. |
vpc? | IVpc | VPC network to place Lambda network interfaces. |
vpc | Subnet | Where to place the network interfaces within the VPC. |
allowAllOutbound?
Type:
boolean
(optional, default: true)
Whether to allow the Lambda to send all network traffic.
If set to false, you must individually add traffic rules to allow the Lambda to connect to network targets.
allowPublicSubnet?
Type:
boolean
(optional, default: 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.
architecture?
Type:
Architecture
(optional, default: Architecture.X86_64)
The system architectures compatible with this lambda function.
architectures?
⚠️ Deprecated: use architecture
Type:
Architecture
[]
(optional, default: [Architecture.X86_64])
DEPRECATED.
awsSdkConnectionReuse?
Type:
boolean
(optional, default: true)
Whether to automatically reuse TCP connections when working with the AWS SDK for JavaScript.
This sets the AWS_NODEJS_CONNECTION_REUSE_ENABLED
environment variable
to 1
.
bundling?
Type:
Bundling
(optional, default: use default bundling options: no minify, no sourcemap, all
modules are bundled.)
Bundling options.
codeSigningConfig?
Type:
ICode
(optional, default: Not Sign the Code)
Code signing config associated with this function.
currentVersionOptions?
Type:
Version
(optional, default: default options as described in VersionOptions
)
Options for the lambda.Version
resource automatically created by the fn.currentVersion
method.
deadLetterQueue?
Type:
IQueue
(optional, default: SQS queue with 14 day retention period if deadLetterQueueEnabled
is true
)
The SQS queue to use if DLQ is enabled.
If SNS topic is desired, specify deadLetterTopic
property instead.
deadLetterQueueEnabled?
Type:
boolean
(optional, default: false unless deadLetterQueue
is set, which implies DLQ is enabled.)
Enabled DLQ.
If deadLetterQueue
is undefined,
an SQS queue with default options will be defined for your Function.
deadLetterTopic?
Type:
ITopic
(optional, default: no SNS topic)
The SNS topic to use as a DLQ.
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.
depsLockFilePath?
Type:
string
(optional, default: the path is found by walking up parent directories searching for
a yarn.lock
or package-lock.json
file)
The path to the dependencies lock file (yarn.lock
or package-lock.json
).
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 (npm
or yarn
) along with this lock file.
description?
Type:
string
(optional, default: No description.)
A description of the function.
entry?
Type:
string
(optional, default: Derived from the name of the defining file and the construct's id.
If the NodejsFunction
is defined in stack.ts
with my-handler
as id
(new NodejsFunction(this, 'my-handler')
), the construct will look at stack.my-handler.ts
and stack.my-handler.js
.)
Path to the entry file (JavaScript or TypeScript).
environment?
Type:
{ [string]: string }
(optional, default: No environment variables.)
Key-value pairs that Lambda caches and makes available for your Lambda functions.
Use environment variables to apply configuration changes, such as test and production environment configurations, without changing your Lambda function source code.
environmentEncryption?
Type:
IKey
(optional, default: AWS Lambda creates and uses an AWS managed customer master key (CMK).)
The AWS KMS key that's used to encrypt your function's environment variables.
ephemeralStorageSize?
Type:
Size
(optional, default: 512 MiB)
The size of the function’s /tmp directory in MiB.
events?
Type:
IEvent
[]
(optional, default: No event sources.)
Event sources for this function.
You can also add event sources using addEventSource
.
filesystem?
Type:
File
(optional, default: will not mount any filesystem)
The filesystem configuration for the lambda function.
functionName?
Type:
string
(optional, default: AWS CloudFormation generates a unique physical ID and uses that
ID for the function's name. For more information, see Name Type.)
A name for the function.
handler?
Type:
string
(optional, default: handler)
The name of the exported handler in the entry file.
initialPolicy?
Type:
Policy
[]
(optional, default: No policy statements are added to the created Lambda role.)
Initial policy statements to add to the created Lambda Role.
You can call addToRolePolicy
to the created lambda to add statements post creation.
insightsVersion?
Type:
Lambda
(optional, default: No Lambda Insights)
Specify the version of CloudWatch Lambda insights to use for monitoring.
layers?
Type:
ILayer
[]
(optional, default: No layers.)
A list of layers to add to the function's execution environment.
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.
logRetention?
Type:
Retention
(optional, default: logs.RetentionDays.INFINITE)
The number of days log events are kept in CloudWatch Logs.
When updating
this property, unsetting it doesn't remove the log retention policy. To
remove the retention policy, set the value to INFINITE
.
logRetentionRetryOptions?
Type:
Log
(optional, default: Default AWS SDK retry options.)
When log retention is specified, a custom resource attempts to create the CloudWatch log group.
These options control the retry policy when interacting with CloudWatch APIs.
logRetentionRole?
Type:
IRole
(optional, default: A new role is created.)
The IAM role for the Lambda function associated with the custom resource that sets the retention policy.
maxEventAge?
Type:
Duration
(optional, default: Duration.hours(6))
The maximum age of a request that Lambda sends to a function for processing.
Minimum: 60 seconds Maximum: 6 hours
memorySize?
Type:
number
(optional, default: 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.
onFailure?
Type:
IDestination
(optional, default: no destination)
The destination for failed invocations.
onSuccess?
Type:
IDestination
(optional, default: no destination)
The destination for successful invocations.
profiling?
Type:
boolean
(optional, default: No profiling.)
Enable profiling.
See also: https://docs.aws.amazon.com/codeguru/latest/profiler-ug/setting-up-lambda.html
profilingGroup?
Type:
IProfiling
(optional, default: A new profiling group will be created if profiling
is set.)
Profiling Group.
See also: https://docs.aws.amazon.com/codeguru/latest/profiler-ug/setting-up-lambda.html
projectRoot?
Type:
string
(optional, default: the directory containing the depsLockFilePath
)
The path to the directory containing project config files (package.json
or tsconfig.json
).
reservedConcurrentExecutions?
Type:
number
(optional, default: No specific limit - account limit.)
The maximum of concurrent executions you want to reserve for the function.
See also: https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html
retryAttempts?
Type:
number
(optional, default: 2)
The maximum number of times to retry when the function returns an error.
Minimum: 0 Maximum: 2
role?
Type:
IRole
(optional, default: A unique role will be generated for this lambda function.
Both supplied and generated roles can always be changed by calling addToRolePolicy
.)
Lambda execution role.
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".
runtime?
Type:
Runtime
(optional, default: Runtime.NODEJS_14_X)
The runtime environment.
Only runtimes of the Node.js family are supported.
securityGroup?
⚠️ Deprecated: - This property is deprecated, use securityGroups instead
Type:
ISecurity
(optional, default: If the function is placed within a VPC and a security group is
not specified, either by this or securityGroups prop, a dedicated security
group will be created for this function.)
What security group to associate with the Lambda's network interfaces. This property is being deprecated, consider using securityGroups instead.
Only used if 'vpc' is supplied.
Use securityGroups property instead. Function constructor will throw an error if both are specified.
securityGroups?
Type:
ISecurity
[]
(optional, 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.)
The list of security groups to associate with the Lambda's network interfaces.
Only used if 'vpc' is supplied.
timeout?
Type:
Duration
(optional, default: 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.
tracing?
Type:
Tracing
(optional, default: Tracing.Disabled)
Enable AWS X-Ray Tracing for Lambda Function.
vpc?
Type:
IVpc
(optional, default: Function is not placed within a VPC.)
VPC network to place Lambda network interfaces.
Specify this if the Lambda function needs to access resources in a VPC.
vpcSubnets?
Type:
Subnet
(optional, default: the Vpc default strategy if not specified)
Where to place the network interfaces within the VPC.
Only used if 'vpc' is supplied. Note: internet access for Lambdas requires a NAT gateway, so picking Public subnets is not allowed.