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
- Download and install Visual Studio 2022.
- Download and install AWS Toolkit for Visual Studio 2022.
- An Active AWS Account. (See AWS Account)
- User with sufficient access to create AWS resources for this article.(See IAM role in AWS IAM Roles Documentation.)
- User should have programmatic access keys.(See IAM user and Access in the AWS IAM documentation.)
- Download and install Amazon command line interface (AWS CLI). Configure AWS CLI.
Tools
- AWS Console
- 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.
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.
Step 7
The following steps are performed as part of publish to Amazon ECS Fargate.
- 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.
Step 2
Open AWS Console, navigate to Amazon ECS service. Click Clusters to view the newly deployed cluster as shown below.
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.