Lessons in this course (9)

2. EC2, Elastic Beanstalk, ECS/Fargate, EKS, App Runner and Lambda

Basic★ Must knowLesson 2 of 9
ServiceYou manageGood for .NET
EC2VM: OS, IIS/Kestrel, patches, scaling (Auto Scaling groups)Lift-and-shift .NET Framework/IIS apps (Windows AMIs)
Elastic BeanstalkJust upload the app; Beanstalk creates EC2, load balancer, auto scalingQuick hosting of ASP.NET Core (Linux) or .NET Framework on IIS (Windows)
App RunnerContainer image or source; fully managed HTTPS serviceSimple containerised APIs
ECS + FargateContainer task definitions and services; no serversMost containerised .NET microservices
EKSKubernetes cluster (managed control plane)Teams standardised on Kubernetes
LambdaFunctions; pay per request and duration; scales to zeroEvent-driven code, APIs with spiky traffic
bash
# ASP.NET Core on Lambda behind API Gateway (Amazon.Lambda.AspNetCoreServer.Hosting)
dotnet new install Amazon.Lambda.Templates
dotnet new serverless.AspNetCoreMinimalAPI -n ShopApi
# Program.cs: builder.Services.AddAWSLambdaHosting(LambdaEventSource.HttpApi);
dotnet lambda deploy-serverless
csharp
// A plain Lambda function handler (S3 upload event → create thumbnail)
public class Function
{
    public async Task Handler(S3Event evt, ILambdaContext ctx)
    {
        foreach (var record in evt.Records)
            ctx.Logger.LogInformation($"New file {record.S3.Object.Key} in {record.S3.Bucket.Name}");
    }
}

Auto Scaling: EC2 Auto Scaling groups or ECS service auto scaling based on CPU, request count or SQS queue depth; place instances/tasks in multiple AZs behind an ALB.