Yesterday I had the honor and privilege of sharing the re:Invent stage once again with my good friend and colleague Runeet Vashisht for our session “Refactoring strategies for .NET applications as you migrate to the cloud” In this session, we were covering the process of refactoring your existing .NET Framework applications into modern .NET 6 applications that can run as Microservices.
Our session started with your Typical Monolithic application developed in .NET Framework 4.8.
Our first stop along the journey for this application was to use the AWS Refactoring Toolkit for .NET. This is a new toolkit provided by AWS that can be installed in Visual Studio. The refactoring toolkit helps customers to convert their legacy .NET Framework applications over to .NET 6. Get the toolkit here:
By using this toolkit, Runeet was able to bring our starter application from .NET Framework 4.8 over to .NET 6.
Be warned: The toolkit is destructive. Your project is updated in place, so it’s not possible to go back once you have kicked off the porting. Keep in mind that the porting of a project is assistive in nature, it’s not a 100% perfect conversion. The tool helps with the manual effort, converting your project structure for you, and applying changes to your code; however, there is going to be additional manual effort required to complete the transformation.
Once the toolkit has been run over your applications, and all the required changes have been made, you are left with a .NET 6 application. Having converted the application to .NET 6 we have an updated architecture and some new benefits:
By converting the project to .NET 6 we are able to run our application on Linux Instances rather than Windows instances. This will result in faster auto-scaling. Another great benefit is lower running costs, as Linux instances avoid paying for the Windows license. (This can save you around 30% on average.) A third benefit of running .NET on a Linux OS is that you may be able to run your application on ARM-based instances rather than Intel instances. Running ARM instances will often result in better price/performance for your workload.
Our next step in the refactoring process was to leverage a tool called the “AWS Microservice Extractor for .NET” https://aws.amazon.com/microservice-extractor/
Using the AWS Microservice Extractor for .NET I was able to locate a specific set of classes in my application and create a microservice out of them. In this case, I specifically wanted to extract functionality relating to the use of Amazon Rekognition to automatically moderate images that had been uploaded to the website.
Microservice Extractor was able to look at my application and help me find a specific set of classes that I wanted to extract into a new microservice. I created a group in the tool that encapsulated the functionality I was interested in. Microservice Extractor then created a new Project, copied the required classes into that project, built out the scaffolding for a HTTP endpoint that would host my microservice, and also updated the code in my residual application so that the application would call the new microservice over the wire, instead of calling the local code.
As a result, we ended up with an updated architecture:
In this case, I was able to take the new Microservice and deploy it directly to AWS App Runner. App runner is a serverless hosting option for your applications in containers and allows you to quickly and easily run your applications without having to worry about how the underlying infrastructure is set up and managed.
Top tip: When I was using Microservice Extractor, I had a starting point in mind, because I had in-depth knowledge of the application ahead of time. However, if you don’t have a lot of knowledge about the application you are working with Microservice Extractor can help you with Heuristic-based recommendations as you browse your application’s visualization, or by using a new Artificial Intelligence recommendation engine. I will cover these more in a later blog post.
In summary: Just because .NET Framework is end-of-the-line with .NET Framework 4.8 doesn’t mean your existing .NET Framework Apps are stuck. AWS has tools that can help you not only get them upgraded to .NET 6 but can also help to evolve their architecture to support things like Microservices.
While this Blog Post only glosses over the process, stay tuned on the Basement Programmer YouTube channel for videos covering all of this functionality coming soon. www.youtube.com/@basementProgrammer
Did you find this article valuable?
Support Tom Moore by becoming a sponsor. Any amount is appreciated!