How to override aws_cdk.core.LegacyStackSynthesizer.add_docker_image_asset in AWS CDK for Python How to override aws_cdk.core.LegacyStackSynthesizer.add_docker_image_asset in AWS CDK for Python docker docker

How to override aws_cdk.core.LegacyStackSynthesizer.add_docker_image_asset in AWS CDK for Python


DockerImageAsset is a managed construct, which handles the repository and versioning by itself. By default it creates a repository for your stack and uploads your docker images to it (tagging them by their hash).

You do not need to create this repository yourself. However, if you are like me and want to have a legible name for the repository, you can name the repo using cdk.json config file and its context section:

// cdk.json{  "app": "python3 your_app",  "context": {    "@aws-cdk/core:enableStackNameDuplicates": "true",    "aws-cdk:enableDiffNoFail": "true",    "assets-ecr-repository-name": "<REPO NAME GOES HERE>"  }}

If you want to further alter the repo (I like to leave it fully managed, but hey), you can load the repo into the CDK stack by using one of the static methods on the aws_ecr.Repository construct.https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ecr.Repository.html#static-from-wbr-repository-wbr-namescope-id-repositoryname

Hope this helps a little :-)