Category Archives: Azure

Azure Reservations vs Automated Power Down

Two of the biggest techniques for saving money on Azure Virtual Machines are Reservations and shutting down VMs when they are not in use. However, as they can’t be used together which one is best?

Azure Reservations allow you to rent those VMs for a much cheaper price, but there’s a commitment of 1 or 3 years. One alternative, automated power-down, involves automatically turning VMs on and off based on their usage requirements. For example a service might only need to be available in office hours or Monday-Friday so why leave the server powered on over night when no-one is using it?

Why can’t they be used together? Well, technically they can- but probably it won’t save you any money. An Azure Reservation commits you to paying a (reduced) price for a VM whether or not that VM is powered on, so if you power down that VM with a reservation you’re still paying (unless you have another un-reserved VM of the same size which is on).

This means there are situations when a reservation is cheaper, and situations when not buying reservations and running the power control automation is financially preferable.

Here’s an example. The pricing is from the Azure Pricing Calculator in January 2021 using the UK South region, and may not represent current rates in your chosen Region.

Example:

A Linux D2v3 VM is required Monday-Friday 9am-5pm all year round.
Uptime in the non-reserved scenario is 8 hours/day or 40 hours/week.
So if our VM costs £0.0865 per hour we are charged (£0.0865 x 40=) £3.46 per week, an average of £15.32 for a 31 day month.

If the VM was left on 24/7 on Pay-As-You-Go pricing that would be (£0.0865 x 24 x 7=) £14.532 per week or £54.356 per month.

Uptime in the reserved scenario is always 24 hours/day
With a 1 year reservation the VM has a 37% discount, so the cost is (£14.532 x 0.63=) £9.15 per week or £40 per month
With a 3 year reservation the VM has a 57% discount, so the cost is (£14.532 x 0.43=) £6.25 per week or £27.10 per month

To put that all in a table:

Hours Cost / month
24/7 Pay As You Go£63.14
24/7 Reserved Instance 1 year£40.00
24/7 Reserved Instance 3 year£27.10
Mon-Fri 9-5: 40 hours per week£15.32
Mon-Sun 8-6: 70 hours per week£26.82
Mon-Fri 24/5: 120 hours per week£45.97

If a server needs to be on over 70 hours a week then switching to a 3-year reserved instance that’s on 24/7 becomes cheaper to run. The 1-year reservation becomes the cheaper option at 105 hours per week (e.g. 5am-8pm 7 days a week).

Windows Licensing

I’ve used an Ubuntu Linux VM in the previous example, and for Windows VMs with Hybrid Benefits applied the pricing is the same. Without Hybrid Benefits, where you are paying for the Windows license with the VM the calculations are trickier because the license isn’t subject to the Reserved Instance discount. Using a figure of £50.00 per month our table now looks like this:

HoursCost / month
24/7 Pay As You Go£113.14
24/7 Reserved Instance 1 year£90.00
24/7 Reserved Instance 3 year£77.10
Mon-Fri 9-5: 40 hours per week£26.94
Mon-Sun 8-6: 70 hours per week£47.14
Mon-Fri 24/5: 120 hours per week£80.81

With the Windows license included, that tipping point changes to 115 hours if you’re using the 3-year, or 134 hours if you’re using the 1-year.

VM Sizes

At this juncture I should point out that these discounts vary between VM sizes and regions. Sticking in UK South the 1-year reservation is hits 55% for the DS2v2 instance, and 70% for the 3-year option. That D2v3 used in our example pricing which is discounted at 37%/57% in UK South is cut by 42%/63% in Switzerland North. Of course, all the base prices vary between instance size and region too- so it’s worth running the calculations on your real environment.

Conclusion

Of course there are other factors to take into account when using either method. Reserved Instances are tying you into a period of use on that family of VM so you should be right-sized before signing up and confident that the application is going to outlast the length of the agreement in this state, or if not you will be able to utilise a VM of that size elsewhere in your environment.

On the flip-side there is a certain amount of overhead setting up and maintaining scheduled startup/ shutdown of Virtual Machines, and any experienced IT person will be placing bets on how long it takes for a customer to report that they couldn’t log on to that VM at 11pm on Sunday!

Remember, you can use the Azure Pricing Calculator to work out specific scenarios.

Depicting chemicals with Azure Functions

A guide to quickly setup an Azure function to draw chemical structures from SMILES strings.

This uses the docker image provided by the CDK project to generate image files of a molecular structure based on a SMILES string. Not only is this potentially useful as a component in a larger application, but it also demonstrates using a docker image within an Azure Function. Running this as a function allows it to be run from just pennies a day, but could also be quickly scaled for more demanding solutions.

PowerShell deployment

This should work from a local PowerShell session after using

Connect-AzAccount
to authenticate, or from Azure Cloud Shell.

The script builds out an Azure Function within a new App Service Plan- plus an associated Storage Account and Application Insights. The Azure function pulls the Docker Image from the Docker Hub.

#Script to deploy SMILES depiction function

#Parameters
#Set these variables
$appName=           "cdkdepict01"               #Short Name for Application used in Naming Convention
$tags=              @{"tag-service"="SMILES"}   #Tags to apply to the Resource Group and Resources.
$subscriptionName=  "Pay-As-You-Go"             #The Subscription to deploy to
$location=          "Central US"                #The Azure Region to deploy to.

#Determine the resource names using a naming convention
$resourceGroupName=     $AppName+"-rsg"
$functionName=          $AppName+"-fun"
$appServicePlanName =   $AppName+"-asp"
$storageAccountName =   $AppName+"sto"

#Switch to the correct subscription
    $context = Set-AzContext -SubscriptionName $subscriptionName

"-- Creating Resource Group "+$resourceGroupName +" in " + $location
    $resourceGroup = New-AzResourceGroup -Location $location -Name $resourceGroupName -tag $Tags

"-- Creating App Service Plan "+$appServicePlanName
    $appServicePlan = New-AzAppServicePlan -Location $location -Tag $tags -ResourceGroupName $resourceGroupName `
                        -Name $appServicePlanName -Tier "Basic" -WorkerSize "Small" -NumberofWorkers 1 -Linux

"-- Creating Storage Account "+$storageAccountName
    $storageAccount = New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccountName `
                        -SkuName "Standard_LRS" -Location $location -Kind Storage -Tag $tags

"-- Creating Function "+$functionName+" from Docker Hub image"
    $newFunction = New-AzFunctionApp -Name $functionName -ResourceGroupName $resourceGroupName -DockerImageName "simolecule/cdkdepict" `
                        -PlanName $appServicePlanName -StorageAccountName $storageAccountName -Tag $tags

"-- Finished"

Once executed the resulting web page, with examples, should be available at

https://appname-fun.azurewebsites.net/
(replace appname with the value used in the script.)

Quick Tip- Azure SQL Server Connectivity

Symptoms

  1. An application server in Azure can’t connect to an IaaS SQL Server on Windows (also in Azure).
  2. The Connection Troubleshoot utility in the Azure Portal says network connectivity between the App server and SQL server on port 1433 is allowed:
    image
  3. PowerShell Test-NetConnection on the App server shows that communication with the SQL Server is blocked on port 1433
    image

Cause

Windows Firewall on the SQL Server is blocking communications from the App Server

Solution

Add a rule to the Windows Firewall on the SQL Server to allow SQL Traffic. See Microsoft Docs for details on how to do this.

AZ-104 Azure Administrator Associate

azure-administrator-associate BadgeLast week the Microsoft AZ104 exam went live and all those who took the test during the beta period (myself included) were issued with their results. The good news is I Passed!

This post will discuss the exam and some of the learning resources I used. Just in case your looking for a brain-dump, sorry- I’m not going to be giving out example questions I remembered from my test paper, or even “I had 7 questions on PowerShell, 4 on Application Gateways, and 3 on Custard Flavours”. That’s not allowed, and it’s not really helpful for anyone honestly trying to pass the exam.

Stepping up from Fundamentals

MS Certifications, Click for Full SizeUnsurprisingly the questions were definitely a natural step-up from the AZ900 Fundamentals exam I took last year– and the content here felt more focused on admin tasks- less of the general “Cloud Computing” viewpoint.

This is to be expected as the exam is for the next level up on the qualification ladder, but it also fit’s in with Microsoft’s role-based qualification mentality. In the past there were more product based exams – “Learn everything about Windows Server 2012” for example – but this has been replaced with a “Learn everything you need to be an Infrastructure Admin” or a “Security Engineer” or “Data Engineer” approach. Check out this chart for details of the current certification offerings and how they fit these roles.

Preparation Materials

Earlier in June I sat the official 4-day course (M-AZ104), hosted by Global Knowledge. The trainer, myself, and the 17 other students, were all connected online as the in-person classroom options are not available at the moment. This method works- and I took plenty of notes – but it’s not quite the same as all being together in-person. For starters, we had to provide our own biscuits!

In post-exam hindsight I think the course probably covered all the material, but perhaps not all of the topics were covered to the depths of the exam. So in addition to hands on experience, I supplemented my notes from the training with lab work and using other materials to reinforce areas I felt weaker on. I used some of the following:

The Questions

My exam had a couple of case study type questions, where you’re given a number of questions around a common environment/problem description. This was followed by a big “normal” multiple-choice section in the middle, and then an extra surprise case study bit at the end (I guess for about the last 10 questions or so). There’s plenty of time to do the test, but watch out and manage your time carefully as you can’t go back to the previous sections once you move on.

From memory, all of my questions were multiple choice, or “put these items in order” kind of questions. There is no lab environment in this exam.

Content wise, it was a real spread across everything on the syllabus. In particular make sure you know the proper Azure terms and where they apply- your Availability zones vs Availability sets for example. It would be easy to lose marks by picking the wrong one in a given situation, or even choosing an answer containing a term that doesn’t even exist.

AZ104 succeeded AZ103 as the exam for this qualification and the main points of new content on the syllabus I spotted were around Containers (Azure Container Instances and Kubernetes Service) and Web Apps (including App Services and App Service Plans). Most of the AZ103 learning material is therefore still valid, but make sure you check the updated list of skills required. I think a basic generic understanding of Kubernetes/Docker/Containers would also be worthwhile for that section.

Online Exam

Thanks to the COVID-19 situation, I took this exam from home- not something I’ve done before as I’ve usually gone along to the local testing centre. Here’s a few tips if you’re planning on doing the same:

  1. Find a space at home that’s nice and free of clutter. You can’t have your “Azure for Dummies” poster on the wall and techie books lying around. Also, remember no-one can walk into, or be overheard in, your exam space during the test.
  2. Ensure you have a stable network connection- so you might want to kick the kids off Netflix. I also ran a long ethernet cable out from my broadband router to the room I was taking the test in to avoid wi-fi hiccups.
  3. Prior to the exam (with Pearson) you’re offered a chance to test your environment. It makes sense to do this on the day of your exam, but be aware that it takes some time as you’re not only testing the network/ webcam/ microphone but also going through the process of taking and uploading photos of your testing space – you’ll have to repeat that bit prior to the exam itself.

If you’re planning on taking AZ-104 soon I hope this all helps, and good luck!