Slack bot that blurts out spider facts when a key word is triggered. Bot based on mattmakai's work
- Create
spiderfacts
bot on your slack team. - Place the bot into whatever channels you wish it to be a member of.
- Copy the API token into the
SPIDER_FACTS_TOKEN
environment variable on the machine where the code will run. - Run
spiderfacts.py
whenever you want your bot to be active.
From AWS Guide
docker build -t spiderfacts .
=> Builds Docker image.Dockerfile
must be created before the command will run
docker images --filter reference=spiderfacts
=> Confirm image was madedocker run -e docker run -e SPIDER_FACTS_TOKEN=xoxb-############-######################## spiderfacts
=> Run the program in Docker. Note, this will continue running until it is manually stopped. Running this command repeatedly will run multiple spiderfacts instances.- populate the hashes with the slack API token
aws ecr create-repository --repository-name spiderfacts
docker tag spiderfacts aws_account_id.dkr.ecr.region.amazonaws.com/spiderfacts
aws_account_id
must be replaced with theregistryId
provided in the previous command.region
must be replaced with whatever region is being used.
aws ecr get-login --no-include-email
=> get the docker login authentication command string for your registry- Provides an authorization token that is valid for 12 hours. It's just a big command that needs to be entered. Read the AWS Guide link posted above for more info, especially about using authentication from unsecured computers.
docker push aws_account_id.dkr.ecr.us-west-2.amazonaws.com/spiderfacts
=> Docker image is now sitting on AWS.
- Create a file called
spiderfacts-task-def.json
with the following contents, substituting the repositoryUri from the previous section for the image field, and env variable filler text for the real slack API token (same one with running the docker image locally):
{
"family": "spiderfacts",
"containerDefinitions": [
{
"name": "spiderfacts",
"image": "aws_account_id.dkr.ecr.us-west-2.amazonaws.com/spiderfacts",
"cpu": 1,
"memory": 500,
"essential": true,
"environment": [
{
"name": "SPIDER_FACTS_TOKEN",
"value": "xoxb-############-########################"
}
]
}
]
}
aws ecs register-task-definition --cli-input-json file://spiderfacts-task-def.json
=> Register a task definition- At this point, a cluster must be created before continuing. I created mine from the web interface because I wasn't sure how to do it from the AWS CLI.
aws ecs run-task --task-definition spiderfacts --cluster spiderfacts
- Neither AWS nor Docker need port rules for the app to function.
- The Docker image will need to be rebuilt any time code changes. There is a way to mount a "code" volume the Docker image can share with one's dev machine. Combining that setup with a tool like nodemon will allow the developer to simply save the file to refresh the Docker image to the latest dev version.
- Automate the above with something like Concourse! CircleCI -> run tests, build Docker image, publish image to artifactory. Then use Concourse (aws CLI) or Terraform (modular config format, can resume from last errored state, publish to most cloud providers, best way) or Cloudformation (single file, has to restart entire deploy, publish only to AWS, still better than AWS CLI) to push image to AWS and everything else you need.