Introduction
In this article, we are going to see how to deploy a .Net Core Web API to AWS Elastic Beanstalk service using CI/CD Pipeline. To configure the CI/CD pipeline, we are using AWS CodeBuild & CodePipeline services.
I have divided the deployment process into 6 steps.
- Create a sample .NET 6 Web API project
- Add a buildspec.yml file to our .Net 6 Web API project
- Create and configure AWS CodeBuild
- Create and configure AWS CodePipeline
- Run CodePipeline pipeline and deploy our .Net Web API
- Test the deployed API Application
Let's begin.
Step 1. Create a sample .NET 6 Web API project
- Open Visual Studio 2022 and click on Create a new project.

- Select 'ASP.NET Core Web API' project

-
Provide the Project name "demo.api"
-
Select Framework as .NET 6, keep other configurations with the default selected value, and click on 'Create'.

- Run and test your demo.api project on localhost

Now, our Web API is ready to deploy
Step 2. Add a 'buildspec.yml' file to our .Net 6 Web API project
A buildspec (build specification) is a collection of build commands and related settings in YAML format that CodeBuild uses to run a build. If you include a buildspec as part of the source code, by default, the buildspec file must be named buildspec.yml and placed in the root of your source directory.
Right-click on project > Add new item > select a text file > rename to buildspec.yml

Add the below content to the buildspec.yml file.
# AWS CodeBuild spec to build an Elastic Beanstalk artifact for AWS CodePipeline to deploy
version: 0.2
phases:
install:
runtime-versions:
dotnet: 6.0
pre_build:
commands:
- echo Restore started on `date`
- echo "CURRENT DIR `pwd`"
- dotnet restore demo.api/demo.api/demo.api.csproj
build:
commands:
- echo Build started on `date`
- dotnet build demo.api/demo.api/demo.api.csproj
post_build:
commands:
- echo Publish started on `date`
- dotnet publish -c Release -o ./build-output demo.api/demo.api/demo.api.csproj
artifacts:
name: DEMO_API_Build_#$CODEBUILD_BUILD_NUMBER
base-directory: './build-output'
files:
- ./**/*
This buildspec declaration
- version represents the version of the build spec standard being used. This build spec declaration uses the latest version, 0.2.
- phases represent the build phases during which you can instruct CodeBuild to run commands. These build phases are listed here as install and build. You cannot change the spelling of these build phase names, and you cannot create more build phase names.
After updating the buildspec.yml file, commit your changes to your source control (GitHub, Bitbucket, etc.).
That's it; we are now done with the code changes.
For the next steps, we will work on the AWS console.
Step 3. Create and configure AWS CodeBuild
Go to AWS console > CodeBuild > click on Build Project















Join the conversation! Your thoughts help the community grow.