Class Code
- All Implemented Interfaces:
- software.amazon.jsii.JsiiSerializable
- Direct Known Subclasses:
- AssetCode,- AssetImageCode,- CfnParametersCode,- EcrImageCode,- InlineCode,- S3Code,- S3CodeV2
Example:
 // Create or reference an existing L1 CfnApplicationInferenceProfile
 CfnApplicationInferenceProfile cfnProfile = CfnApplicationInferenceProfile.Builder.create(this, "CfnProfile")
         .inferenceProfileName("my-cfn-profile")
         .modelSource(InferenceProfileModelSourceProperty.builder()
                 .copyFrom(BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V1_0.getInvokableArn())
                 .build())
         .description("Profile created via L1 construct")
         .build();
 // Import the L1 construct as an L2 ApplicationInferenceProfile
 IInferenceProfile importedFromCfn = ApplicationInferenceProfile.fromCfnApplicationInferenceProfile(cfnProfile);
 // Grant permissions to use the imported profile
 Function lambdaFunction = Function.Builder.create(this, "MyFunction")
         .runtime(Runtime.PYTHON_3_11)
         .handler("index.handler")
         .code(Code.fromInline("def handler(event, context): return \"Hello\""))
         .build();
 importedFromCfn.grantProfileUsage(lambdaFunction);
 - 
Nested Class SummaryNested classes/interfaces inherited from class software.amazon.jsii.JsiiObjectsoftware.amazon.jsii.JsiiObject.InitializationMode
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionabstract CodeConfigbind(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.voidbindToResource(CfnResource _resource) Called after the CFN function resource has been created to allow the code class to bind to it.voidbindToResource(CfnResource _resource, ResourceBindOptions _options) Called after the CFN function resource has been created to allow the code class to bind to it.static AssetCodeLoads the function code from a local disk path.static AssetCodefromAsset(String path, AssetOptions options) Loads the function code from a local disk path.static AssetImageCodefromAssetImage(String directory) Create an ECR image from the specified asset and bind it as the Lambda code.static AssetImageCodefromAssetImage(String directory, AssetImageCodeProps props) Create an ECR image from the specified asset and bind it as the Lambda code.static S3CodefromBucket(IBucket bucket, String key) Lambda handler code as an S3 object.static S3CodefromBucket(IBucket bucket, String key, String objectVersion) Lambda handler code as an S3 object.static S3CodeV2fromBucketV2(IBucket bucket, String key) Lambda handler code as an S3 object.static S3CodeV2fromBucketV2(IBucket bucket, String key, BucketOptions options) Lambda handler code as an S3 object.static CfnParametersCodeCreates a new Lambda source defined using CloudFormation parameters.static CfnParametersCodeCreates a new Lambda source defined using CloudFormation parameters.static AssetCodefromCustomCommand(String output, List<String> command) Runs a command to build the code asset that will be used.static AssetCodefromCustomCommand(String output, List<String> command, CustomCommandOptions options) Runs a command to build the code asset that will be used.static AssetCodefromDockerBuild(String path) Loads the function code from an asset created by a Docker build.static AssetCodefromDockerBuild(String path, DockerBuildAssetOptions options) Loads the function code from an asset created by a Docker build.static EcrImageCodefromEcrImage(IRepository repository) Use an existing ECR image as the Lambda code.static EcrImageCodefromEcrImage(IRepository repository, EcrImageCodeProps props) Use an existing ECR image as the Lambda code.static InlineCodefromInline(String code) Inline code for Lambda handler.Methods inherited from class software.amazon.jsii.JsiiObjectjsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface software.amazon.jsii.JsiiSerializable$jsii$toJson
- 
Constructor Details- 
Codeprotected Code(software.amazon.jsii.JsiiObjectRef objRef) 
- 
Codeprotected 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-
 
- 
fromAssetLoads 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.
 
- 
fromAssetImageCreate 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.Note: If objectVersionis not defined, the lambda will not be updated automatically if the code in the bucket is updated. This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set objectVersion.- 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.Note: If objectVersionis not defined, the lambda will not be updated automatically if the code in the bucket is updated. This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set objectVersion.- 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.Note: If options.objectVersionis not defined, the lambda will not be updated automatically if the code in the bucket is updated. This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set objectVersion.- 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.Note: If options.objectVersionis not defined, the lambda will not be updated automatically if the code in the bucket is updated. This is because CDK/Cloudformation does not track changes on the source S3 Bucket. It is recommended to either use S3Code.fromAsset() instead or set objectVersion.- 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
 
- 
fromCfnParametersCreates 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/codecontaining 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/codecontaining 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 /assetin the image.- Parameters:
- path- The path to the directory containing the Docker file. This parameter is required.
- options- Docker build options.
 
- 
fromDockerBuildLoads the function code from an asset created by a Docker build.By default, the asset is expected to be located at /assetin 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.
 
- 
fromInlineInline code for Lambda handler.- Parameters:
- code- The actual handler code (the resulting zip file cannot exceed 4MB). This parameter is required.
- Returns:
- LambdaInlineCodewith 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-
 
- 
bindToResourceCalled 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.
 
 
-