Wednesday, 03 February 2010

How Do I Stop the Billing Meter in Windows Azure?

This might come as a surprise to some folks, but in Windows Azure you are billed when you deploy, not when you run.  That means we don't care about CPU hours - we care about deployed hours.  Your meter starts the second you deploy, irrespective of the state of the application.  This means that even if you 'Suspend' your service so it is not reachable (and consumes no CPU), the meter is still running.

Visually, here is the meter still running:

image

Here is when the meter is stopped:

image

Right now, there is a 'free' offering of Windows Azure that offers a limited # of hours per month.  If you are using MSDN benefits for Windows Azure, there is another offering that offers some bucket of 'free' hours.  Any overage and you start to pay.

Now, if you are like me and have a fair number of hosted services squirreled around, you might forget to go to the portal and delete the deployments when you are done.  Or, you might simply wish to automate the removal of your deployments at the end of day.  There are lots of reasons to remove your deployments, but the primary one is to turn the meter off.  Given that re-deploying your services is very simple (and can also be automated), this is not a huge issue to remove the deployment when you are done.

Automatic Service Removal

For those folks that wish an automated solution, it turns out that this is amazingly simple when using the Service Management API and the Azure cmdlets.  Here is the complete, deployment-nuking script:

$cert = Get-Item cert:\CurrentUser\My\<cert thumbprint>
$sub = 'CCCEA07B. your sub ID'

$services = Get-HostedServices -Certificate $cert -SubscriptionId $sub

$services | Get-Deployment -Slot Production | Set-DeploymentStatus 'Suspended' | Get-OperationStatus -WaitToComplete
$services | Get-Deployment -Slot Staging | Set-DeploymentStatus 'Suspended' | Get-OperationStatus -WaitToComplete

$services | Get-Deployment -Slot Production | Remove-Deployment
$services | Get-Deployment -Slot Staging | Remove-Deployment

That's it - just 6 lines of Powershell. BE CAREFUL.  This script will iterate through all the services in your subscription ID, stop any deployed service, and then remove it.  After this runs, every hosted service will be gone and the billing meter has stopped (for hosted services anyway).

Wednesday, 03 February 2010 15:18:27 (Eastern Standard Time, UTC-05:00)
Thanks for clearing that up! What about staging? Is that metered too?

Cheers,
Anthony.
Wednesday, 03 February 2010 18:06:39 (Eastern Standard Time, UTC-05:00)
Yes, this applies to staging as well. Anything you deploy counts. Thanks!
Thursday, 04 February 2010 14:22:12 (Eastern Standard Time, UTC-05:00)
Checked my account purely on a whim this morning and saw that I'd already accumulated a few billable dollars. Thanks for posting this!
Jeff Key
Sunday, 07 February 2010 23:16:49 (Eastern Standard Time, UTC-05:00)
To me "compute hours" sounds very similar to CPU time to me. I feel a bit misled.
Don
Tuesday, 09 February 2010 01:28:01 (Eastern Standard Time, UTC-05:00)
This is valuable information and I particularly like the PowerShell scriptlet that takes care of everything.
Thursday, 25 February 2010 17:29:18 (Eastern Standard Time, UTC-05:00)
Wow. Thanks for the post!

I am pretty disappointed though in Microsoft for this. I absolutly agree with Don that "compute hours" sounds to me like those hours which comuting is happening. If your service is stopped, then there is not any computing. Ok fine, the application is taking up space right even it if is sitting there. Well, I see your point. Please figure out a reasonable fee (much less than the cost of compute hours) for those that want to have their app just sit there not running forever.

I absolutely love Microsoft and have loved Azure, but this is ridiculous.
Tom
Comments are closed.