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
Resources
[+] AWS::ECR::Repository NorthwindContainerRegistry NorthwindContainerRegistryB7CF4399

Outputs
[+] Output ContainerRegistry ContainerRegistry: {"Value":{"Fn::Join":["",[{"Fn::Select":[4,{"Fn::Split":[":",{"Fn::GetAtt":["NorthwindContainerRegistryB7CF4399","Arn"]}]}]},".dkr.ecr."
,{"Fn::Select":[3,{"Fn::Split":[":",{"Fn::GetAtt":["NorthwindContainerRegistryB7CF4399","Arn"]}]}]},".",{"Ref":"AWS::URLSuffix"},"/",{"Ref":"NorthwindContainerRegistryB7CF4399"}]]}}

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

Outputs:
NorthwindCdkStack.ContainerRegistry = 404486542784.dkr.ecr.eu-west-1.amazonaws.com/northwind
NorthwindCdkStack.CodeRepository = https://git-codecommit.eu-west-1.amazonaws.com/v1/repos/Northwind
NorthwindCdkStack.PostgreSQLEndpointAddress = northwind-postgresql.cluster-cyhlwzws5aoz.eu-west-1.rds.amazonaws.com

Stack ARN:
arn:aws:cloudformation:eu-west-1:404486542784:stack/NorthwindCdkStack/f78fb1c0-8ed1-11ea-8a83-0a0af0d573f8