Skip to content
v2.273.0

EcrImageCode Class ​

Represents a Docker image in ECR that can be bound as Lambda Code.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_ecr as ecr } from 'aws-cdk-lib';
import { aws_lambda as lambda } from 'aws-cdk-lib';

declare const repository: ecr.Repository;
const ecrImageCode = new lambda.EcrImageCode(repository, /* all optional props */ {
  cmd: ['cmd'],
  entrypoint: ['entrypoint'],
  tag: 'tag',
  tagOrDigest: 'tagOrDigest',
  workingDirectory: 'workingDirectory',
});
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_ecr as ecr
from aws_cdk import aws_lambda as lambda_

# repository: ecr.Repository

ecr_image_code = lambda_.EcrImageCode(repository,
    cmd=["cmd"],
    entrypoint=["entrypoint"],
    tag="tag",
    tag_or_digest="tagOrDigest",
    working_directory="workingDirectory"
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.ecr.*;
import software.amazon.awscdk.services.lambda.*;

Repository repository;

EcrImageCode ecrImageCode = EcrImageCode.Builder.create(repository)
        .cmd(List.of("cmd"))
        .entrypoint(List.of("entrypoint"))
        .tag("tag")
        .tagOrDigest("tagOrDigest")
        .workingDirectory("workingDirectory")
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.ECR;
using Amazon.CDK.AWS.Lambda;

Repository repository;

var ecrImageCode = new EcrImageCode(repository, new EcrImageCodeProps {
    Cmd = new [] { "cmd" },
    Entrypoint = new [] { "entrypoint" },
    Tag = "tag",
    TagOrDigest = "tagOrDigest",
    WorkingDirectory = "workingDirectory"
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var repository Repository

ecrImageCode := awscdk.Aws_lambda.NewEcrImageCode(repository, &EcrImageCodeProps{
	Cmd: []*string{
		jsii.String("cmd"),
	},
	Entrypoint: []*string{
		jsii.String("entrypoint"),
	},
	Tag: jsii.String("tag"),
	TagOrDigest: jsii.String("tagOrDigest"),
	WorkingDirectory: jsii.String("workingDirectory"),
})

Initializer ​

ts
new EcrImageCode(repository: IRepository, props?: EcrImageCodeProps)
python
EcrImageCode(repository: IRepository, props: typing.Optional[EcrImageCodeProps] = None)
java
new EcrImageCode(IRepository repository, EcrImageCodeProps props)
csharp
new EcrImageCode(IRepository repository, EcrImageCodeProps? props = null)
go
NewEcrImageCode(Repository IRepository, Props EcrImageCodeProps)

Properties ​

isInlinebooleanis_inlineboolisInlineBooleanIsInlineboolIsInline*boolrequired#
Determines whether this Code is inline code or not.

Methods ​

bind(_scope: Construct): CodeConfigdef bind(self, _scope: Construct) -> CodeConfigpublic CodeConfig bind(Construct _scope)public CodeConfig Bind(Construct _scope)func Bind(_scope Construct) CodeConfig#
Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
bindToResource(_resource: CfnResource, _options?: ResourceBindOptions): voiddef bind_to_resource(self, _resource: CfnResource, _options: typing.Optional[ResourceBindOptions] = None) -> Nonepublic void bindToResource(CfnResource _resource, ResourceBindOptions _options)public void BindToResource(CfnResource _resource, ResourceBindOptions? _options = null)func BindToResource(_resource CfnResource, _options ResourceBindOptions)#
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.

fromAsset(path: string, options?: AssetOptions): AssetCode@staticmethod def from_asset(path: str, options: typing.Optional[AssetOptions] = None) -> AssetCodepublic static AssetCode fromAsset(String path, AssetOptions options)public static AssetCode FromAsset(string path, AssetOptions? options = null)func FromAsset(Path *string, Options AssetOptions) AssetCodestatic#
Loads the function code from a local disk path.
1 parameter

Parameters

  • pathpathpathpathPath — Either a directory with the Lambda code bundle or a .zip file.
fromAssetImage(directory: string, props?: AssetImageCodeProps): AssetImageCode@staticmethod def from_asset_image(directory: str, props: typing.Optional[AssetImageCodeProps] = None) -> AssetImageCodepublic static AssetImageCode fromAssetImage(String directory, AssetImageCodeProps props)public static AssetImageCode FromAssetImage(string directory, AssetImageCodeProps? props = null)func FromAssetImage(Directory *string, Props AssetImageCodeProps) AssetImageCodestatic#
Create an ECR image from the specified asset and bind it as the Lambda code.
2 parameters

Parameters

  • directorydirectorydirectorydirectoryDirectory — the directory from which the asset must be created.
  • propspropspropspropsProps — properties to further configure the selected image.
fromBucket(bucket: IBucket, key: string, objectVersion?: string): S3Code@staticmethod def from_bucket(bucket: IBucket, key: str, object_version: typing.Optional[str] = None) -> S3Codepublic static S3Code fromBucket(IBucket bucket, String key, String objectVersion)public static S3Code FromBucket(IBucket bucket, string key, string? objectVersion = null)func FromBucket(Bucket IBucket, Key *string, ObjectVersion *string) S3Codestatic#
Lambda handler code as an S3 object.
notes · 3 parameters

Note: If objectVersion is 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

  • bucketbucketbucketbucketBucket — The S3 bucket.
  • keykeykeykeyKey — The object key.
  • objectVersionobject_versionobjectVersionobjectVersionObjectVersion — Optional S3 object version.
fromBucketV2(bucket: IBucket, key: string, options?: BucketOptions): S3CodeV2@staticmethod def from_bucket_v2(bucket: IBucket, key: str, options: typing.Optional[BucketOptions] = None) -> S3CodeV2public static S3CodeV2 fromBucketV2(IBucket bucket, String key, BucketOptions options)public static S3CodeV2 FromBucketV2(IBucket bucket, string key, BucketOptions? options = null)func FromBucketV2(Bucket IBucket, Key *string, Options BucketOptions) S3CodeV2static#
Lambda handler code as an S3 object.
notes · 3 parameters

Note: If options.objectVersion is 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

  • bucketbucketbucketbucketBucket — The S3 bucket.
  • keykeykeykeyKey — The object key.
  • optionsoptionsoptionsoptionsOptions — Optional parameters for setting the code, current optional parameters to set here are 1.
fromCfnParameters(props?: CfnParametersCodeProps): CfnParametersCode@staticmethod def from_cfn_parameters(props: typing.Optional[CfnParametersCodeProps] = None) -> CfnParametersCodepublic static CfnParametersCode fromCfnParameters(CfnParametersCodeProps props)public static CfnParametersCode FromCfnParameters(CfnParametersCodeProps? props = null)func FromCfnParameters(Props CfnParametersCodeProps) CfnParametersCodestatic#
Creates a new Lambda source defined using CloudFormation parameters.
1 parameter · returns

Parameters

  • propspropspropspropsProps — optional construction properties of CfnParametersCode.

Returns: a new instance of CfnParametersCode

fromCustomCommand(output: string, command: string[], options?: CustomCommandOptions): AssetCode@staticmethod def from_custom_command(output: str, command: typing.List[str], options: typing.Optional[CustomCommandOptions] = None) -> AssetCodepublic static AssetCode fromCustomCommand(String output, List<String> command, CustomCommandOptions options)public static AssetCode FromCustomCommand(string output, string[] command, CustomCommandOptions? options = null)func FromCustomCommand(Output *string, Command *[]*string, Options CustomCommandOptions) AssetCodestatic#
Runs a command to build the code asset that will be used.
3 parameters

Parameters

  • outputoutputoutputoutputOutput — 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.
  • commandcommandcommandcommandCommand — The command which will be executed to generate the output, for example, [ 'node', 'bundle_code.js' ].
  • optionsoptionsoptionsoptionsOptions — options for the custom command, and other asset options -- but bundling options are not allowed.
fromDockerBuild(path: string, options?: DockerBuildAssetOptions): AssetCode@staticmethod def from_docker_build(path: str, options: typing.Optional[DockerBuildAssetOptions] = None) -> AssetCodepublic static AssetCode fromDockerBuild(String path, DockerBuildAssetOptions options)public static AssetCode FromDockerBuild(string path, DockerBuildAssetOptions? options = null)func FromDockerBuild(Path *string, Options DockerBuildAssetOptions) AssetCodestatic#
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.

2 parameters

Parameters

  • pathpathpathpathPath — The path to the directory containing the Docker file.
  • optionsoptionsoptionsoptionsOptions — Docker build options.
fromEcrImage(repository: IRepository, props?: EcrImageCodeProps): EcrImageCode // chainable@staticmethod def from_ecr_image(repository: IRepository, props: typing.Optional[EcrImageCodeProps] = None) -> EcrImageCodepublic static EcrImageCode fromEcrImage(IRepository repository, EcrImageCodeProps props)public static EcrImageCode FromEcrImage(IRepository repository, EcrImageCodeProps? props = null)func FromEcrImage(Repository IRepository, Props EcrImageCodeProps) EcrImageCodestatic#
Use an existing ECR image as the Lambda code.
2 parameters

Parameters

  • repositoryrepositoryrepositoryrepositoryRepository — the ECR repository that the image is in.
  • propspropspropspropsProps — properties to further configure the selected image.
fromInline(code: string): InlineCode@staticmethod def from_inline(code: str) -> InlineCodepublic static InlineCode fromInline(String code)public static InlineCode FromInline(string code)func FromInline(Code *string) InlineCodestatic#
Inline code for Lambda handler.
1 parameter · returns

Parameters

  • codecodecodecodeCode — The actual handler code (the resulting zip file cannot exceed 4MB).

Returns: LambdaInlineCode with inline code.