java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.lambda.Code
All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable
Direct Known Subclasses:
AssetCode, AssetImageCode, CfnParametersCode, EcrImageCode, InlineCode, S3Code

@Generated(value="jsii-pacmak/1.97.0 (build 729de35)", date="2024-04-18T17:54:19.188Z") @Stability(Stable) public abstract class Code extends software.amazon.jsii.JsiiObject
Represents the Lambda Handler Code.

Example:

 import software.amazon.awscdk.services.signer.*;
 SigningProfile signingProfile = SigningProfile.Builder.create(this, "SigningProfile")
         .platform(Platform.AWS_LAMBDA_SHA384_ECDSA)
         .build();
 CodeSigningConfig codeSigningConfig = CodeSigningConfig.Builder.create(this, "CodeSigningConfig")
         .signingProfiles(List.of(signingProfile))
         .build();
 Function.Builder.create(this, "Function")
         .codeSigningConfig(codeSigningConfig)
         .runtime(Runtime.NODEJS_18_X)
         .handler("index.handler")
         .code(Code.fromAsset(join(__dirname, "lambda-handler")))
         .build();
 
  • Constructor Details

    • Code

      protected Code(software.amazon.jsii.JsiiObjectRef objRef)
    • Code

      protected Code(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • Code

      @Stability(Stable) protected Code()
  • Method Details

    • fromAsset

      @Stability(Stable) @NotNull public static AssetCode fromAsset(@NotNull String path, @Nullable AssetOptions options)
      Loads the function code from a local disk path.

      Parameters:
      path - Either a directory with the Lambda code bundle or a .zip file. This parameter is required.
      options -
    • fromAsset

      @Stability(Stable) @NotNull public static AssetCode fromAsset(@NotNull String path)
      Loads the function code from a local disk path.

      Parameters:
      path - Either a directory with the Lambda code bundle or a .zip file. This parameter is required.
    • fromAssetImage

      @Stability(Stable) @NotNull public static AssetImageCode fromAssetImage(@NotNull String directory, @Nullable AssetImageCodeProps props)
      Create an ECR image from the specified asset and bind it as the Lambda code.

      Parameters:
      directory - the directory from which the asset must be created. This parameter is required.
      props - properties to further configure the selected image.
    • fromAssetImage

      @Stability(Stable) @NotNull public static AssetImageCode fromAssetImage(@NotNull String directory)
      Create an ECR image from the specified asset and bind it as the Lambda code.

      Parameters:
      directory - the directory from which the asset must be created. This parameter is required.
    • fromBucket

      @Stability(Stable) @NotNull public static S3Code fromBucket(@NotNull IBucket bucket, @NotNull String key, @Nullable String objectVersion)
      Lambda handler code as an S3 object.

      Parameters:
      bucket - The S3 bucket. This parameter is required.
      key - The object key. This parameter is required.
      objectVersion - Optional S3 object version.
    • fromBucket

      @Stability(Stable) @NotNull public static S3Code fromBucket(@NotNull IBucket bucket, @NotNull String key)
      Lambda handler code as an S3 object.

      Parameters:
      bucket - The S3 bucket. This parameter is required.
      key - The object key. This parameter is required.
    • fromCfnParameters

      @Stability(Stable) @NotNull public static CfnParametersCode fromCfnParameters(@Nullable CfnParametersCodeProps props)
      Creates a new Lambda source defined using CloudFormation parameters.

      Parameters:
      props - optional construction properties of CfnParametersCode.
      Returns:
      a new instance of CfnParametersCode
    • fromCfnParameters

      @Stability(Stable) @NotNull public static CfnParametersCode fromCfnParameters()
      Creates a new Lambda source defined using CloudFormation parameters.

      Returns:
      a new instance of CfnParametersCode
    • fromDockerBuild

      @Stability(Stable) @NotNull public static AssetCode fromDockerBuild(@NotNull String path, @Nullable DockerBuildAssetOptions options)
      Loads the function code from an asset created by a Docker build.

      By default, the asset is expected to be located at /asset in the image.

      Parameters:
      path - The path to the directory containing the Docker file. This parameter is required.
      options - Docker build options.
    • fromDockerBuild

      @Stability(Stable) @NotNull public static AssetCode fromDockerBuild(@NotNull String path)
      Loads the function code from an asset created by a Docker build.

      By default, the asset is expected to be located at /asset in the image.

      Parameters:
      path - The path to the directory containing the Docker file. This parameter is required.
    • fromEcrImage

      @Stability(Stable) @NotNull public static EcrImageCode fromEcrImage(@NotNull IRepository repository, @Nullable EcrImageCodeProps props)
      Use an existing ECR image as the Lambda code.

      Parameters:
      repository - the ECR repository that the image is in. This parameter is required.
      props - properties to further configure the selected image.
    • fromEcrImage

      @Stability(Stable) @NotNull public static EcrImageCode fromEcrImage(@NotNull IRepository repository)
      Use an existing ECR image as the Lambda code.

      Parameters:
      repository - the ECR repository that the image is in. This parameter is required.
    • fromInline

      @Stability(Stable) @NotNull public static InlineCode fromInline(@NotNull String code)
      Inline code for Lambda handler.

      Parameters:
      code - The actual handler code (limited to 4KiB). This parameter is required.
      Returns:
      LambdaInlineCode with inline code.
    • bind

      @Stability(Stable) @NotNull public abstract CodeConfig bind(@NotNull software.constructs.Construct scope)
      Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.

      Parameters:
      scope - The binding scope. This parameter is required.
    • bindToResource

      @Stability(Stable) public void bindToResource(@NotNull CfnResource _resource, @Nullable ResourceBindOptions _options)
      Called after the CFN function resource has been created to allow the code class to bind to it.

      Specifically it's required to allow assets to add metadata for tooling like SAM CLI to be able to find their origins.

      Parameters:
      _resource - This parameter is required.
      _options -
    • bindToResource

      @Stability(Stable) public void bindToResource(@NotNull CfnResource _resource)
      Called after the CFN function resource has been created to allow the code class to bind to it.

      Specifically it's required to allow assets to add metadata for tooling like SAM CLI to be able to find their origins.

      Parameters:
      _resource - This parameter is required.