logo
Menu
Dockerize ASP.NET Framework Application using App2Container & deploy to AWS ECS

Dockerize ASP.NET Framework Application using App2Container & deploy to AWS ECS

In this article, we will modernize the sample ASP.NET framework app using App2Container CLI tool & finally we will deploy it to AWS Elastic Container Service (ECS)

Published Jan 8, 2024
In this article, I will demonstrate the capabilities of the AWS App2Container command line tool. By utilizing the App2Container tool, you can modernize (dockerize) your .NET and Java applications and seamlessly deploy them to AWS ECS/EKS/App Runner.
When dealing with applications that are no longer in active development, identifying dependencies and dockerizing the application can be a challenging task. In this article, I will guide you through the process of lifting and shifting my .NET Framework application from EC2 to AWS Elastic Container Service (ECS).

What is AWS App2Container?

AWS App2Container (A2C) is a tool provided by Amazon Web Services (AWS) to help users containerize their existing applications. The main purpose of App2Container is to simplify the process of migrating on-premises applications or applications running on virtual machines to containerized environments.
Here are some key features and functionalities of AWS App2Container:
  1. Automated Containerization: App2Container automates the process of containerizing applications. It analyzes the application running on a source environment, captures its configuration, and generates the necessary artifacts for containerization.
  2. Compatibility Analysis: The tool performs compatibility analysis to identify and address potential challenges or issues that may arise during the migration process. This helps users understand the feasibility of containerizing a particular application.
  3. Support for Various Platforms: AWS App2Container supports containerization for applications running on different platforms, including Java and .NET. This flexibility allows users to modernize a variety of applications.
  4. Integration with AWS Services: Once an application is containerized, App2Container can facilitate the deployment of the containerized application to AWS services like Amazon ECS (Elastic Container Service), Amazon EKS (Elastic Kubernetes Service), or AWS App Runner.
  5. CLI Tool: App2Container is available as a command-line interface (CLI) tool, making it convenient for users to incorporate it into their existing workflows and automation processes.
AWS App2Container (A2C) serves as a command-line tool designed for the strategic modernization of .NET and Java applications, transforming them into containerized solutions. A2C conducts a comprehensive analysis and establishes an inventory of all applications currently operational in virtual machines, whether on-premises or within cloud environments. The process is streamlined: select the desired application for containerization, and A2C takes care of packaging the application artifact along with identified dependencies into container images. It configures network ports and generates ECS task and Kubernetes pod definitions.
A2C goes beyond containerization; it leverages CloudFormation to provision the necessary cloud infrastructure and sets up CI/CD pipelines essential for deploying the containerized .NET or Java application into a production environment. The tool not only facilitates the modernization of existing applications but also ensures standardized deployment and operations through the efficient utilization of containers. This results in enhanced agility and consistency in application deployment across your business landscape.
A2C-Workflow
A2C-Workflow

Dockerize .NET Framework Application using App2Container

Before starting App2Container, I have already setup a sample legacy .NET framework application running in Internet Information Services (IIS) web server on Windows Server 2019 with Docker installed on it. I can access the application as shown below -
ASP_Net_Web_App
ASP_Net_Web_App
ASP_Net_Web_App
ASP_Net_Web_App
Then, I have created a customized IAM Policy named "AWS-EC2-SSM-Policy-Piyush" to enable AWS SSM Access for my launched EC2. Additionally, while creating an IAM Role for my EC2, I attached AWS-managed-policy "AdministratorAccess" as shown in below screenshot. The IAM role name is "App2Container-Role-EC2-Piyush".
App2Container-Role-EC2-Piyush
App2Container-Role-EC2-Piyush
I also have configured AWS CLI on my EC2 Instance and authenticated it via this IAM Role.
1
aws sts get-caller-identity
A2CRole-EC2-CLI
A2CRole-EC2-CLI
The first step is to create the Amazon S3 bucket which is used to store deployment artifacts of the application containerization. When you try to deploy the containerized application to AWS, the S3 bucket is used.
  1. Login to the AWS Console and choose US East (Virginia) as the region.
  2. Goto S3 Management Console. Use + Create bucket button to create a new bucket piyush-a2c-bucket. If the bucket name is not available, then create a bucket with the name which is available. For me, the name was unique.
