How To Publish ASP.NET Core Web API To Amazon ECS Fargate Using Visual Studio 2022

Introduction

In this article, you will learn how to publish ASP.NET Core Web API to Amazon ECS Fargate using Visual Studio 2022.

Topics covered

This article demonstrates how to build the following:

  • Create a sample ASP.NET Core Web API
  • Publish to ECS Fargate from Visual Studio
  • Test the ASP.NET Core Web API
  • Clean up resources

Pre-requisites

  1. Download and install Visual Studio 2022.
  2. Download and install AWS Toolkit for Visual Studio 2022.
  3. An Active AWS Account. (See AWS Account)
  4. User with sufficient access to create AWS resources for this article.(See IAM role in AWS IAM Roles Documentation.)
  5. User should have programmatic access keys.(See IAM user and Access in the AWS IAM documentation.)
  6. Download and install Amazon command line interface (AWS CLI). Configure AWS CLI.

Tools

  1. AWS Console
  2. Visual Studio 2022

Task 1: Create a sample ASP.NET Core Web API

In this task, you will see how to create a new sample .NET 6 ASP.NET Core Web API using Visual Studio 2022.

Step 1

Open Visual Studio 2022, click Create a new project.

Step 2

Search ASP.NET in the search bar, select ASP.NET Core Web API project template and click Next.

Step 3

Enter the project name as AWSNetECSDemo. Click Next.

Step 4

Select .NET 6.0 (Long-term support) as Framework. Click Create.

Step 5

Hit Ctrl+F5 to run the web API locally and test the default weatherforecast API using swagger.

Task 2: Publish to ECS Fargate from Visual Studio

In this task, you will see how to publish the .NET API to ECS Fargate from Visual Studio 2022.

Step 1

Right-click the project, click Publish to AWS (Preview feature) …

Step 2

Select the AWS Profile configured in your machine using AWS CLI command and select the region where this API needs to be deployed.

How to publish ASP.NET Core Web API to Amazon ECS Fargate using Visual Studio 2022

Step 3

Select Publish to as New Target.

Step 4

Select ASP.NET Core App to Amazon ECS using Fargate.

Step 5

Click Edit Settings to update the settings such as adding environment variables, selecting VPC etc.

Step 6

Click Publish. Click Yes to confirm the deployment.

How to publish ASP.NET Core Web API to Amazon ECS Fargate using Visual Studio 2022

How to publish ASP.NET Core Web API to Amazon ECS Fargate using Visual Studio 2022

Step 7

The following steps are performed as part of publish to Amazon ECS Fargate.

How to publish ASP.NET Core Web API to Amazon ECS Fargate using Visual Studio 2022

  • Creating deployment image
  • Pushing container image to Elastic Container Registry (ECR)
  • Configuring AWS Cloud Development Kit (CDK)
  • Deploying AWS CDK Project

Task 3: Test the ASP.NET Core Web API

In this task, you will see how to test the ASP.NET Core Web API deployed to Amazon ECS Fargate.

Step 1

Open the browser, enter the endpoint URL copied in previous section. Append the controller name WeatherForecast to view the results as shown below.

How to publish ASP.NET Core Web API to Amazon ECS Fargate using Visual Studio 2022

Step 2

Open AWS Console, navigate to Amazon ECS service. Click Clusters to view the newly deployed cluster as shown below.

How to publish ASP.NET Core Web API to Amazon ECS Fargate using Visual Studio 2022

Task 4: Clean up resources

Delete all the resources to ensure that you're not charged for any services you aren't using.

Summary

This article describes how to publish ASP.NET Core Web API to Amazon ECS Fargate using Visual Studio 2022.