It's inspired by Chaos Monkey, but the randomness is determined by what the chatters are talking about on a Slack channel. The bot wouldn't know up front what the humans will be saying and when they will say it, that's natural randomness we're taking advantage of.
Here's an example of a conversation between Bruce Wayne and Tony Stark on a Slack channel, which messages are analysed by Chaos bot, and are used to determine whether to terminate a random EC2 instance.
Chaos has two components, a bot that's configured on Slack, and a piece of infrastructure on AWS.
The bot is a Slack outgoing webhook custom integration.
The infrastructure on AWS is a Lambda function that receives POST requests from the Slack bot via an API Gateway, it parses the messages using a simple natural language processing speakeasy-nlp package, those messages will then be used to determine whether to terminate a random EC2 instance from the specified Auto Scaling Groups.
Chaos currently supports a mode called
sentiment, which processes the messages based on positive/negative sentiment using speakeasy-nlp. It is easy to introduce new modes in the future for other processing algorithm(s).
There are two parts to install, the bot on Slack, and the infrastructure on AWS.
Let's install the bot first by creating a Slack outgoing webhook custom integration.
- Go to your Slack account's custom integrations page at
- The page will show the available custom integrations. Click on Outgoing WebHooks link.
- Click Add Configuration button.
- Click Add Outgoing WebHooks integration button.
- Fill in the integration settings:
- Channel: select the channel where you want the bot to be running on, pick a channel with many users, e.g. #general
- Trigger Word(s): leave this empty because we want to consume all messages
- URL(s): leave this empty for now, we'll go back to this option after the infrastructure is built.
- Token: Slack will generate the token for you, this token will be configured in Lambda function.
- Descriptive Label: description for this custom integration, e.g. Chaos Outgoing WebHook
- Customize Name: the name of your bot, e.g. Chaos
- Customize Icon: upload Chaos astro monkey icon
- Click Save Settings button.
Next, the second part is to create the infrastructure on AWS.
- Install node.js .
- Set up AWS credential, to be used by Serverless framework.
- Clone the repository:
git clone https://github.com/shinesolutions/chaos-slackbot.
- Configure the Slack token from the outgoing webhook custom integration settings in
conf/config.json. Add the token to
- Configure the Auto Scaling Group names in
autoScalingGroupNamesarray property. (TODO: move this to SimpleDB so this can be programatically configured outside of Chaos Slackbot)
- Install tools and dependencies:
make tools deps.
- Build the Lambda function and API Gateway:
make deploy. The output of this command will show a POST endpoint, e.g.
- Return to the Slack Outgoing WebHook custom integration settings page, and copy paste the POST endpoint from the command output to URL(s) setting, then click Save Settings button.
- Have the users join the Slack channel configured in the bot setting, e.g. #general .
- Chaos bot will start consuming the messages from that channel, and when the algorithm hits, it will terminate a random EC2 instance.
Chaos Slack bot Lambda function can be configured in conf/config.json .
|allowedTokens||An array of allowed Slack tokens. If any is specified, then only incoming requests with that token are accepted. If left empty, then all incoming requests are accepted.|
|mode||Chaos mode to determine message processing rule, currently only supports
|ignoredUserNames||An array of Slack usernames to be ignored, at the very least you want to ignore
|controlledStartHour||Start hour of the day when Chaos bot is allowed to terminate EC2 instance. Valid value: 0 to 24.|
|controlledEndHour||End hour of the day when Chaos bot is no longer allowed to terminate EC2 instance. Valid value: 0 to 24.|
|timezone||Timezone for controlledStartHour and controlledEndHour. Use Moment Timezone to find valid timezone values.|
|terminationLimit||The number of message hits before Chaos terminates a random EC2 instance. The specified mode determines how a message hit is calculated.|
|autoScalingGroupNames||An array of whitelisted Auto Scaling Group names. EC2 instances that belong to these Auto Scaling Groups are candidates for termination.|
|simpleDBDomainName||The name of SimpleDB database domain.|
Install Serverless framework and other tools:
Download library dependencies:
Build the infrastructure with default prod stage:
Remove the infrastructure with default prod stage:
Specify custom stage:
STAGE=dev make deps deploy remove
This project is a submission to AWS Serverless Chatbot Hackathon 2016 - with self-imposed 24-hour total time limit scattered across several days/nights.