How the formatter works
The formatter has two distinct code paths depending on the structure of the incoming message.Pass-through: messages with attachments or text
If the parsed JSON message already contains an attachments or text key at the top level, the payload is merged directly into the Slack request without any further processing. This lets you publish a fully-formed Slack message payload to SNS and have it forwarded as-is.
Key-value fields: arbitrary JSON objects
If the message is a JSON object that does not containattachments or text, each key-value pair is rendered as a separate field in the Slack attachment.
String values shorter than 25 characters are displayed inline (side by side). Longer values are displayed on their own line. Dict and list values are JSON-serialized before display.
subject value is used as the Slack attachment title when provided.
Plain text strings
If the message body is not valid JSON, the Lambda treats it as a plain text string and renders it as a single field value.Routing specific message types with filter policies
If you publish multiple message types to the same SNS topic, you can use SNS subscription filter policies to control which messages the Lambda receives.event_type message attribute with the value alert or warning are delivered to the Lambda. Other messages are dropped before they reach the function.