Replacing your application stack with Azure services

I've been thinking recently what would be the cost of Azure services, if I'd like to replace my VM with this particular cloud solutions. Please do have in mind, that in this post I'm not taking into account multiple third-party applications(like TeamCity or YouTrack), which I run on the VM along with my projects. Only technology stack matters.

What do we have?

My VM is a very basic machine:

  • Windows Server 2012
  • 1 Core AMD Opteron Processor 6386 SE 2,80 GHz
  • 50 GBs HDD storage
  • 4 GBs RAM

It's perfectly fine to run a simple SPA application, SQL server and EventStore to aggregate events from multiple devices. It's far from optimal solution but serves well since many months. Cost - about 18 EUR. 

If I had a chance to start from scratch, I'd select following stack on Azure:

  • EventHub for 10M events for 9,65 EUR
  • App Service shared infrastructure for 8,16 EUR
  • Table Storage with 50 GBs of storage and 100 transaction units for 3,26EUR

It gives total of 21,06 EUR.

Pros and cons?

While having a VM gives you great flexibility, it also complicates many things when it comes to update all software, deploy and configure it. It's also a bit more difficult to integrate all together. The biggest disadvantage of a VM is the lack of scalability - if an application will meet its higher requirements, it will cost us much more to migrate to the higher stack.

The downside of a stack built on Azure is having shared infrastructure for our web application which can(but doesn't have to be) problematic from time to time. What I like about this solution is having it all in once place and integrating it all with ease. What is more I can add Azure B2C for free and have a widely used access control solution for my application. Who knows, maybe I'll migrate to the cloud in the future?

Building CSX files using VSTS

Azure Functions seem like a great idea to develop you microservices/APIs/gateways quickly and without too much overhead. They're scalable, can integrate with plenty of other Azure capabilities seamlessly and are really cheap. However, there's one problem when building your CI/CD pipeline - by default VSTS doesn't know how to build .funproj projects. Although it's easy to fix when building a project locally(by installing a SDK for Azure Functions), VSTS(and probably other build agents) is unable to do so and will greet you with sweet:

The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AzureFunctions\Microsoft.AzureFunctions.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

The solution for this issue is pretty simple - we have to provide missing files to VSTS.

Helping VSTS

If you installed Azure Functions SDK locally you can go directly to:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AzureFunctions\

You will find all missing .props and .targets file needed to build Function Apps. Copy all file from the directory and paste them somewhere next to your project. 

The last thing needed to is to modify .funproj file so it searches for the correct file. Open your .funproj file with any text editor and find <Import Project="..." /> lines. Currently they point to Program Files (x86) directory, what causes VSTS to fail when it tries to build your project because they're unavailable for it. Just change them to something like <Import Project="..\.build\Microsoft.AzureFunctions.Props" Condition="'$(VSToolsPath)' != ''" /> and <Import Project="..\.build\Microsoft.AzureFunctions.targets" Condition="'$(VSToolsPath)' != ''" /> and push to your repository. Now when VSTS tries to run another build, it will go green again.