How to turn on/off cloud instances during office hours

18,624

Solution 1

Approach

You could always roll your own solution, insofar most cloud providers offer a respective API to start/stop instances on demand (or even on schedule), which is what those management services are actually using as well of course - the AmazonEC2 Java interface offers all relevant methods for example (amongst many others), specifically:

Via Scripting (EC2)

The most simple approach for this regarding Amazon EC2 would be to craft yourself some Python scripts by means of the excellent boto (An integrated interface to current and future infrastructural services offered by Amazon Web Services), which exposes all EC2 methods mentioned above; you could then start those scripts on demand or via your operating system scheduler.

Via Continuous Integration / Automation (EC2)

Another option would be to facilitate a continuous integration server as an automation engine (a sometimes overlooked aspect of these systems), in case you happen to run one anyway; it would allow you to both start/stop instances on demand or scheduled similar to cron.

We do exactly this by means of the Bamboo AWS Plugin (it's Open Source and the code is available on Bitbucket), see my answer to How to start and stop an Amazon EC2 instance programmatically in java for more details on this approach. While Atlassian Bamboo is a commercial offering, there should be something similar available for popular Open Source CI solutions like e.g. Jenkins as well.

Solution 2

Azure

REST:

You can do this to Azure deployments by using the Windows Azure Service Management REST API. Because it is REST you can use most programming languages to access it.

You could have an application running on your local machine that schedules calls to these services to delete at a certain time at the end of office hours and then create your service again in the morning.

PowerShell:

Or you can manage your deployments in the same way but instead of using REST you can use Azure PowerShell cmdlets. I have done this way myself and it works nicely.

To help you get started there is a nice tutorial on how to do use PowerShell to deploy Azure applications.

also if you didn't already know I should also mention there is a 3month free trial with Azure if you are simply looking for cutting costs whilst developing.

Solution 3

NOTE: As for June of 2013, IaaS Instances can be placed in a "stopped (deallocated)" state. In this state you are only billed for storage of any disks associated with the VM. The original answer below describes a VM instance that is in a "stopped" but not deallocated state. The deallocated state is currently the default for VM stop actions taken via the Azure management portal.

The only way to accomplish this in Widows Azure today is to delete the deployment.

If you stop the service, you are still billed (like renting office space, you pay for it even if you aren't in it), and you can't set the instance count to zero. An option may use is to just reduce the instance count to absolute minimum (1) an then scale it back up during needed hours. But the cost benefits of this will depend on the size of your instances.

Solution 4

Old thread I know, but Microsoft introduced 'Runbooks' for Azure in 2014 that you can use for automation, including scheduled startups and shutdowns. As mentioned above, be sure you are in stopped (deallocated) state, as opposed to just stopped, in order to prevent charges.

More info:

Script to stop your VMs

Azure automation, official MS docs.

Solution 5

Yes Automation Runbook are there by which we can schedule the job. I created the script for stopping (De-allocated) Azure VM.

https://gallery.technet.microsoft.com/Deallocate-all-VM-under-79049c69

Please read about how to use runbook http://azure.microsoft.com/blog/2014/06/19/azure-automation-runbook-management/

Dellocation and stop are different, since stop vm will also incur cost.

Share:
18,624
David
Author by

David

I'm a full time Umbraco Freelancer based in the UK; freelancing since 2011, working with Umbraco since 2009 and web developing since 2002.

Updated on June 06, 2022

Comments

  • David
    David almost 2 years

    I've got my head around creating cloud instances in AWS, Azure and Rackspace. However, I need to turn my instances off at the end of the day and on in the morning as this will half my hosting cost (they are for development).

    I've looked at a few management services but they blew my brains out. Is there a simple way to do this?

  • David Makogon
    David Makogon over 12 years
    Adding to this: If a single instance is still too costly, you can change the VM size to Extra Small during the off-hours, then change it back to something larger during business hours.
  • astaykov
    astaykov over 12 years
    Can we actually do that today? This setting is part of service definition, not configuration?
  • BritishDeveloper
    BritishDeveloper over 12 years
    You can't do that unless you delete the instance, change the source code, and deploy it again. In which case why would you bother?! Just leave it deleted until the morning
  • astaykov
    astaykov over 12 years
    I know how can you do that. And it is not changing source code, but just the service definition file (.csdef). The point is that David mentioned you could do this dynamically, which I don't know to be yet available.
  • BrentDaCodeMonkey
    BrentDaCodeMonkey over 12 years
    Actually you can do an in-place upgrade to change the VM size (as David pointed out) with a new package that contains the updated csdef file for the new targetted size. This enhancement was introduced las fall, and while not ideal, is a stepping stone to hopefully an easier option.
  • Marco
    Marco over 7 years
    FYI the Bamboo AWS Plugin is deprecated: marketplace.atlassian.com/plugins/….