From 1d2381abf0e0fc0a0159f06a3aba98b712520661 Mon Sep 17 00:00:00 2001 From: Alex Gottschalk Date: Fri, 22 Feb 2019 00:34:14 -0800 Subject: [PATCH] need to convert from json string to dict when extracting message from event (#30) * need to convert from json to dict here * detect type of message, try to convert from json to dict --- functions/notify_slack.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/functions/notify_slack.py b/functions/notify_slack.py index 43733c8d..769fe357 100644 --- a/functions/notify_slack.py +++ b/functions/notify_slack.py @@ -59,6 +59,11 @@ def notify_slack(subject, message, region): "icon_emoji": slack_emoji, "attachments": [] } + if type(message) is str: + try: + message = json.loads(message) + except json.JSONDecodeError as err: + logging.exception(f'JSON decode error: {err}') if "AlarmName" in message: notification = cloudwatch_notification(message, region) payload['text'] = "AWS CloudWatch notification - " + message["AlarmName"]