Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
badra001 committed Apr 27, 2023
1 parent 68adcc3 commit f8b6bbe
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions code/ddns-lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -3256,25 +3256,28 @@ def discover_emr_master(tags):


def evaluate_event_action(event):
"""
This takes the EventBridge event and returns a DNS action to take (ADD|REMOVE) based on running or not-running (stopping, terminating). If not an ec2 event, it returns None.

:param dict(str) event: Event dict from handler
:return str: DNS action, either ADD (to create records) or REMOVE (to delete records)
e_source = event['source']
action=None
try:
if e_source=='aws.ec2':
e_instance_id = event['detail']['instance-id']
e_state = event['detail']['state']
action="ADD" if e_state == "running" else "DELETE"
LOGGER.info(f"event_action ** {action} ** instance_id {instance_id} instance_state {e_state}")
else:
LOGGER.info(f"event_action unrecognized source {e_source}")
except:
LOGGER.error(f"event_action event structure cannot be parsed {lineno()}")
return action

"""
This takes the EventBridge event and returns a DNS action to take (ADD|REMOVE) based on running or not-running (stopping, terminating). If not an ec2 event, it returns None.
:param dict(str) event: Event dict from handler
:return str: DNS action, either ADD (to create records) or REMOVE (to delete records)
"""

e_source = event['source']
action = None
try:
if e_source == 'aws.ec2':
e_instance_id = event['detail']['instance-id']
e_state = event['detail']['state']
action = "ADD" if e_state == "running" else "DELETE"
LOGGER.info(
f"event_action ** {action} ** instance_id {instance_id} instance_state {e_state}")
else:
LOGGER.info(f"event_action unrecognized source {e_source}")
except:
LOGGER.error(f"event_action event structure cannot be parsed {lineno()}")
return action


##
# aws: elasticmapreduce: job - flow - id        j - 8O514K6HPIYZ
Expand Down
Binary file modified code/ddns-lambda.zip
Binary file not shown.

0 comments on commit f8b6bbe

Please sign in to comment.