# AssetImageCode

Represents an ECR image that will be constructed from the specified asset and can be bound as Lambda code.

Extends: [Code](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Code.html) › AssetImageCode
Obtainable from: [Code.fromAssetImage](/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Code.html#fromassetimage)

- Source: [`aws-lambda/lib/code.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-lambda/lib/code.ts#L785)

## Example

TypeScript:

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

declare const networkMode: ecr_assets.NetworkMode;
declare const platform: ecr_assets.Platform;
const assetImageCode = new lambda.AssetImageCode('directory', {
  assetName: 'assetName',
  buildArgs: {
    buildArgsKey: 'buildArgs',
  },
  buildContexts: {
    buildContextsKey: 'buildContexts',
  },
  buildSecrets: {
    buildSecretsKey: 'buildSecrets',
  },
  buildSsh: 'buildSsh',
  cacheDisabled: false,
  cacheFrom: [{
    type: 'type',

    // the properties below are optional
    params: {
      paramsKey: 'params',
    },
  }],
  cacheTo: {
    type: 'type',

    // the properties below are optional
    params: {
      paramsKey: 'params',
    },
  },
  cmd: ['cmd'],
  displayName: 'displayName',
  entrypoint: ['entrypoint'],
  exclude: ['exclude'],
  extraHash: 'extraHash',
  file: 'file',
  followSymlinks: cdk.SymlinkFollowMode.NEVER,
  ignoreMode: cdk.IgnoreMode.GLOB,
  invalidation: {
    buildArgs: false,
    buildContexts: false,
    buildSecrets: false,
    buildSsh: false,
    extraHash: false,
    file: false,
    networkMode: false,
    outputs: false,
    platform: false,
    repositoryName: false,
    target: false,
  },
  networkMode: networkMode,
  outputs: ['outputs'],
  platform: platform,
  target: 'target',
  workingDirectory: 'workingDirectory',
});
```

Python:

```python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
import aws_cdk as cdk
from aws_cdk import aws_ecr_assets as ecr_assets
from aws_cdk import aws_lambda as lambda_

# network_mode: ecr_assets.NetworkMode
# platform: ecr_assets.Platform

asset_image_code = lambda_.AssetImageCode("directory",
    asset_name="assetName",
    build_args={
        "build_args_key": "buildArgs"
    },
    build_contexts={
        "build_contexts_key": "buildContexts"
    },
    build_secrets={
        "build_secrets_key": "buildSecrets"
    },
    build_ssh="buildSsh",
    cache_disabled=False,
    cache_from=[ecr_assets.DockerCacheOption(
        type="type",

        # the properties below are optional
        params={
            "params_key": "params"
        }
    )],
    cache_to=ecr_assets.DockerCacheOption(
        type="type",

        # the properties below are optional
        params={
            "params_key": "params"
        }
    ),
    cmd=["cmd"],
    display_name="displayName",
    entrypoint=["entrypoint"],
    exclude=["exclude"],
    extra_hash="extraHash",
    file="file",
    follow_symlinks=cdk.SymlinkFollowMode.NEVER,
    ignore_mode=cdk.IgnoreMode.GLOB,
    invalidation=ecr_assets.DockerImageAssetInvalidationOptions(
        build_args=False,
        build_contexts=False,
        build_secrets=False,
        build_ssh=False,
        extra_hash=False,
        file=False,
        network_mode=False,
        outputs=False,
        platform=False,
        repository_name=False,
        target=False
    ),
    network_mode=network_mode,
    outputs=["outputs"],
    platform=platform,
    target="target",
    working_directory="workingDirectory"
)
```

Java:

```java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.*;
import software.amazon.awscdk.services.ecr.assets.*;
import software.amazon.awscdk.services.lambda.*;

NetworkMode networkMode;
Platform platform;

AssetImageCode assetImageCode = AssetImageCode.Builder.create("directory")
        .assetName("assetName")
        .buildArgs(Map.of(
                "buildArgsKey", "buildArgs"))
        .buildContexts(Map.of(
                "buildContextsKey", "buildContexts"))
        .buildSecrets(Map.of(
                "buildSecretsKey", "buildSecrets"))
        .buildSsh("buildSsh")
        .cacheDisabled(false)
        .cacheFrom(List.of(DockerCacheOption.builder()
                .type("type")

                // the properties below are optional
                .params(Map.of(
                        "paramsKey", "params"))
                .build()))
        .cacheTo(DockerCacheOption.builder()
                .type("type")

                // the properties below are optional
                .params(Map.of(
                        "paramsKey", "params"))
                .build())
        .cmd(List.of("cmd"))
        .displayName("displayName")
        .entrypoint(List.of("entrypoint"))
        .exclude(List.of("exclude"))
        .extraHash("extraHash")
        .file("file")
        .followSymlinks(SymlinkFollowMode.NEVER)
        .ignoreMode(IgnoreMode.GLOB)
        .invalidation(DockerImageAssetInvalidationOptions.builder()
                .buildArgs(false)
                .buildContexts(false)
                .buildSecrets(false)
                .buildSsh(false)
                .extraHash(false)
                .file(false)
                .networkMode(false)
                .outputs(false)
                .platform(false)
                .repositoryName(false)
                .target(false)
                .build())
        .networkMode(networkMode)
        .outputs(List.of("outputs"))
        .platform(platform)
        .target("target")
        .workingDirectory("workingDirectory")
        .build();
```

C# / .NET:

```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;
using Amazon.CDK.AWS.Ecr.Assets;
using Amazon.CDK.AWS.Lambda;

NetworkMode networkMode;
Platform platform;

var assetImageCode = new AssetImageCode("directory", new AssetImageCodeProps {
    AssetName = "assetName",
    BuildArgs = new Dictionary<string, string> {
        { "buildArgsKey", "buildArgs" }
    },
    BuildContexts = new Dictionary<string, string> {
        { "buildContextsKey", "buildContexts" }
    },
    BuildSecrets = new Dictionary<string, string> {
        { "buildSecretsKey", "buildSecrets" }
    },
    BuildSsh = "buildSsh",
    CacheDisabled = false,
    CacheFrom = new [] { new DockerCacheOption {
        Type = "type",

        // the properties below are optional
        Params = new Dictionary<string, string> {
            { "paramsKey", "params" }
        }
    } },
    CacheTo = new DockerCacheOption {
        Type = "type",

        // the properties below are optional
        Params = new Dictionary<string, string> {
            { "paramsKey", "params" }
        }
    },
    Cmd = new [] { "cmd" },
    DisplayName = "displayName",
    Entrypoint = new [] { "entrypoint" },
    Exclude = new [] { "exclude" },
    ExtraHash = "extraHash",
    File = "file",
    FollowSymlinks = SymlinkFollowMode.NEVER,
    IgnoreMode = IgnoreMode.GLOB,
    Invalidation = new DockerImageAssetInvalidationOptions {
        BuildArgs = false,
        BuildContexts = false,
        BuildSecrets = false,
        BuildSsh = false,
        ExtraHash = false,
        File = false,
        NetworkMode = false,
        Outputs = false,
        Platform = false,
        RepositoryName = false,
        Target = false
    },
    NetworkMode = networkMode,
    Outputs = new [] { "outputs" },
    Platform = platform,
    Target = "target",
    WorkingDirectory = "workingDirectory"
});
```

Golang:

```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"
import "github.com/aws/aws-cdk-go/awscdk"

var networkMode NetworkMode
var platform Platform

assetImageCode := awscdk.Aws_lambda.NewAssetImageCode(jsii.String("directory"), &AssetImageCodeProps{
	AssetName: jsii.String("assetName"),
	BuildArgs: map[string]*string{
		"buildArgsKey": jsii.String("buildArgs"),
	},
	BuildContexts: map[string]*string{
		"buildContextsKey": jsii.String("buildContexts"),
	},
	BuildSecrets: map[string]*string{
		"buildSecretsKey": jsii.String("buildSecrets"),
	},
	BuildSsh: jsii.String("buildSsh"),
	CacheDisabled: jsii.Boolean(false),
	CacheFrom: []DockerCacheOption{
		&DockerCacheOption{
			Type: jsii.String("type"),

			// the properties below are optional
			Params: map[string]*string{
				"paramsKey": jsii.String("params"),
			},
		},
	},
	CacheTo: &DockerCacheOption{
		Type: jsii.String("type"),

		// the properties below are optional
		Params: map[string]*string{
			"paramsKey": jsii.String("params"),
		},
	},
	Cmd: []*string{
		jsii.String("cmd"),
	},
	DisplayName: jsii.String("displayName"),
	Entrypoint: []*string{
		jsii.String("entrypoint"),
	},
	Exclude: []*string{
		jsii.String("exclude"),
	},
	ExtraHash: jsii.String("extraHash"),
	File: jsii.String("file"),
	FollowSymlinks: cdk.SymlinkFollowMode_NEVER,
	IgnoreMode: cdk.IgnoreMode_GLOB,
	Invalidation: &DockerImageAssetInvalidationOptions{
		BuildArgs: jsii.Boolean(false),
		BuildContexts: jsii.Boolean(false),
		BuildSecrets: jsii.Boolean(false),
		BuildSsh: jsii.Boolean(false),
		ExtraHash: jsii.Boolean(false),
		File: jsii.Boolean(false),
		NetworkMode: jsii.Boolean(false),
		Outputs: jsii.Boolean(false),
		Platform: jsii.Boolean(false),
		RepositoryName: jsii.Boolean(false),
		Target: jsii.Boolean(false),
	},
	NetworkMode: networkMode,
	Outputs: []*string{
		jsii.String("outputs"),
	},
	Platform: platform,
	Target: jsii.String("target"),
	WorkingDirectory: jsii.String("workingDirectory"),
})
```

## Initializer

TypeScript:

```ts
new AssetImageCode(directory: string, props: AssetImageCodeProps)
```

Python:

```python
AssetImageCode(directory: str, props: AssetImageCodeProps)
```

Java:

```java
new AssetImageCode(String directory, AssetImageCodeProps props)
```

C# / .NET:

```csharp
new AssetImageCode(string directory, AssetImageCodeProps props)
```

Golang:

```go
NewAssetImageCode(Directory *string, Props AssetImageCodeProps)
```

## Properties

- `isInline`: boolean — Determines whether this Code is inline code or not.

## Methods

- `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): void` — 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` (static) — Loads the function code from a local disk path.

  **Parameters**

  - `path` — Either a directory with the Lambda code bundle or a .zip file.

- `fromAssetImage(directory: string, props?: AssetImageCodeProps): AssetImageCode // chainable` (static) — 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.
  - `props` — properties to further configure the selected image.

- `fromBucket(bucket: IBucket, key: string, objectVersion?: string): S3Code` (static) — Lambda handler code as an S3 object.

  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**

  - `bucket` — The S3 bucket.
  - `key` — The object key.
  - `objectVersion` — Optional S3 object version.

- `fromBucketV2(bucket: IBucket, key: string, options?: BucketOptions): S3CodeV2` (static) — Lambda handler code as an S3 object.

  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**

  - `bucket` — The S3 bucket.
  - `key` — The object key.
  - `options` — Optional parameters for setting the code, current optional parameters to set here are 1.

- `fromCfnParameters(props?: CfnParametersCodeProps): CfnParametersCode` (static) — Creates a new Lambda source defined using CloudFormation parameters.

  **Parameters**

  - `props` — optional construction properties of `CfnParametersCode`.

  **Returns:** a new instance of `CfnParametersCode`

- `fromCustomCommand(output: string, command: string[], options?: CustomCommandOptions): AssetCode` (static) — 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`.
  - `command` — The command which will be executed to generate the output, for example, [ 'node', 'bundle_code.js' ].
  - `options` — options for the custom command, and other asset options -- but bundling options are not allowed.

- `fromDockerBuild(path: string, options?: DockerBuildAssetOptions): AssetCode` (static) — 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.
  - `options` — Docker build options.

- `fromEcrImage(repository: IRepository, props?: EcrImageCodeProps): EcrImageCode` (static) — Use an existing ECR image as the Lambda code.

  **Parameters**

  - `repository` — the ECR repository that the image is in.
  - `props` — properties to further configure the selected image.

- `fromInline(code: string): InlineCode` (static) — Inline code for Lambda handler.

  **Parameters**

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

  **Returns:** `LambdaInlineCode` with inline code.
