Created
August 25, 2019 00:22
-
-
Save anhtv08/03e425029445dce7392315c87eedef2a to your computer and use it in GitHub Desktop.
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
def evaluate_ec2_instance(ec2_client, event): | |
instance_id = event['detail']['instance-id'] | |
instance_state = event['detail']['state'] | |
''' | |
only perform this evaluation rule when starting an new instance | |
check if instance state is pending then try to perfrom evaluation | |
''' | |
if instance_state != 'pending': | |
log.info('current state : ' + instance_state) | |
return | |
tag_list = get_tag_for_instance_id(ec2_client, instance_id) | |
if not tag_list: | |
shutdown_ec2_instance(ec2_client, instance_id) | |
else: | |
if not validate_tag_name(tag_list): | |
shutdown_ec2_instance(ec2_client, instance_id) | |
else: | |
log.info("Instance has been tagged properly") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment