How to turn on/off cloud instances during office hours
Asked Answered
H

9

21

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?

Hasten answered 25/1, 2012 at 12:22 Comment(0)
A
11

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.

Anasarca answered 25/1, 2012 at 13:0 Comment(1)
FYI the Bamboo AWS Plugin is deprecated: marketplace.atlassian.com/plugins/….Musil
J
12

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.

Jagatai answered 25/1, 2012 at 15:19 Comment(0)
A
11

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.

Anasarca answered 25/1, 2012 at 13:0 Comment(1)
FYI the Bamboo AWS Plugin is deprecated: marketplace.atlassian.com/plugins/….Musil
H
6

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.

Hervey answered 25/1, 2012 at 12:35 Comment(5)
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.Michealmicheil
Can we actually do that today? This setting is part of service definition, not configuration?Metage
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 morningJagatai
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.Metage
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.Hervey
C
2

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.

Cauca answered 21/12, 2014 at 1:22 Comment(0)
E
1

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.

Emmeram answered 21/12, 2014 at 4:58 Comment(0)
L
1

The best article on automation + switching on/off VMs I have found so far. [05 February 2015]. http://clemmblog.azurewebsites.net/using-azure-automation-start-und-stop-virtual-machines-schedule/

Liquorice answered 5/2, 2015 at 17:30 Comment(0)
V
0

Recommended solution for AWS:

The AWS Data Pipeline is uniquely suited to this task. Data Pipeline uses AWS technologies and can be configured to run AWS CLI commands on a set schedule with no external dependencies. Data Pipeline can write logs to S3 and runs in the context of an IAM role, which eliminates key management requirements. Data Pipeline is also cost effective; for example, the Data Pipeline free tier can be used to stop and start instances once per day.

https://aws.amazon.com/premiumsupport/knowledge-center/stop-start-ec2-instances/

Viosterol answered 4/6, 2016 at 9:16 Comment(0)
H
0

Refer to this article, there some options to turn your instances on/off inside AWS.

  • AWS Datapipeline
  • AWS Lambda scheduled events
  • Scheduled Cron on EC2 instance
  • Scheduled Scaling of Auto Scaling Group

So in your case I'd recommend the followings:

For AWS:

Through Shell Command like AWS CLI commands: See Turn on/off Cloud instances using AWS Pipeline. this method will initiate a separate EC2 instance to be started and terminated for each AWS API call that running times affect to your Bill.

Through programming languages like Node.js / Python: See Turn on/off Cloud instances using AWS Lambda. The task running twice a day for typically less than 3 seconds with memory consumption up to 128MB typically costs less than $0.0004 USD/month

For Azure and Rackspace (or other platforms you may have):
Use the above tools to provide a Respective API to start/stop instances on demand.

You may also consider to set scripts-per-boot which runs each time your instance is started.

Haft answered 16/7, 2016 at 5:27 Comment(0)
H
0

AWS

AWS SDK is your best bet but I am using TotalCloud.io to start and stop instances under the free tier. Very customizable.

Easy to setup.

Himelman answered 20/6, 2019 at 8:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.