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.
On this page · 5 min · Advanced
On this page
- Learning objectives
- Explanation
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Advanced
- Updated
- Oct 29, 2026
Related tutorials
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#
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 /app .
USER app
EXPOSE 8080
ENTRYPOINT ["dotnet", "Shop.Api.dll"]
# Task definition environment / secrets:
# ASPNETCORE_ENVIRONMENT = Production
# ConnectionStrings__Default ← from Secrets Manager
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:8080
info: Microsoft.Hosting.Lifetime[0]
Application started. Hosting environment: ProductionThis example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- The SDK image restores and publishes; restore is cached by copying the .csproj first.
- The runtime-only aspnet image keeps the final image small.
- USER app runs as the non-root user built into .NET 8+ images.
- 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#
.NET 8+ images listen on 8080. Match the container port and target group port.
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
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#
Which port do official .NET 8+ ASP.NET Core container images listen on by default?
Want more? Practise all AWS MCQs · AWS interview questions
My notes#
Saved in this browser.