Created
December 28, 2018 21:43
-
-
Save adam-phillipps/4231f23aabde23ba2db407f37c1637f3 to your computer and use it in GitHub Desktop.
pseudo-code to run the after_hours
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
class YourHandler: | |
# ... | |
CEREBRO_URL = 'https://cerebro-backend/api/v1/' | |
def is_handling_this_request(event, context): | |
return True if the event came from your trigger | |
def handle_request(event, context): | |
resource_list = [] | |
def _get_id(hostname): | |
rid = requests.get(CEREBRO_URL + 'instances?hostname=' + hostname)['aws_id'] | |
if rid: | |
return rid | |
else: | |
# get ip from aws | |
found_id = ec2.describe_instances(filter based on ip or whatever)['instance_id'] | |
# update cerebro instances table so it can have an up to date resource id | |
requests.put(CEREBRO_URL + 'instances', data={'aws_id':found_id}) | |
return found_id | |
ah_data = requests.get(CEREBRO_URL + 'after_hours') | |
for resource in ah_data: | |
resource_list.append(( | |
_get_id(ah_data['hostname']), | |
ah_data['start_time'], | |
ah_data['end_time'])) | |
# find out how to trigger the main lambda to shut down all these resources | |
lambda.invoke(MAIN_LAMBDA, resource_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment