Sunday, 7 May 2017

How to get free Azure credits for more than one month and use them efficiently

A good way to learn about cloud development is building prototypes. The most important thing that you need when you want you want to build prototypes in the cloud is a cloud environment and preferably at an affordable price. How does the cost of a cloud environment compare to building prototypes on your local machine?
When you are building prototypes on your local machine, you have first invested in your hardware, your computer and depending on the prototype you want to develop you have invested a certain amount of money in software. Next you are still have your monthly costs like your internet connection and your electricity bill. This means that you immediately know how much you are spending.
When  you are building prototypes in the cloud, you initially start with a low bill, because you have more a pay as you go model, but if you don't pay attention this bill can grow faster than the amount that you would have invested in your bare metal locally. You have however the possibility to play with technologies that are not easily available on your desktop environment. Examples of these are machine learning software and business intelligence solutions.
In this blog post I will go more into detail about how you can get free cloud credits for Azure and things to consider when you are building prototypes with virtual machines.

On a quest for credits
Initially, when I started with building prototypes for the cloud I used a mix of emulators, Azure Machine Learning Studio and the Azure free trial credits for one month of $200. However to keep building prototypes on a continuous basis I needed a more long term supply of credits. Luckily after an extra search on the internet I found the Visual Studio Dev Essentials program. This program provides a lot of free resources for developers but the most important aspect for me were the  $25 or 40 CAD of Azure credits a month for one year. 
In the rest of this blog post I will describe some lessons learnt using these credits in the most optimal way. I will focus on Virtual Machines in this blog post and how the Azure Portal also will help you to identify the highest costs of your cloud consumption.

How the portal tracks the consumption of your monthly credits
The Azure Portal tracks the amount of credits that you have used and makes a forecast about the credits that you will use by the end of the billing period. It also provides a breakdown about the resources that are using the most.
By inspecting these costs on a daily basis you can adjust your spending costs. Next you can also validate whether you really understand how your are spending your credits. For example if you have deleted or stopped a resource and your spending is still not significantly lower, you might still have some ghost parts of this resource living in your Azure account and eating away your credits.

How to optimize the cost of Virtual Machines
What do we want to learn from experimenting with Virtual Machines in the cloud?
In Azure you can choose from various versions of both Windows and Linux operating systems. You can also select the flavor that you want and you need to select different options like the type of drives for the virtual machine, the region and the size and the cost of the virtual machine. Finally you can still select some extra options like the use of managed disks, the availability set and a diagnostic storage account that might add in extra costs.
What is the most cost effective option?
It is important that you have a clear goal about what you want to achieve with the prototype that you are building when you are selecting you virtual machines. For example if you want to understand the various ways about how to connect with a virtual machine or want to experiment with Network interfaces, you don't need a machine with 14 GB of memory, 2 cores and 4 data disks. In the beginning of the billing period you also want to be more more conservative than the end of the billing period. If you however have a more computing intensive project in mind working with more computing power might reduce the number of resources that you are spending.

Be careful when selecting the size of your VM
One of the first things that I learnt was that when you are selecting the size of your virtual machine, don't select one of the recommended options as you can see below. However select the View all option in the upper right corner.

Next scroll down and you will be presented with the A0 Basic and the A1 Basic which are more affordable options to play with. If these cheap options are not available. Select another region for your virtual machine till you have found the A0 and A1 options.

Understand the charges when a virtual machine is turned off
You can turn off a virtual machine from the Azure Portal and in this case nothing is being charged for the compute hours. When you turn on and off your local machine, you expect it still to work. This means that your operating system and all the the software is still left on your drives. In the cloud this means that you need to keep paying for the storage of your virtual machine. 
There are different types of availability and redundancy that can influence the cost significantly. When you also want to make sure that your disk are safe from disaster, you also will need to add in extra backup options.
Next you can also add extra data disks to your virtual machine, these disks are persistent when your virtual machine has been deleted. So make sure also to delete these disks in case that you don't need them any more. Therefore when you have deleted a virtual, make sure that you keep monitoring the costs and that you are seeing the cost reduction that you expected.
Finally there are also still some costs involved with the public ips for the various virtual machines. However the costs of these are small in comparison with the disks. But when you want to remove all the traces from a virtual machine, you will need to delete these ones separately. 

In this blog post we discussed a strategy that gives you free cloud credits for a year. Next we discussed how you can use these cloud credits in an optimal way when you are using virtual machines in the cloud. Good luck with your journey to the cloud.