Skip to content

Instantly share code, notes, and snippets.

@anhtv08
Created August 25, 2019 00:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anhtv08/03e425029445dce7392315c87eedef2a to your computer and use it in GitHub Desktop.
Save anhtv08/03e425029445dce7392315c87eedef2a to your computer and use it in GitHub Desktop.
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