aws-cdk-lib.aws_ecr_assets.DockerImageAsset

class DockerImageAsset (construct)

LanguageType name
.NETAmazon.CDK.AWS.Ecr.Assets.DockerImageAsset
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsecrassets#DockerImageAsset
Javasoftware.amazon.awscdk.services.ecr.assets.DockerImageAsset
Pythonaws_cdk.aws_ecr_assets.DockerImageAsset
TypeScript (source)aws-cdk-lib » aws_ecr_assets » DockerImageAsset

Implements IConstruct, IDependable

An asset that represents a Docker image.

The image will be created in build time and uploaded to an ECR repository.

Example

import { DockerImageAsset } from 'aws-cdk-lib/aws-ecr-assets';

const asset = new DockerImageAsset(this, 'MyBuildImage', {
  directory: path.join(__dirname, 'my-image'),
  buildArgs: {
    HTTP_PROXY: 'http://10.20.30.2:1234',
  },
  invalidation: {
    buildArgs: false,
  },
});

Initializer

new DockerImageAsset(scope: Construct, id: string, props: DockerImageAssetProps)

Parameters

  • scope Construct
  • id string
  • props DockerImageAssetProps

Construct Props

NameTypeDescription
directorystringThe directory where the Dockerfile is stored.
assetName?stringUnique identifier of the docker image asset and its potential revisions.
buildArgs?{ [string]: string }Build args to pass to the docker build command.
buildSecrets?{ [string]: string }Build secrets.
cacheFrom?DockerCacheOption[]Cache from options to pass to the docker build command.
cacheTo?DockerCacheOptionCache to options to pass to the docker build command.
exclude?string[]File paths matching the patterns will be excluded.
extraHash?stringExtra information to encode into the fingerprint (e.g. build instructions and other inputs).
file?stringPath to the Dockerfile (relative to the directory).
followSymlinks?SymlinkFollowModeA strategy for how to handle symlinks.
ignoreMode?IgnoreModeThe ignore behavior to use for exclude patterns.
invalidation?DockerImageAssetInvalidationOptionsOptions to control which parameters are used to invalidate the asset hash.
networkMode?NetworkModeNetworking mode for the RUN commands during build.
outputs?string[]Outputs to pass to the docker build command.
platform?PlatformPlatform to build for.
target?stringDocker target to build to.

directory

Type: string

The directory where the Dockerfile is stored.

Any directory inside with a name that matches the CDK output folder (cdk.out by default) will be excluded from the asset


assetName?

Type: string (optional, default: no asset name)

Unique identifier of the docker image asset and its potential revisions.

Required if using AppScopedStagingSynthesizer.


buildArgs?

Type: { [string]: string } (optional, default: no build args are passed)

Build args to pass to the docker build command.

Since Docker build arguments are resolved before deployment, keys and values cannot refer to unresolved tokens (such as lambda.functionArn or queue.queueUrl).


buildSecrets?

Type: { [string]: string } (optional, default: no build secrets)

Build secrets.

Docker BuildKit must be enabled to use build secrets.

See also: https://docs.docker.com/build/buildkit/ Example

import { DockerBuildSecret } from 'aws-cdk-lib';

const buildSecrets = {
  'MY_SECRET': DockerBuildSecret.fromSrc('file.txt')
};

cacheFrom?

Type: DockerCacheOption[] (optional, default: no cache from options are passed to the build command)

Cache from options to pass to the docker build command.

See also: https://docs.docker.com/build/cache/backends/


cacheTo?

Type: DockerCacheOption (optional, default: no cache to options are passed to the build command)

Cache to options to pass to the docker build command.

See also: https://docs.docker.com/build/cache/backends/


exclude?

Type: string[] (optional, default: nothing is excluded)

File paths matching the patterns will be excluded.

See ignoreMode to set the matching behavior. Has no effect on Assets bundled using the bundling property.


extraHash?

Type: string (optional, default: hash is only based on source content)

Extra information to encode into the fingerprint (e.g. build instructions and other inputs).


file?

Type: string (optional, default: 'Dockerfile')

Path to the Dockerfile (relative to the directory).


followSymlinks?

Type: SymlinkFollowMode (optional, default: SymlinkFollowMode.NEVER)

A strategy for how to handle symlinks.


ignoreMode?

Type: IgnoreMode (optional, default: IgnoreMode.GLOB)

The ignore behavior to use for exclude patterns.


invalidation?

Type: DockerImageAssetInvalidationOptions (optional, default: hash all parameters)

Options to control which parameters are used to invalidate the asset hash.


networkMode?

Type: NetworkMode (optional, default: no networking mode specified (the default networking mode NetworkMode.DEFAULT will be used))

Networking mode for the RUN commands during build.

Support docker API 1.25+.


outputs?

Type: string[] (optional, default: no outputs are passed to the build command (default outputs are used))

Outputs to pass to the docker build command.

See also: https://docs.docker.com/engine/reference/commandline/build/#custom-build-outputs


platform?

Type: Platform (optional, default: no platform specified (the current machine architecture will be used))

Platform to build for.

Requires Docker Buildx.


target?

Type: string (optional, default: no target)

Docker target to build to.

Properties

NameTypeDescription
assetHashstringA hash of this asset, which is available at construction time.
imageTagstringThe tag of this asset when it is uploaded to ECR.
imageUristringThe full URI of the image (including a tag).
nodeNodeThe tree node.
repositoryIRepositoryRepository where the image is stored.

assetHash

Type: string

A hash of this asset, which is available at construction time.

As this is a plain string, it can be used in construct IDs in order to enforce creation of a new resource when the content hash has changed.


imageTag

Type: string

The tag of this asset when it is uploaded to ECR.

The tag may differ from the assetHash if a stack synthesizer adds a dockerTagPrefix.


imageUri

Type: string

The full URI of the image (including a tag).

Use this reference to pull the asset.


node

Type: Node

The tree node.


repository

Type: IRepository

Repository where the image is stored.

Methods

NameDescription
addResourceMetadata(resource, resourceProperty)Adds CloudFormation template metadata to the specified resource with information that indicates which resource property is mapped to this local asset.
toString()Returns a string representation of this construct.

addResourceMetadata(resource, resourceProperty)

public addResourceMetadata(resource: CfnResource, resourceProperty: string): void

Parameters

  • resource CfnResource — The CloudFormation resource which is using this asset [disable-awslint:ref-via-interface].
  • resourceProperty string — The property name where this asset is referenced.

Adds CloudFormation template metadata to the specified resource with information that indicates which resource property is mapped to this local asset.

This can be used by tools such as SAM CLI to provide local experience such as local invocation and debugging of Lambda functions.

Asset metadata will only be included if the stack is synthesized with the "aws:cdk:enable-asset-metadata" context key defined, which is the default behavior when synthesizing via the CDK Toolkit.

See also: https://github.com/aws/aws-cdk/issues/1432


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.