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).
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:
- 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.
- 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.
- 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.
- 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.
- 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.
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 -
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".
I also have configured AWS CLI on my EC2 Instance and authenticated it via this IAM Role.
aws sts get-caller-identity
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.
- Login to the AWS Console and choose US East (Virginia) as the region.
- 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.
Now, Let's start App2Container step by step.
- 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
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
Now time to analyze and find running applications on server. Run inventory command as follows
The output includes a JSON object collection with one entry for each application.
To analyze application, we need
iis-app-id from previous step. Run analyze command as follows
app2container analyze --application-id iis-app-id
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.
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
app2container containerize --application-id iis-app-id
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 -
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.
Run the generate app-deployment command as follow
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".
AWS App2Container generates everything for us, we need to copy CloudFormation command from previous step output window and run in AWS CLI.
AWS CloudFormation template creates all the required resources for the application. We can verify newly created resources from AWS account.
Access ECS Fargate application through Application Load Balancer.
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.
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.