Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #31 from TechNative-B-V/feature/update-alarm-creat…
Browse files Browse the repository at this point in the history
…or-function

Updated err_msg with the lambda ARN incase the lambda function might have an error to also display the Lambda ARN in the error details
  • Loading branch information
AndrNgg authored Sep 11, 2024
2 parents ede71e9 + 45d477a commit 4fc9a2f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions alarm_creator/lambda_function.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import boto3
import json
import os
import logging
import traceback
import sys
import boto3, json, os
import logging, traceback, sys
import datetime
from actions import AWS_Alarms, DeleteAlarms

Expand All @@ -14,8 +10,9 @@
sns_arn = os.environ["SNS_ARN"]



def lambda_handler(event, context):
print(event)
function_detail = context.invoked_function_arn

try:
print("{}: AWS_Alarms()".format(datetime.datetime.now()))
Expand All @@ -28,17 +25,20 @@ def lambda_handler(event, context):
traceback_string = traceback.format_exception(
exception_type, exception_value, exception_traceback
)
# Create a JSON dump with the details to publish to the SNS topic in case of an exeception.
err_msg = json.dumps(
{
"functionDetail": function_detail,
"errorType": exception_type.__name__,
"errorMessage": str(exception_value),
"stackTrace": traceback_string,
}
)

# Publish the error message to the SNS topic
client.publish(
TopicArn=f"{sns_arn}",
Subject="Error Creating CloudWatch Alarm",
Subject=f"Error Creating CloudWatch Alarm",
Message=json.dumps({"default": err_msg}),
MessageStructure="json",
)
Expand Down

0 comments on commit 4fc9a2f

Please sign in to comment.