Building .Net Application Using CodeBuild Custom Windows Image

Kamlesh Bhatt
kamlesh_bhatt
Published in
4 min readSep 24, 2019

--

At the time of writing this document, AWS provide CodeBuild with Windows base image in limited regions also those image don’t have the latest .Net framework you can check the versions provided here.

In order to build your own image you need to write your own Dockerfile with the .NetFramework required by your project.

AWS also provides the latest .NetFramework Dockerfile which can be found in this article.

Okay, now let’s begin…

What would You need ?

  1. Windows Machine with docker and AWS CLI installed.
  2. GitHub Repo
  3. AWS Account with ECR created.

First step is to Install docker in your machine, or you can spin-up a EC2 windows server with containers image(ami-06b2f8d71dc2825ee) just like me. Also it’s easier for getting environment ready within minutes.

Once your instance/Machine is ready you can login to your server and verify that docker is installed by running command docker --version as shown below.

Once the docker is up and running you need to have AWS-CLI installed as well so that you can push your image to ECR which we are using for this tutorial.

Now you are ready to build your own image.

The Dockerfile that we are using in this tutorial can be found in my Github repository.

You can login to your ECR using below command and start the action.

Invoke-Expression -Command (Get-ECRLoginCommand -Region us-east-1).Command

Once you have logged in to the repo, you need to build and push to the ECR repo as shown below images. Following commands can be used to build, tag and push the image to your ECR repository.

docker build -t msbuild .

docker tag msbuild:latest 111648417676.dkr.ecr.us-east-1.amazonaws.com/msbuild:latest

docker push 111648417676.dkr.ecr.us-east-1.amazonaws.com/msbuild:latest

Once your image is pushed, you will be able to see the image in your ECR repository.

Now login to your AWS account and go to CodeBuild and create a new project for your .Net Application as shown in below images.

Note: You need to authorise your github repo incase you are using github

The .Net Application that we are using here can be found here.

Here you need to configure the image that you build above to build your .Net Application.

You need to create a bucket to store your artifacts which can be later used in deployment phase.

Moreover you can also select logs of the build to be stored in Cloudwatch as shown in image below, which will basically send the build logs in Cloudwatch for you to view later.

Verify your details, once verified then you can create the build project.

You are now all set to build your project. Once your build is successful you can see the artifacts in the s3 bucket as show in below images.

Thank you !!!

--

--

Kamlesh Bhatt
kamlesh_bhatt

4x AWS Certified | DevOps Engineer | GCP | Azure | Cloud Platform Engineer | Docker | Kubernetes