"How can I change the default Amazon SNS email subject line, "AWS Notification Message", for an EventBridge rule?"
"I configured my Amazon Simple Notification Service (Amazon SNS) to receive email notifications from an Amazon EventsBridge rule that has multiple event sources. How do I customize the default SNS email subject line, "AWS Notification Message," and email body based on the event that triggers the notification?"
"I configured my Amazon Simple Notification Service (Amazon SNS) to receive email notifications from an Amazon EventsBridge rule that has multiple event sources. How do I customize the default SNS email subject line, "AWS Notification Message," and email body based on the event that triggers the notification?Short descriptionThere is currently no way to customize the message of an Amazon SNS email based on specific EventBridge rules using the Amazon SNS console.Use a Lambda function, instead of the Amazon SNS topic, as a target for the EventBridge rule. Then, configure the Lambda function to publish a custom message to the Amazon SNS topic when triggered by the EventBridge rule.Here's how the logic works:The EventBridge rule is triggered.The Lambda function invokes with the payload of the EventBridge rule.The function calls the Amazon SNS publish API.Amazon SNS delivers an email notification with a custom subject or message.ResolutionNote: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure that you’re using the most recent AWS CLI version.Create an AWS Lambda function that is set as a target for the EventBridge ruleFor more information, see Tutorial: Schedule AWS Lambda functions using EventBridge.Important: Make sure that the Lambda function’s execution role has permission to publish to the Amazon SNS topic. For example, if your function's execution role has the AWS managed policy, AWSLambdaBasicExecutionRole, you must attach the AmazonSNSFullAccess policy to the execution role.After the Lambda function is set as a target for the EventBridge rule, the following resource-based policy is automatically added to the function:{  "Version": "2012-10-17",  "Id": "default",  "Statement": [    {      "Sid": "AWSEvents_CWRule_CustomEmailSubject_Id196649187337",      "Effect": "Allow",      "Principal": {        "Service": "events.amazonaws.com"      },      "Action": "lambda:InvokeFunction",      "Resource": "Lambda-function-ARN",      "Condition": {        "ArnLike": {          "AWS:SourceArn": "Eventbridge-rule-ARN"        }      }    }  ]}Configure the Lambda function to publish a custom email subject or a custom message to the Amazon SNS topicFor more information, see Publish (API reference).Important: The following code snippets are for reference only. Don't use the code snippets in your production environment before testing them.Example Python publish API callimport boto3import jsonsns_arn = "SNS_TOPC_ARN"def lambda_handler(event, context):    client = boto3.client("sns")    resp = client.publish(TargetArn=sns_arn, Message=json.dumps(event), Subject="CUSTOM_SUBJECT")Example JavaScript/Node.js publish API callconst AWS = require('aws-sdk');exports.handler = (event, context, callback) => {    let sns = new AWS.SNS();    sns.publish({    TopicArn: 'SNS_TOPIC_ARN',    Message: JSON.stringify(event),     Subject: 'CUSTOM_SUBJECT'    }, function(error, data){       if(error) console.log(error, error.stack);       callback(error, data);     });};Important: Make sure that you replace the values for SNS_TOPIC_ARN and CUSTOM_SUBJECT with your own inputs.In this way, you can use a Lambda function to customize and forward a EventBridge rule’s email subject or message to an Amazon SNS topic.Related informationTutorial: Create an Amazon EventBridge rule for AWS CloudTrail API callsFollow"