DEV Community

Cover image for Hello AWS Microservice Extractor for .NET, Let's Work on that Legacy App
George Saadeh
George Saadeh

Posted on

Hello AWS Microservice Extractor for .NET, Let's Work on that Legacy App

Background

Organizations are increasingly facing challenges while modernizing their legacy applications especially those their business depends on for day-to-day operations. Many are actively looking to progressively decompose large monoliths (legacy or not) into microservices as these systems become too large to deal with.

There are different strategies, techniques and patterns teams can use to break down a monolithic application. Recently AWS introduced the AWS Microservice Extractor for .NET, a new tool that helps customers on their path to extract microservices from their monolithic applications. It simplifies the process of refactoring applications into independent services using source code analysis and visual representations.

In this tutorial, we look at how we can use the AWS Microservice Extractor for .NET on a real-world application to extract a service.

At the time of writing the AWS Microservice Extractor for .NET supports only .NET Framework CLR 4.0+ ASP.NET web service applications hosted on IIS and the extraction only supports CLR 4.7.0+. Therefore I decided to use the source of one of the Web API projects I worked on in the past which was built on .NET 4.6.1 and which I've upgraded to 4.7.2. Luckily the upgrade was smooth.

I do not own the source code of this application and I was only a contributor. Therefore I made sure not to share any code. I also disabled data sharing during analysis.

It is only worth noting that AWS Microservice Extractor for .NET is available for use at no cost which is phenomenal.

Preparations

To prepare the environment, I followed the instructions in the documentation.

I created a new IAM user and attached a custom IAM policy

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Resource": [
        "*"
      ],
      "Action": [
        "serviceextract:GetConfig"
      ]
    },
    {
      "Sid": "SectionForMetricsService",
      "Effect": "Allow",
      "Action": "execute-api:invoke",
      "Resource": [
        "arn:aws:execute-api:us-east-1:*:*/prod/POST/put-metric-data",
        "arn:aws:execute-api:us-east-1:*:*/prod/POST/put-log-data"
      ]
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

I then configured my AWS CLI profile and installed the AWS Microservice Extractor for .NET tool.

Setup the tool

I did not need to do the rest of the steps since my Windows VM already had Visual Studio 2019 installed with multiple versions of the .NET framework.

After the quick configuration the setup was successful.

Setup successful

Onboarding

After downloading the application code on my machine I was ready to start the analysis.

I clicked on Onboard application and I've added the solution file which points to the Web API application. I did not select the runtime profiling data.

Onboard application

Onboarding in progress

After a few minutes, the application was onboarded successfully.

It is worth noting that the tool includes analysis for .NET core portability which is great.

Onboarding successful

Visualizing

Now comes the exciting part. My application was analyzed and I was ready to see the visual representation.

The purpose of this visualization exercise is to learn more about the application components, dependencies and metrics to "quickly" identify which could be refactored into smaller service.

Visualize the app high level

Alright, this was a bit surprising at first glance with all the different connections. After going through the documentation I was able to navigate the interface slightly better and identity some of the services I have. I used the filter to look up my SpeakerService.

Use the filter

To understand the dependencies of the service, I clicked on it and I was presented with a nice view of the edges. Superb!

Visualize edges

Isolating the service in a separate part of the graph was no trivial task. After some battling, I managed to get the components grouped and ready for extraction.

Group service

Extracting

Exhilarated and curious, I hit the extract group as service button.

Extract group as service

I entered a few details about the service and then select which invocation method i want to use.

Service details

Invocation method

A few rounds of trial and error between the visual designer and the extractor and I was still getting this. The extraction halted at 60%.

Command failed: error while building and applying rules to transform the MicroService: error while updating build files for microservice: unable to remove some projects from sln
Enter fullscreen mode Exit fullscreen mode

It was one of the infrastructure projects that it couldn't remove from the solution.

Nevertheless, the extraction of the SpeakerService completed according to the application details screen and also the logs.

Service extracted

The log file can be found in the installation directly under /logs/drift-extraction.log.

The extracted service was located in the installation directory.

Extracted service

Opening the solution of the ApiIntegrationService in Visual Studio revealed multiple missing "infrastructure" projects which is probably why the extraction failed.

I can take it from here and add the missing dependencies and get the service in a build-able state.

Known Limits and Concerns

This documentation article mentions a few limits that you need to know before you start using it.

When extracting a microservice, you need to decide what to do with the building blocks and "shared" code. Do you publish those to nuget package (i.e. internal feed) and reference them, do you use code duplication by duplicating only what's needed etc. It's your call. The extractor however did not do very well with shared projects for me. I was not sure if I need to include all of these dependencies in the group. I believe there is additional manual work to be done.

Conclusion

AWS Microservice Extractor for .NET is a fantastic tool. It offers great analysis and visualization capabilities with somehow limited or dissatisfying extraction capabilities (at least for me).

It still provides a lot of assistance in your migration and can get you started on the right path. Any help is greatly required and appreciated.

You still need to touch both the old application and the new extracted service, maybe add some missing dependencies.

Not the glorious ending I was hoping for but nonetheless the start of a compelling journey. The tool was recently released and I expect great things for the future.

P.S: I will update the article with any new findings and if I manage to get a smooth extraction for the service.

Discussion (0)