Search code examples
amazon-web-serviceschatbotslack

Can I customize messages received through Slack's AWS Chatbot integration?


Currently we have set up AWS Chatbot integration for Slack to receive notifications about CodePipeline - results of CodeBuilds and status of all stages of CodePipeline. I have noticed that the out of the box integration's messages aren't as descriptive as I would like.

For example: if a build fails due to a failed unit test the Chatbot will output POST_BUILD: COMMAND_EXECUTION_ERROR: Error while executing command: <command>. Reason: exit status 1 which is fine but I would much rather change that message to be something more descriptive - to tell me that a test has failed.

I figured that Chatbot is subscribed to SNS topics and once those are sent out it will post a message on Slack. Is there a way to customize the contents of the messages it sends?


Solution

  • UPDATE: After reading the docs further, I found out we can not modify event messages in aws chatbot.

    I get an "Event received is not supported" error

    Even though below approach is correct, but notification's originating service is not supported by AWS Chatbot.

    Using AWS Chatbot with other AWS services

    You can have a custom Event Rule like below, I choose for FAILED state you can customize whichever event you want and then subscribe a lambda to it where you can build a meaninful message and then send it to the SNS topic which has AWS Chatbot subscribed :

    {
      "source": [
        "aws.codepipeline"
      ],
      "detail-type": [
        "CodePipeline Action Execution State Change"
      ],
      "detail": {
        "state": [
          "FAILED"
        ]
      }
    }
    

    I did something like this for PagerDuty calls so that on-call person gets a proper message with some more information attached to the alert.