Date post: | 15-Apr-2017 |
Category: |
Technology |
Upload: | torontonodejs |
View: | 719 times |
Download: | 0 times |
Building your own Slack bot on the modern AWS stackAndrew CarreiroPlatform Architect, Klick Health
Demo
Basic Structure
SlackChat app that lets us POST data by typing /8ball
Amazon API GatewayReceives the request from Slack, and routes the request to Lambda
Amazon LambdaEvaluates the chat command, and returns a response.
Amazon DynamoDBNoSQL backend for the app
API Gateway
Lambda
DynamoDB
/8ball Should I try AWS?
POSTInvokes
Possible answers are saved & read
Responds
Responds
“Absolutely!” 8
DynamoDB
Why DynamoDB?
- Need for this app: persistent data store across requests- A JSON file on S3 also a possibility given scale- Something like Redis (Amazon Elasticache) could also work, but price
prohibitive- DynamoDB pricing structure is confusing, but you get 25GB storage and
~200M requests per month in the Free Tier
API Gateway
Lambda
DynamoDB
/8ball Should I try AWS?
POSTInvokes
Possible answers are saved & read
Responds
Responds
“Absolutely!” 8
Writing the Lambda Function
What is Amazon Lambda?
- Old method: I need a server to execute my code- Server sits idle sometimes, other times is completely overwhelmed
- Use AWS computing power, and be billed by the 100ms- Theoretically infinitely scalable, if you have the money- Can run Node, Java, or Python
Coding for Lambda
- Amazon Lambda uses Node.js: v0.10.36- Deployment in it’s most basic state involves a manual zip upload
- lightweight is best-- adding Babel.js was a pain for uploads
- Expect your tests to work locally
Coding for Lambda
Create a user and credentials for what you need:https://console.aws.amazon.com/iam/home?region=us-east-1#users
~/.aws/config
[default]output = jsonregion = us-east-1
Coding for Lambda: Config and Credentials
~/.aws/credentials
[default]aws_access_key_id = LINDNWVQQKAKP7BIA5TXaws_secret_access_key = L4Q8mgs4o4dO4qe3RBbXPSZPfhOQFnj1U2dlDn30
Lambda Example Code
Deploying Lambda
Approaches
https://github.com/mentum/lambdaws
https://github.com/jaws-framework/JAWS
Manual Lambda setup
API Gateway
Lambda
DynamoDB
/8ball Should I try AWS?
POSTInvokes
Possible answers are saved & read
Responds
Responds
“Absolutely!” 8
Setting up API Gateway
API Gateway
Lambda
DynamoDB
/8ball Should I try AWS?
POSTInvokes
Possible answers are saved & read
Responds
Responds
“Absolutely!” 8
Adding a Slash Command on Slack
GitHub Repogithub.com/andrewcarreiro/slack-8ball
RyanRay URL Encoding gisthttps://gist.github.com/ryanray/668022ad2432e38493df
Klick Health is hiring!
Thanks