class aws_cdk.aws_ecr_assets.DockerImageAsset(scope, id, *, directory, build_args=None, file=None, invalidation=None, network_mode=None, platform=None, repository_name=None, target=None, extra_hash=None, exclude=None, follow=None, ignore_mode=None, follow_symlinks=None)

Bases: Construct

An asset that represents a Docker image.

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




from aws_cdk.aws_ecr_assets import DockerImageAsset, NetworkMode

asset = DockerImageAsset(self, "MyBuildImage",
    directory=path.join(__dirname, "my-image"),
  • scope (Construct) –

  • id (str) –

  • directory (str) – 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

  • build_args (Optional[Mapping[str, str]]) – 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). Default: - no build args are passed

  • file (Optional[str]) – Path to the Dockerfile (relative to the directory). Default: ‘Dockerfile’

  • invalidation (Union[DockerImageAssetInvalidationOptions, Dict[str, Any], None]) – Options to control which parameters are used to invalidate the asset hash. Default: - hash all parameters

  • network_mode (Optional[NetworkMode]) – Networking mode for the RUN commands during build. Support docker API 1.25+. Default: - no networking mode specified (the default networking mode NetworkMode.DEFAULT will be used)

  • platform (Optional[Platform]) – Platform to build for. Requires Docker Buildx. Default: - no platform specified (the current machine architecture will be used)

  • repository_name (Optional[str]) – (deprecated) ECR repository name. Specify this property if you need to statically address the image, e.g. from a Kubernetes Pod. Note, this is only the repository name, without the registry and the tag parts. Default: - the default ECR repository for CDK assets

  • target (Optional[str]) – Docker target to build to. Default: - no target

  • extra_hash (Optional[str]) – (deprecated) Extra information to encode into the fingerprint (e.g. build instructions and other inputs). Default: - hash is only based on source content

  • exclude (Optional[Sequence[str]]) – (deprecated) Glob patterns to exclude from the copy. Default: nothing is excluded

  • follow (Optional[FollowMode]) – (deprecated) A strategy for how to handle symlinks. Default: Never

  • ignore_mode (Optional[IgnoreMode]) – (deprecated) The ignore behavior to use for exclude patterns. Default: - GLOB for file assets, DOCKER or GLOB for docker assets depending on whether the ‘

  • follow_symlinks (Optional[SymlinkFollowMode]) – A strategy for how to handle symlinks. Default: SymlinkFollowMode.NEVER


add_resource_metadata(resource, resource_property)

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.

  • resource (CfnResource) – The CloudFormation resource which is using this asset [disable-awslint:ref-via-interface].

  • resource_property (str) – The property name where this asset is referenced.


Return type:



Returns a string representation of this construct.

Return type:




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.


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

Use this reference to pull the asset.


The construct tree node associated with this construct.


Repository where the image is stored.


(deprecated) A hash of the source 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.


use assetHash



Static Methods

classmethod is_construct(x)

Return whether the given object is a Construct.


x (Any) –

Return type: