Even though I work for the Azure and ASP.NET team, I still pay for my own Azure account. Frankly, if I did get free cloud time not only would I likely abuse it, but I also wouldn't be using the cloud in the way it's meant to be used! From my perspective, a good cloud is a cheap cloud. I use CDNs, caching, and focus on a balance of cheap resources and compute that work for me when I need them, and are asleep (and not costing me money) when I don't.
There's things like auto-scale for websites, for example, based on either CPU or a schedule, but the one thing that gets me into trouble (sometimes) is leaving big virtual machines on. I manage most of my Azure assets from the command line, so I can just "azure vm list" to see what's running and I'll see this:
C:\Users\scottha
λ azure vm list
info: Executing command vm list
+ Getting virtual machines
data: Name Status Location DNS Name
data: -------------------- ------------------ -------- -------------------------------
data: VSinTheSky StoppedDeallocated West US vsinthesky.cloudapp.net
data: hanselmandiscourse StoppedDeallocated West US discourse.cloudapp.net
data: hanselmansendy ReadyRole West US sendy.cloudapp.net
data: hanselmanlinuxfarm StoppedDeallocated West US linuxfarm.cloudapp.net
data: hanselmanlinuxfarm-2 StoppedDeallocated West US linuxfarm.cloudapp.net
data: hanselmanlinuxfarm-3 StoppedDeallocated West US linuxfarm.cloudapp.net
data: hanselmanmysql ReadyRole West US mysql.cloudapp.net
info: vm list command OK
If I want to shut one down I can use the command line, the Azure Portal, or even manage VMs within Visual Studio itself:
But sometimes I have custom apps to manage Azure resources, perhaps WinForms or WPF apps, MSBuild Tasks, or I want to add cloud management to an existing process. I'll want to not just turn off VMs, but also manage WebSites, create resources, upload things to storage and more.
I just learned from Brady Gaster that there's now Windows Azure Management Libraries for .NET as part of the Azure SDK. Basically this means that you can call the same backend REST APIs that the Azure Portal calls now, except now with a simple wrapper around them that makes it rather a bit easier in .NET.
Brady has a lot of info on his blog about this libraries. Here's some of the best highlights:
- Supports Portable Class Libraries (PCL)
- Ships as a set of focused NuGet packages with minimal dependencies to simplify versioning
- Supports async/await-based task asynchrony (with easy synchronous overloads)
- Has a shared infrastructure for common error handling, tracing, configuration, and HTTP pipeline manipulation
- Is factored for easy testability and mocking
- Is built on top of popular libraries such as HttpClient and Json.NET
- Is all open source and on GitHub.
They are on NuGet as a group of packages but you can get them separately if you want to just manage VMs, for example. Here's the version I'm using from NuGet. Note it's prerelease as of the date of this writing. https://www.nuget.org/packages/Microsoft.WindowsAzure.Management.Libraries
Azure authentication and authorization is based on X509 Certificates, so you'll use those to initially talk to your Azure instance. You can download your certificates from an authenticated session here and your certificates and subscription id are inside.
I can list out, for example, all my running websites in all their locations (web spaces):
using (var client = new WebSiteManagementClient(creds)) {
var spaces = client.WebSpaces.List();
foreach (var space in spaces) {
Console.WriteLine("Space: {0}", space.Name);
var sites = client.WebSpaces.ListWebSites(space.Name, new WebSiteListParameters{ PropertiesToInclude = { "Name" }});
foreach (var site in sites) {
Console.WriteLine(" " + site.Name);
}
}
}
This little app gives me this output:
Space: eastuswebspace
SmallestDotNet
Space: northcentraluswebspace
Hanselminutes
Space: northeuropewebspace
Space: westuswebspace
babysmash
nerddinnerofficial
ratchetandthegeek
speakinghacks
thisdeveloperslife
hanselmanlyncrelay
HanselmanGhost
anglebrackets
lostphonescreen
loggingtest
GetInvolved
keysleft
I can go and update sites, disable (stop) them, make web farms, scale them, create, configure and generally do everything I can from the command line. Very slick. Now I can manage Azure stuff from PowerShell, from .NET, from node and the cross platform command line, Visual Studio, and the Azure Portal.
Go read all about Windows Azure Management Libraries on Brady's blog, get them on NuGet, or read the code and enter issues on GitHub.
if you link your MSDN and Azure accounts and you can get up to $150 a month in Azure credits, so up to two free VMs running all day for a month.
I've done a few posts on "Penny Pinching in the Cloud" that you may enjoy.
- Penny Pinching in the Cloud: When do Azure Websites make sense?
- Penny Pinching in the Cloud: Enabling New Relic Performance Monitoring on Windows Azure Websites
- Penny Pinching Video: Moving my Website's Images to the Azure CDN (and using a custom domain)
- Penny Pinching Video: Moving an Azure Website between data centers
- Pinching pennies when scaling in The Cloud - lazy loading images and using the Azure CDN to save money
- Penny Pinching in the Cloud: How to run a two day Virtual Conference for $10
Also, I encourage you to check out Azure Friday, a new show I'm doing at http://friday.azure.com. Azure Friday also on iTunes as a downloadable podcast in HD!
Sponsor: Thanks to Aspose for sponsoring the blog feed this week! Aspose.Total for .NET has all the APIs you need to create, manipulate and convert Microsoft Office documents and a host of other file formats in your applications. Curious? Start a free trial today!
© 2013 Scott Hanselman. All rights reserved.