Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from botocore.vendored import requests
- import boto3
- import time
- region = 'xx-xxxx-x'
- instances = ['x-xxxxxxxxxxxx']
- website = 'https://website.com/'
- webstring = 'SearchText'
- def lambda_handler(event, context):
- for i in range(0,3):
- if check_website():
- return 'Website OK'
- time.sleep(60)
- reboot_instance()
- return 'Restarted instances'
- def check_website():
- r = requests.get(website)
- if webstring in r.text:
- return True
- else:
- return False
- def reboot_instance():
- ec2 = boto3.client('ec2', region_name=region)
- ec2.reboot_instances(InstanceIds=instances)
Add Comment
Please, Sign In to add comment