in cloudformation/lambda_backup.py [0:0]
def lambda_handler(event, context):
try:
logger.info(json.dumps(event))
message = event['detail']
if LIFECYCLE_KEY in message and ASG_KEY in message:
life_cycle_hook = message[LIFECYCLE_KEY]
auto_scaling_group = message[ASG_KEY]
instance_id = message[EC2_KEY]
if check_document():
command_id = send_command(instance_id)
if command_id != None:
if check_command(command_id, instance_id):
logger.info("Lambda executed correctly")
else:
abandon_lifecycle(life_cycle_hook, auto_scaling_group, instance_id)
else:
abandon_lifecycle(life_cycle_hook, auto_scaling_group, instance_id)
else:
abandon_lifecycle(life_cycle_hook, auto_scaling_group, instance_id)
else:
logger.error("No valid JSON message: %s", parsed_message)
except Exception, e:
logger.error("Error: %s", str(e))