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

Viewed 3722

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?

2 Answers

Official answer no, but there is a workaround I detected. You can use Cloudwatch EventBridge messages and adjust them to your likening.

Simply said

Publish following message

{
"version": "0",
"id": "13cde686-328b-6117-af20-0e5566167482",
"detail-type": "Your custom message",
"source": "aws.ecr",
"account": "123456789012",
"time": "2019-11-16T01:54:34Z",
"region": "azAZ0-9!-_/|?!.,",
"resources": [],
"detail": {}
}

and you'll see something like

AWS Chatbot custom event

And you are free to edit region, detail-type and account according to some limitations

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.

Related