Sometimes we might have to reboot EC2 instances. If the requirement is to restart EC2 instances regularly, we can achieve it by writing a small piece of code. I also came across a similar requirement and a portion of the code I used is given below.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|__author__ = 'Amal G Jose'|
|self.instance_id_list = ["i-xxxxxx", "i-xxxxxx", "i-xxxxx", "i-xxxx", "i-xxxxx", "i-xxxxx", "i-xxxxx"]|
|self.aws_access_key = "XXXXXXXXXXX"|
|self.aws_secret_key = "XXXXXXXXXXX"|
|self.region = "xx-xxxx-x"|
|self.conn = boto.ec2.connect_to_region(self.region,|
|print "Rebooting instances: %s" %(str(self.instance_id_list))|
|except Exception, e:|
|print "Error occurred while restarting instances: %s" %(str(e))|
|if __name__ == '__main__':|
|restart = EC2Reboot()|