Class NodejsFunctionProps.Builder

java.lang.Object
software.amazon.awscdk.services.lambda.nodejs.NodejsFunctionProps.Builder
All Implemented Interfaces:
software.amazon.jsii.Builder<NodejsFunctionProps>
Enclosing interface:
NodejsFunctionProps

@Stability(Stable) public static final class NodejsFunctionProps.Builder extends Object implements software.amazon.jsii.Builder<NodejsFunctionProps>
A builder for NodejsFunctionProps
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • awsSdkConnectionReuse

      @Stability(Stable) public NodejsFunctionProps.Builder awsSdkConnectionReuse(Boolean awsSdkConnectionReuse)
      Parameters:
      awsSdkConnectionReuse - The AWS_NODEJS_CONNECTION_REUSE_ENABLED environment variable does not exist in the AWS SDK for JavaScript v3. 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.

      Returns:
      this
    • bundling

      @Stability(Stable) public NodejsFunctionProps.Builder bundling(BundlingOptions bundling)
      Parameters:
      bundling - Bundling options.
      Returns:
      this
    • code

      @Stability(Stable) public NodejsFunctionProps.Builder code(Code code)
      Parameters:
      code - The code that will be deployed to the Lambda Handler. 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.
      Returns:
      this
    • depsLockFilePath

      @Stability(Stable) public NodejsFunctionProps.Builder depsLockFilePath(String depsLockFilePath)
      Parameters:
      depsLockFilePath - The path to the dependencies lock file (yarn.lock, pnpm-lock.yaml 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 (yarn, pnpm or npm) along with this lock file.

      Returns:
      this
    • entry

      @Stability(Stable) public NodejsFunctionProps.Builder entry(String entry)
      Parameters:
      entry - Path to the entry file (JavaScript or TypeScript).
      Returns:
      this
    • handler

      @Stability(Stable) public NodejsFunctionProps.Builder handler(String handler)
      Parameters:
      handler - The name of the exported handler in the entry file.
      • 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.
      Returns:
      this
    • projectRoot

      @Stability(Stable) public NodejsFunctionProps.Builder projectRoot(String projectRoot)
      Parameters:
      projectRoot - The path to the directory containing project config files (package.json or tsconfig.json).
      Returns:
      this
    • runtime

      @Stability(Stable) public NodejsFunctionProps.Builder runtime(Runtime runtime)
      Parameters:
      runtime - The runtime environment. Only runtimes of the Node.js family are supported.
      Returns:
      this
    • adotInstrumentation

      @Stability(Stable) public NodejsFunctionProps.Builder adotInstrumentation(AdotInstrumentationConfig adotInstrumentation)
      Parameters:
      adotInstrumentation - Specify the configuration of AWS Distro for OpenTelemetry (ADOT) instrumentation.
      Returns:
      this
    • allowAllIpv6Outbound

      @Stability(Stable) public NodejsFunctionProps.Builder allowAllIpv6Outbound(Boolean allowAllIpv6Outbound)
      Parameters:
      allowAllIpv6Outbound - Whether to allow the Lambda to send all ipv6 network traffic. 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.

      Returns:
      this
    • allowAllOutbound

      @Stability(Stable) public NodejsFunctionProps.Builder allowAllOutbound(Boolean allowAllOutbound)
      Parameters:
      allowAllOutbound - Whether to allow the Lambda to send all network traffic (except ipv6). 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.

      Returns:
      this
    • allowPublicSubnet

      @Stability(Stable) public NodejsFunctionProps.Builder allowPublicSubnet(Boolean allowPublicSubnet)
      Parameters:
      allowPublicSubnet - 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.
      Returns:
      this
    • applicationLogLevel

      @Stability(Deprecated) @Deprecated public NodejsFunctionProps.Builder applicationLogLevel(String applicationLogLevel)
      Deprecated.
      Use `applicationLogLevelV2` as a property instead.
      Parameters:
      applicationLogLevel - Sets the application log level for the function.
      Returns:
      this
    • applicationLogLevelV2

      @Stability(Stable) public NodejsFunctionProps.Builder applicationLogLevelV2(ApplicationLogLevel applicationLogLevelV2)
      Parameters:
      applicationLogLevelV2 - Sets the application log level for the function.
      Returns:
      this
    • architecture

      @Stability(Stable) public NodejsFunctionProps.Builder architecture(Architecture architecture)
      Parameters:
      architecture - The system architectures compatible with this lambda function.
      Returns:
      this
    • codeSigningConfig

      @Stability(Stable) public NodejsFunctionProps.Builder codeSigningConfig(ICodeSigningConfig codeSigningConfig)
      Parameters:
      codeSigningConfig - Code signing config associated with this function.
      Returns:
      this
    • currentVersionOptions

      @Stability(Stable) public NodejsFunctionProps.Builder currentVersionOptions(VersionOptions currentVersionOptions)
      Parameters:
      currentVersionOptions - Options for the lambda.Version resource automatically created by the fn.currentVersion method.
      Returns:
      this
    • deadLetterQueue

      @Stability(Stable) public NodejsFunctionProps.Builder deadLetterQueue(IQueue deadLetterQueue)
      Parameters:
      deadLetterQueue - The SQS queue to use if DLQ is enabled. If SNS topic is desired, specify deadLetterTopic property instead.
      Returns:
      this
    • deadLetterQueueEnabled

      @Stability(Stable) public NodejsFunctionProps.Builder deadLetterQueueEnabled(Boolean deadLetterQueueEnabled)
      Parameters:
      deadLetterQueueEnabled - Enabled DLQ. If deadLetterQueue is undefined, an SQS queue with default options will be defined for your Function.
      Returns:
      this
    • deadLetterTopic

      @Stability(Stable) public NodejsFunctionProps.Builder deadLetterTopic(ITopic deadLetterTopic)
      Parameters:
      deadLetterTopic - 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.
      Returns:
      this
    • description

      @Stability(Stable) public NodejsFunctionProps.Builder description(String description)
      Parameters:
      description - A description of the function.
      Returns:
      this
    • environment

      @Stability(Stable) public NodejsFunctionProps.Builder environment(Map<String,String> environment)
      Parameters:
      environment - 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.
      Returns:
      this
    • environmentEncryption

      @Stability(Stable) public NodejsFunctionProps.Builder environmentEncryption(IKey environmentEncryption)
      Parameters:
      environmentEncryption - The AWS KMS key that's used to encrypt your function's environment variables.
      Returns:
      this
    • ephemeralStorageSize

      @Stability(Stable) public NodejsFunctionProps.Builder ephemeralStorageSize(Size ephemeralStorageSize)
      Parameters:
      ephemeralStorageSize - The size of the function’s /tmp directory in MiB.
      Returns:
      this
    • events

      @Stability(Stable) public NodejsFunctionProps.Builder events(List<? extends IEventSource> events)
      Sets the value of FunctionOptions.getEvents()
      Parameters:
      events - Event sources for this function. You can also add event sources using addEventSource.
      Returns:
      this
    • filesystem

      @Stability(Stable) public NodejsFunctionProps.Builder filesystem(FileSystem filesystem)
      Parameters:
      filesystem - The filesystem configuration for the lambda function.
      Returns:
      this
    • functionName

      @Stability(Stable) public NodejsFunctionProps.Builder functionName(String functionName)
      Parameters:
      functionName - A name for the function.
      Returns:
      this
    • initialPolicy

      @Stability(Stable) public NodejsFunctionProps.Builder initialPolicy(List<? extends PolicyStatement> initialPolicy)
      Parameters:
      initialPolicy - Initial policy statements to add to the created Lambda Role. You can call addToRolePolicy to the created lambda to add statements post creation.
      Returns:
      this
    • insightsVersion

      @Stability(Stable) public NodejsFunctionProps.Builder insightsVersion(LambdaInsightsVersion insightsVersion)
      Parameters:
      insightsVersion - Specify the version of CloudWatch Lambda insights to use for monitoring.
      Returns:
      this
    • ipv6AllowedForDualStack

      @Stability(Stable) public NodejsFunctionProps.Builder ipv6AllowedForDualStack(Boolean ipv6AllowedForDualStack)
      Parameters:
      ipv6AllowedForDualStack - Allows outbound IPv6 traffic on VPC functions that are connected to dual-stack subnets. Only used if 'vpc' is supplied.
      Returns:
      this
    • layers

      @Stability(Stable) public NodejsFunctionProps.Builder layers(List<? extends ILayerVersion> layers)
      Sets the value of FunctionOptions.getLayers()
      Parameters:
      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.
      Returns:
      this
    • logFormat

      @Stability(Deprecated) @Deprecated public NodejsFunctionProps.Builder logFormat(String logFormat)
      Deprecated.
      Use `loggingFormat` as a property instead.
      Parameters:
      logFormat - Sets the logFormat for the function.
      Returns:
      this
    • loggingFormat

      @Stability(Stable) public NodejsFunctionProps.Builder loggingFormat(LoggingFormat loggingFormat)
      Parameters:
      loggingFormat - Sets the loggingFormat for the function.
      Returns:
      this
    • logGroup

      @Stability(Stable) public NodejsFunctionProps.Builder logGroup(ILogGroup logGroup)
      Parameters:
      logGroup - The log group the function sends logs to. By default, Lambda functions send logs to an automatically created default log group named /aws/lambda/. 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.

      Returns:
      this
    • logRetention

      @Stability(Stable) public NodejsFunctionProps.Builder logRetention(RetentionDays logRetention)
      Parameters:
      logRetention - 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.

      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 software.amazon.awscdk.services.logs.*;
                           
                           LogGroup myLogGroup;
                           
                           myLogGroup.getLogGroupName();
                           
      Returns:
      this
    • logRetentionRetryOptions

      @Stability(Stable) public NodejsFunctionProps.Builder logRetentionRetryOptions(LogRetentionRetryOptions logRetentionRetryOptions)
      Parameters:
      logRetentionRetryOptions - 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.

      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.

      Returns:
      this
    • logRetentionRole

      @Stability(Stable) public NodejsFunctionProps.Builder logRetentionRole(IRole logRetentionRole)
      Parameters:
      logRetentionRole - The IAM role for the Lambda function associated with the custom resource that sets the retention policy. 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.
      Returns:
      this
    • memorySize

      @Stability(Stable) public NodejsFunctionProps.Builder memorySize(Number memorySize)
      Parameters:
      memorySize - 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.
      Returns:
      this
    • paramsAndSecrets

      @Stability(Stable) public NodejsFunctionProps.Builder paramsAndSecrets(ParamsAndSecretsLayerVersion paramsAndSecrets)
      Parameters:
      paramsAndSecrets - Specify the configuration of Parameters and Secrets Extension.
      Returns:
      this
    • profiling

      @Stability(Stable) public NodejsFunctionProps.Builder profiling(Boolean profiling)
      Parameters:
      profiling - Enable profiling.
      Returns:
      this
    • profilingGroup

      @Stability(Stable) public NodejsFunctionProps.Builder profilingGroup(IProfilingGroup profilingGroup)
      Parameters:
      profilingGroup - Profiling Group.
      Returns:
      this
    • recursiveLoop

      @Stability(Stable) public NodejsFunctionProps.Builder recursiveLoop(RecursiveLoop recursiveLoop)
      Parameters:
      recursiveLoop - Sets the Recursive Loop Protection for Lambda Function. It lets Lambda detect and terminate unintended recusrive loops.
      Returns:
      this
    • reservedConcurrentExecutions

      @Stability(Stable) public NodejsFunctionProps.Builder reservedConcurrentExecutions(Number reservedConcurrentExecutions)
      Parameters:
      reservedConcurrentExecutions - The maximum of concurrent executions you want to reserve for the function.
      Returns:
      this
    • role

      @Stability(Stable) public NodejsFunctionProps.Builder role(IRole role)
      Sets the value of FunctionOptions.getRole()
      Parameters:
      role - 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".

      Returns:
      this
    • runtimeManagementMode

      @Stability(Stable) public NodejsFunctionProps.Builder runtimeManagementMode(RuntimeManagementMode runtimeManagementMode)
      Parameters:
      runtimeManagementMode - Sets the runtime management configuration for a function's version.
      Returns:
      this
    • securityGroups

      @Stability(Stable) public NodejsFunctionProps.Builder securityGroups(List<? extends ISecurityGroup> securityGroups)
      Parameters:
      securityGroups - The list of security groups to associate with the Lambda's network interfaces. Only used if 'vpc' is supplied.
      Returns:
      this
    • snapStart

      @Stability(Stable) public NodejsFunctionProps.Builder snapStart(SnapStartConf snapStart)
      Parameters:
      snapStart - Enable SnapStart for Lambda Function. SnapStart is currently supported only for Java 11, 17 runtime
      Returns:
      this
    • systemLogLevel

      @Stability(Deprecated) @Deprecated public NodejsFunctionProps.Builder systemLogLevel(String systemLogLevel)
      Deprecated.
      Use `systemLogLevelV2` as a property instead.
      Parameters:
      systemLogLevel - Sets the system log level for the function.
      Returns:
      this
    • systemLogLevelV2

      @Stability(Stable) public NodejsFunctionProps.Builder systemLogLevelV2(SystemLogLevel systemLogLevelV2)
      Parameters:
      systemLogLevelV2 - Sets the system log level for the function.
      Returns:
      this
    • timeout

      @Stability(Stable) public NodejsFunctionProps.Builder timeout(Duration timeout)
      Parameters:
      timeout - 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.
      Returns:
      this
    • tracing

      @Stability(Stable) public NodejsFunctionProps.Builder tracing(Tracing tracing)
      Parameters:
      tracing - Enable AWS X-Ray Tracing for Lambda Function.
      Returns:
      this
    • vpc

      @Stability(Stable) public NodejsFunctionProps.Builder vpc(IVpc vpc)
      Sets the value of FunctionOptions.getVpc()
      Parameters:
      vpc - VPC network to place Lambda network interfaces. Specify this if the Lambda function needs to access resources in a VPC. This is required when vpcSubnets is specified.
      Returns:
      this
    • vpcSubnets

      @Stability(Stable) public NodejsFunctionProps.Builder vpcSubnets(SubnetSelection vpcSubnets)
      Parameters:
      vpcSubnets - Where to place the network interfaces within the VPC. 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).

      Returns:
      this
    • maxEventAge

      @Stability(Stable) public NodejsFunctionProps.Builder maxEventAge(Duration maxEventAge)
      Parameters:
      maxEventAge - The maximum age of a request that Lambda sends to a function for processing. Minimum: 60 seconds Maximum: 6 hours
      Returns:
      this
    • onFailure

      @Stability(Stable) public NodejsFunctionProps.Builder onFailure(IDestination onFailure)
      Parameters:
      onFailure - The destination for failed invocations.
      Returns:
      this
    • onSuccess

      @Stability(Stable) public NodejsFunctionProps.Builder onSuccess(IDestination onSuccess)
      Parameters:
      onSuccess - The destination for successful invocations.
      Returns:
      this
    • retryAttempts

      @Stability(Stable) public NodejsFunctionProps.Builder retryAttempts(Number retryAttempts)
      Parameters:
      retryAttempts - The maximum number of times to retry when the function returns an error. Minimum: 0 Maximum: 2
      Returns:
      this
    • build

      @Stability(Stable) public NodejsFunctionProps build()
      Builds the configured instance.
      Specified by:
      build in interface software.amazon.jsii.Builder<NodejsFunctionProps>
      Returns:
      a new instance of NodejsFunctionProps
      Throws:
      NullPointerException - if any required attribute was not provided