Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn on/off cloud instances during office hours

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?

like image 935
David Avatar asked Jan 25 '12 12:01

David


5 Answers

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.

like image 186
BritishDeveloper Avatar answered Nov 11 '22 08:11

BritishDeveloper


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:

  • StartInstances()
  • StopInstances()
  • RebootInstances()

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.

like image 40
Steffen Opel Avatar answered Nov 11 '22 08:11

Steffen Opel


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.

like image 38
BrentDaCodeMonkey Avatar answered Nov 11 '22 09:11

BrentDaCodeMonkey


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.

like image 2
sdcharle Avatar answered Nov 11 '22 08:11

sdcharle


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.

like image 1
Mahesh Malpani Avatar answered Nov 11 '22 09:11

Mahesh Malpani