The Ops Community ⚙️

Cover image for Send Custom Notification with AWS Chatbot
Jatin Mehrotra
Jatin Mehrotra

Posted on

Send Custom Notification with AWS Chatbot

AWS Chatbot is ChatOps offering from AWS to monitor, troubleshoot, and operate your AWS environments natively from within your chat channels ( Teams, Slack channels etc)

Until now, there was a limitation that notifications from aws chatbot could not be customised, additional information in the notifications

But with this update, the aws chatbot just got new powers !!!

Outcome of the Blog

Slack Notification

  • By the end of this blog, you will know:
  • How to send custom notifications using chatbot using lambda.
  • Why this update will help users to understand and respond quickly to events.

About this Update [ 12/09/2023 ]

Chatbot feature Update

  • This update will help users to understand more insights about the notification and which will help them to respond quicker.
  • You can add specific details, tag team members, and include remediation steps. It's upto your creativity now that how insightful and information you can make your custom notifications.
  • There are no additional costs to use custom notifications.

Prerequisites for sending custom notifications using chatbot?

  • Custom notifications must use the following event format as mentioned in the docs.
  • Take a note about the parameters which are required and which are optional in the given table in Parameters table.

    "version": String, 
    "source": String, 
    "id": String,    
    "content": {
        "textType": String, 
        "title": String,  
        "description": String, 
        "nextSteps": [ String, String, ... ], 
        "keywords": [ String, String, ... ] 
        "metadata": {                     
            "threadId": String,
            "summary": String,
            "eventType": String,
            "relatedResources": [ String, String, ... ],
            "additionalContext" : {
                "customerProvidedKey1": String,
                "customerProvidedKey2": String
Enter fullscreen mode Exit fullscreen mode
  • Use client specific syntax: If messages are being sent to slack then slack markdown format should be used within custom notification and vice-versa for Teams.

  • From the docs

    You can add chat platform compatible emojis in your custom notifications. You can also tag team members using @mentions in your custom notifications for Slack. Tagged team members are notified when the custom notification is delivered to the chat channel. To tag a team member in Slack, use their user ID. For example, @userID. Tagging team members in Microsoft Teams isn't currently supported.

Architecture Pattern for using custom Notifications

architecture of blog

  • There will be a source which will emit the events with all the details.
  • Either source will generate event (using Lambda) with all the custom information or use EventBridge Input Transformers to add custom information to the original event.
  • Final notifications will be sent to SNS topic.
  • Chatbot will continuously monitor that sns topic and send notification to slack channel.

Let's create a custom notification using aws Lambda.

  • As we saw in architecture pattern we need 3 things to implement and test out custom notification: AWS Lambda, sns topic and chatbot configured for the slack channel

Note: For visual simplicity and understanding, I will be using AWS console for this blog but the same thing can be achieved using AWS CDK.

Create SNS topic

  • Create SNS topic and note its arn.

sns topic

Create a Lambda

import {
} from "@aws-sdk/client-eventbridge"

import { SNSClient, PublishCommand } from "@aws-sdk/client-sns";

const snsClient = new SNSClient({ region: process.env.AWS_REGION });
const snsTopicARN = process.env.SNS_TOPIC_ARN

export async function handler() {

    await publishNotificationToSlack()

    return {
        body: JSON.stringify({ message: 'Successful lambda invocation' }),
        statusCode: 200,

export const publishNotificationToSlack = async (
) => {

 const slackFormatEvent = {
    "version": "1.0",
    "source": "custom",
    "content": {
        "description": ":fire: Your <|post> is gaining traction!!! :fire:",
      "title": ":linkedin: Check Linkedin <@YOURSLACKID|YOURNAME>"

    const response = await snsClient.send(
        new PublishCommand({
            Message: JSON.stringify(slackFormatEvent),
            TopicArn: snsTopicARN,

Enter fullscreen mode Exit fullscreen mode
  • I have attached permissions of full access sns to lambda role so that lambda can send notifications to sns topic directly. From a security point of view you should limit access to only required SNS topic.

Lambda image role

  • Add environment variable to lambda configuration as SNS_TOPIC_ARN: arn of the SNS topic noted earlier

Configure AWS Chatbot client and Slack Channel

  • In order to set up AWS chatbot client for Slack and slack channel, follow the steps mentioned here in docs.

Chatbot slack channel configuration

chatbot client

  • Note: While configuring the Slack channel, add the SNS topic created earlier.

sns topic for chatbot config

Test out the Lambda function

lambda function URL

  • Visit the function URL of the lambda function

Lambda invoke

slack image

From the DevOps perspective

  • This update enables DevOps teams to improve their observability.
  • Allows the team to understand more insights about the notifications as it allows to define and add more information to your notifications.
  • With the support of custom notifications and native client support like slack mentions, it definitely allows the team to respond even more quickly at the time of critical events.

Connect with me over Linkedin or Twitter and share your thoughts about this blog.

Top comments (0)