AWS · Production

Deploying ASP.NET Core Applications

ASP.NET Core runs well on AWS — on Linux containers, on Elastic Beanstalk, or even on Lambda. Here are the two most common paths.

Advanced 5 min Lesson 29 of 30
0/30 in AWS
On this page · 5 min · Advanced

Learning objectives#

  • Deploy quickly with Elastic Beanstalk
  • Containerise and run on ECS Fargate
  • Configure settings and secrets
  • Connect to RDS

Explanation#

Elastic Beanstalk takes a published app (or zip) and creates EC2 instances, a load balancer and auto scaling for you — great for getting started.

For production microservices, containerise the app with the official .NET images and run it on ECS Fargate behind an ALB.

ASP.NET Core reads environment variables, so ConnectionStrings__Default in the task definition overrides appsettings.json. .NET 8+ container images listen on port 8080 by default.

RDS supports SQL Server, MySQL and PostgreSQL; Aurora PostgreSQL with Npgsql is a popular cost-effective option.

Code example: Container image for an ASP.NET Core API#

DockerfileDockerfile Illustrative
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
WORKDIR /src
COPY *.csproj ./
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /app --no-restore


FROM mcr.microsoft.com/dotnet/aspnet:9.0
WORKDIR /app
COPY --from=build /app .
USER app
EXPOSE 8080
ENTRYPOINT ["dotnet", "Shop.Api.dll"]


# Task definition environment / secrets:
#   ASPNETCORE_ENVIRONMENT = Production
#   ConnectionStrings__Default  ← from Secrets Manager
Expected output
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://[::]:8080
info: Microsoft.Hosting.Lifetime[0]
      Application started. Hosting environment: Production

This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.

Step-by-step explanation#

  1. The SDK image restores and publishes; restore is cached by copying the .csproj first.
  2. The runtime-only aspnet image keeps the final image small.
  3. USER app runs as the non-root user built into .NET 8+ images.
  4. Environment variables override appsettings.json in production.

Real-world use case#

An ASP.NET Core Web API with EF Core on RDS, deployed by CodePipeline or GitHub Actions to ECS Fargate.

Common mistakes#

Target group on port 80

.NET 8+ images listen on 8080. Match the container port and target group port.

Connection strings in appsettings.Production.json

Inject them from Secrets Manager.

Best practices#

  • Use Linux containers
  • Health checks with MapHealthChecks("/health")
  • Secrets from Secrets Manager
  • Run EF Core migrations as a separate deployment step

Remember this#

Quick start: Elastic Beanstalk. Production containers: ECS Fargate.

.NET 8+ containers listen on 8080.

ConnectionStrings__Default env var overrides appsettings.

Practice exercise#

Your task: Deploy a published ASP.NET Core app to Elastic Beanstalk with the EB CLI.

Show solution
Shell Illustrative
dotnet publish -c Release -o publish
cd publish
eb init -p "64bit Amazon Linux 2023 running .NET 8" shop-api --region ap-south-1   # pick the current .NET platform
eb create shop-api-dev

Mini quiz#

Deploying ASP.NET Core Applications quizMultiple choice Question 1 of 1

Which port do official .NET 8+ ASP.NET Core container images listen on by default?

Score so far: 0/0

Want more? Practise all AWS MCQs · AWS interview questions

My notes#

Saved in this browser.

Progress is saved in this browser. Sign in to sync.