piyush-a2c-bucket
piyush-a2c-bucket
Now, Let's start App2Container step by step.

Step 1: Download and Install AWS App2Container

  • Download the App2Container installation package, AWSApp2Container-installer-windows.zip.
  • Extract the package and open PowerShell (Run as administrator) on that folder
  • Run install script from PowerShell
1
.\install.ps1
Install-A2C-Tool
Install-A2C-Tool

Step 2: Initialize AWS App2Container

Initialize AWS App2Container on application server. You are prompted to provide some information. Press "enter" to accept the default value. I have added S3 bucket name "piyush-a2c-bucket", rest of the option taken as default. Run init command as follows
1
app2container init
A2C-Init
A2C-Init

Step 3: Run AWS App2Container inventory command

Now time to analyze and find running applications on server. Run inventory command as follows
1
app2container inventory
The output includes a JSON object collection with one entry for each application.
A2C-inventory
A2C-inventory

Step 4: Analyze your application

To analyze application, we need iis-app-id from previous step. Run analyze command as follows
1
app2container analyze --application-id iis-app-id
A2C-analyze
A2C-analyze
The output is a JSON file, analysis.json, stored in the workspace directory that you specified when you ran the app2container init command in step 2.

Step 5: Transform your application

Now that your application has gone through the analysis phase, it's ready for containerization. The transform phase creates the containers that your application runs in after you deploy it to Amazon ECS, Amazon EKS, or App Runner, if eligible.
To containerize application run containerize command as follows
1
app2container containerize --application-id iis-app-id
Docker-Error
Docker-Error
Note: If docker is not installed on your server, you will get an error. Install docker and re-run containerize command.
On my machine since docker is already installed, I am able to containerize the application as shown below -
Containerization
Containerization
The output is a set of deployment files stored in the workspace directory that you specified when you ran the app2container init command. Below is the screenshot of docker image.
Container-Image
Container-Image

Step 6: Deploy your application

Run the generate app-deployment command as follow
1
app2container generate app-deployment --application-id iis-app-id
This command creates ECR (Elastic Container Registry) on your AWS account and push docker image on that registry. It will upload CloudFormation template on S3 bucket "piyush-a2c-bucket".
app-deployment
app-deployment

Step 7: Deploy your application on AWS ECS

AWS App2Container generates everything for us, we need to copy CloudFormation command from previous step output window and run in AWS CLI.
app-deploy-to-ECS-Fargate
app-deploy-to-ECS-Fargate

Step 8: Verify AWS Resources

AWS CloudFormation template creates all the required resources for the application. We can verify newly created resources from AWS account.
ECS-Fargate-Cluster
ECS-Fargate-Cluster

Step 9: Verify Dockerized Application

Access ECS Fargate application through Application Load Balancer.
ECS-Fargate-App-ALB
ECS-Fargate-App-ALB
In this article, I've launched a basic .NET Framework application using the generated Dockerfile without making any modifications. However, you have the flexibility to customize the container image before deploying it. Ensure that you run AWS App2Container on a supported operating system.
Hope you enjoyed it.

OK, folks that’s it for this article. Have a nice day guys…… Stay tuned…..!!!!!

This concludes the present article. Wishing you all a wonderful day! Stay tuned for more updates. Remember to show your support by liking and sharing this post on your social networks. I'll continue to share insights within this fantastic AWS community platform. Please make sure to follow for future content!
Let's build a community that thrives on the exchange of knowledge, where collaboration fuels innovation. Join me in this endeavor, and together, let's shape the future of technology.

Comments