Setup container registry

Next you need to setup Amazon Elastic Container Registry (ECR) in order to store Docker images that will be built. Amazon Elastic Container Registry (ECR) is a fully-managed Docker container registry that makes it easy for developers to store, manage, and deploy Docker container images. Amazon ECR is integrated with Amazon Elastic Container Service (ECS), simplifying your development to production workflow.

Open NorthwindCdk.sln in Visual Studio.

Add Amazon.CDK.AWS.ECR Nuget package to the project:

CodeCommit Nuget

Open NorthwindCdkStack.cs.

Please add the following changes at the end of NorthwindCdkStack constructor:

namespace NorthwindCdk
    public class NorthwindCdkStack : Stack
        internal NorthwindCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)

            // ECR

            var containerRegistry = new Amazon.CDK.AWS.ECR.Repository(this, "NorthwindContainerRegistry", new Amazon.CDK.AWS.ECR.RepositoryProps
                RepositoryName = "northwind",
                RemovalPolicy = RemovalPolicy.DESTROY

            new CfnOutput(this, "ContainerRegistry", new CfnOutputProps
                Value = containerRegistry.RepositoryUri

Save changes and compile the project.

Run cdk diff to take a look at the changes that are going to be deployed.

cdk diff

The output should look like this:

Stack NorthwindCdkStack
[+] AWS::ECR::Repository NorthwindContainerRegistry NorthwindContainerRegistryB7CF4399

[+] Output ContainerRegistry ContainerRegistry: {"Value":{"Fn::Join":["",[{"Fn::Select":[4,{"Fn::Split":[":",{"Fn::GetAtt":["NorthwindContainerRegistryB7CF4399","Arn"]}]}]},".dkr.ecr."

Next deploy the updates using cdk deploy command.

cdk deploy

The output should look like this:

NorthwindCdkStack: deploying...
NorthwindCdkStack: creating CloudFormation changeset...
 0/3 | 10:46:18 AM | CREATE_IN_PROGRESS   | AWS::ECR::Repository                  | NorthwindContainerRegistry (NorthwindContainerRegistryB7CF4399)
 0/3 | 10:46:19 AM | UPDATE_IN_PROGRESS   | AWS::CDK::Metadata                    | CDKMetadata

 ✅  NorthwindCdkStack

NorthwindCdkStack.ContainerRegistry =
NorthwindCdkStack.CodeRepository =
NorthwindCdkStack.PostgreSQLEndpointAddress =

Stack ARN: