Guest User

Untitled

a guest
Oct 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import json
  2. from botocore.vendored import requests
  3. import boto3
  4. import time
  5.  
  6. region = 'xx-xxxx-x'
  7. instances = ['x-xxxxxxxxxxxx']
  8. website = 'https://website.com/'
  9. webstring = 'SearchText'
  10.  
  11. def lambda_handler(event, context):
  12. for i in range(0,3):
  13. if check_website():
  14. return 'Website OK'
  15. time.sleep(60)
  16. reboot_instance()
  17. return 'Restarted instances'
  18.  
  19.  
  20. def check_website():
  21. r = requests.get(website)
  22. if webstring in r.text:
  23. return True
  24. else:
  25. return False
  26.  
  27. def reboot_instance():
  28. ec2 = boto3.client('ec2', region_name=region)
  29. ec2.reboot_instances(InstanceIds=instances)
Add Comment
Please, Sign In to add comment