Skip to content

Event rule to send to SNS in appropriate format?

0

I have an event bridge rule that sends to another SNS topic. Before sending to another SNS topic it must be in a specific format similar to a CloudWatch Alarm like below.

How can I satisfy this requirement?

Would this be an event transformer to use and how? Or shall I have it go to a Lambda function that can alter the output to what I desire?

For the keys, I see in the transformer I can change the values but not sure how to adjust the keys.

{ "AlarmName": "ConfigRuleName", "AlarmDescription": "Config", "AWSAccountId": "account_id", "AlarmConfigurationUpdatedTimestamp": "time", "NewStateValue": "ALARM", "NewStateReason": "non_compliant", "StateChangeTime": "dest", "Region": "us-east-1", "AlarmArn": "alarm", "OldStateValue": "N/A", "OKActions": [N/A], "AlarmActions": [ "arn:aws:sns:us-east-1:<account_id>:Critical" ], "InsufficientDataActions": [], "Trigger": { "MetricName": "N/A", "Namespace": "N/A", "StatisticType": "N/A", "Statistic": "N/A", "Unit": null, "Dimensions": [], "Period": 300, "EvaluationPeriods": 1, "ComparisonOperator": "N/A", "Threshold": d, "TreatMissingData": "N/A", "EvaluateLowSampleCountPercentile": "" } }

1 Answer
1
Accepted Answer

You can use input transformation to transform the text of an event before sending it to a target. This can be done in the console or API.

See this reference guide for how to do so: https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html

Note that you are taking parts of the matched events or constants and recreating a new text format, usually JSON. Here is a tutorial on how to use input transformers: https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-input-transformer-tutorial.html

However, like you said you can also use Lambda where you'll have full control over the transformation process for the desired output. In the Lambda function you can access the event data through the event parameter in your Lambda handler function, transform it to your desired output, and then send the transformed output to an SNS topic. This might be the preferred option if you need a very specific format for your output.

If you need guidance on setting up your function see: https://docs.aws.amazon.com/lambda/latest/dg/python-handler.html

To publish to an SNS topic with a Lambda see this link: https://repost.aws/knowledge-center/sns-topic-lambda

AWS
answered a year ago
EXPERT
reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.