I have message coming from SNS (CloudWatch alarm) to an AWS Lambda function. It is in below format. Lambda then email message via other SNS. But in email, message does not get formatted. It appears as below. How can I format message?
{"AlarmName":"sf-datalake-pcclaims-test-use1-datastream-ade-bytes","AlarmDescription":"Less than one bytes are read in last one minute.","AWSAccountId":"364206986528","NewStateValue":"ALARM","NewStateReason":"Threshold Crossed: 1 datapoint [0.0 (31/12/19 17:52:00)] was less than the threshold (1.0).","StateChangeTime":"2019-12-31T17:53:05.509+0000","Region":"US East (N. Virginia)","OldStateValue":"INSUFFICIENT_DATA","Trigger":{"MetricName":"GetRecords.Bytes","Namespace":"AWS/Kinesis","StatisticType":"Statistic","Statistic":"MINIMUM","Unit":null,"Dimensions":[{"value":"sf-datalake-pcclaims-test-use1-datastream-ade","name":"StreamName"}],"Period":60,"EvaluationPeriods":1,"ComparisonOperator":"LessThanThreshold","Threshold":1.0,"TreatMissingData":"- TreatMissingData: missing","EvaluateLowSampleCountPercentile":""}}
My code is as below:
import json
import boto3
def lambda_handler(event, context):
client = boto3.client('sns')
message = json.dumps(event['Records'][0]['Sns']['Message'])
response = client.publish(
TargetArn='arn:aws:sns:us-east-1:xxxxxxxxx:datalake-pcclaims-test-use1-email-error-alerts',
Message=message,
Subject='a short subject for your message',
MessageStructure='string'
)
print("From SNS yyyyyyyyyyyyyy: " + message)
return {
'statusCode': 200,
}