Class Code
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
,S3CodeV2
@Generated(value="jsii-pacmak/1.104.0 (build e79254c)",
date="2024-11-22T02:24:03.880Z")
@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();
-
Nested Class Summary
Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationMode
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract CodeConfig
bind
(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.void
bindToResource
(CfnResource _resource) Called after the CFN function resource has been created to allow the code class to bind to it.void
bindToResource
(CfnResource _resource, ResourceBindOptions _options) Called after the CFN function resource has been created to allow the code class to bind to it.static AssetCode
Loads the function code from a local disk path.static AssetCode
fromAsset
(String path, AssetOptions options) Loads the function code from a local disk path.static AssetImageCode
fromAssetImage
(String directory) Create an ECR image from the specified asset and bind it as the Lambda code.static AssetImageCode
fromAssetImage
(String directory, AssetImageCodeProps props) Create an ECR image from the specified asset and bind it as the Lambda code.static S3Code
fromBucket
(IBucket bucket, String key) Lambda handler code as an S3 object.static S3Code
fromBucket
(IBucket bucket, String key, String objectVersion) Lambda handler code as an S3 object.static S3CodeV2
fromBucketV2
(IBucket bucket, String key) Lambda handler code as an S3 object.static S3CodeV2
fromBucketV2
(IBucket bucket, String key, BucketOptions options) Lambda handler code as an S3 object.static CfnParametersCode
Creates a new Lambda source defined using CloudFormation parameters.static CfnParametersCode
Creates a new Lambda source defined using CloudFormation parameters.static AssetCode
fromCustomCommand
(String output, List<String> command) Runs a command to build the code asset that will be used.static AssetCode
fromCustomCommand
(String output, List<String> command, CustomCommandOptions options) Runs a command to build the code asset that will be used.static AssetCode
fromDockerBuild
(String path) Loads the function code from an asset created by a Docker build.static AssetCode
fromDockerBuild
(String path, DockerBuildAssetOptions options) Loads the function code from an asset created by a Docker build.static EcrImageCode
fromEcrImage
(IRepository repository) Use an existing ECR image as the Lambda code.static EcrImageCode
fromEcrImage
(IRepository repository, EcrImageCodeProps props) Use an existing ECR image as the Lambda code.static InlineCode
fromInline
(String code) Inline code for Lambda handler.Methods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
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
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
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.
-
fromBucketV2
@Stability(Stable) @NotNull public static S3CodeV2 fromBucketV2(@NotNull IBucket bucket, @NotNull String key, @Nullable BucketOptions options) Lambda handler code as an S3 object.- Parameters:
bucket
- The S3 bucket. This parameter is required.key
- The object key. This parameter is required.options
- Optional parameters for setting the code, current optional parameters to set here are 1.
-
fromBucketV2
@Stability(Stable) @NotNull public static S3CodeV2 fromBucketV2(@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 ofCfnParametersCode
.- Returns:
- a new instance of
CfnParametersCode
-
fromCfnParameters
Creates a new Lambda source defined using CloudFormation parameters.- Returns:
- a new instance of
CfnParametersCode
-
fromCustomCommand
@Stability(Stable) @NotNull public static AssetCode fromCustomCommand(@NotNull String output, @NotNull List<String> command, @Nullable CustomCommandOptions options) Runs a command to build the code asset that will be used.- Parameters:
output
- Where the output of the command will be directed, either a directory or a .zip file with the output Lambda code bundle * For example, if you use the command to run a build script (e.g., [ 'node', 'bundle_code.js' ]), and the build script generates a directory/my/lambda/code
containing code that should be ran in a Lambda function, then output should be set to/my/lambda/code
. This parameter is required.command
- The command which will be executed to generate the output, for example, [ 'node', 'bundle_code.js' ]. This parameter is required.options
- options for the custom command, and other asset options -- but bundling options are not allowed.
-
fromCustomCommand
@Stability(Stable) @NotNull public static AssetCode fromCustomCommand(@NotNull String output, @NotNull List<String> command) Runs a command to build the code asset that will be used.- Parameters:
output
- Where the output of the command will be directed, either a directory or a .zip file with the output Lambda code bundle * For example, if you use the command to run a build script (e.g., [ 'node', 'bundle_code.js' ]), and the build script generates a directory/my/lambda/code
containing code that should be ran in a Lambda function, then output should be set to/my/lambda/code
. This parameter is required.command
- The command which will be executed to generate the output, for example, [ 'node', 'bundle_code.js' ]. This parameter is required.
-
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
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
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
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.
-