Alkis Kalogeris
Alkis Kalogeris

Reputation: 17745

AWS reboot instances using lambda and scheduled event

I'm using AWS javascript sdk to build a AWS lambda (canary template). I'm using this in order to reboot some instances at a specified interval (everyday at a certain time).

I'm restarting two instances of the same AMI. Below are my questions:

  1. Since there are two instances, I want to reboot the first one and then the second one. I'm doing it this way so no down time is present. I'm rebooting the second instance inside the callback of the first one. Will the success callback be called when the instance has actually rebooted, or should I add some timeout in order to be sure?
  2. The instances I'm running have an auto-scaling group. This means that, if an instance stops, automatically a new instance will be launched. If I reboot my instances, will the auto-scaling group know about this so I won't end up with 4 instances running?

I hope the title is descriptive enough. If it's not feel free to edit it.

Upvotes: 2

Views: 1658

Answers (1)

Shibashis
Shibashis

Reputation: 8401

I am assuming you are using the AWS Javascript sdk

1: The aws node sdk is asynchronous in nature and would return immediately after the reboot command is submitted. You should introduce a wait. I would suggest the describe instance status API to wait, rather than a fixed interval wait.

2: You will not have four instances, as soon as you stop the instance, the asg will terminate the instance and create a new one.

Here is the link to AWS SDK documentation: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#rebootInstances-property

Upvotes: 2

Related Questions