# AssetImageCode

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

Extends: Code › AssetImageCode

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

## Example

```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',
});
```

## Initializer

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

## Properties

- `isInline`: boolean (required) — 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.
