Powering SlackBot with AWS
Design
Creating AWS Lambda
- Creating IAM user
Create IAM user with programmatic access
Create the Group with the following Access
Create the user and download the .csv.
2. Create IAM policy
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "logs:CreateLogGroup",
"Resource": "arn:aws:logs:us-west-2:322572314979:*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:us-west-2:322572314979:log-group:/aws/lambda/myGEDWasHelperLambda
:*"
},
{
"Effect": "Allow",
"Action": "dynamodb:*",
"Resource": "arn:aws:dynamodb:us-west-2:322572314979:table/wasGEDTable"
},
{
"Effect": "Allow",
"Action": [
"ec2:CreateNetworkInterface",
"ec2:DeleteNetworkInterface",
"ec2:DescribeNetworkInterfaces"
],
"Resource": "*"
}
]
}
3. Create Role
4. Create Lambda
5. Local code setup
Adding AWS configure
- Open ~/.aws/configure in a text editor
- Add the details from the csv downloaded at the time of creation of IAM user.
[default]
aws_access_key_id=<aws_access_key_id>
aws_secret_access_key=<aws_secret_access_key>
Create the lambda function setup using npm init. After creating the the code add the environment variables in the lambda
Compress into a zip and deploy it as lambda.
zip -r deploy.zip . -x ".idea/*" ".DS_Store" ".git/*" ".gitignore"
aws lambda update-function-code --function-name myWASBotFunction --zip-file fileb://deploy.zip
6. Create API Gateway
Select HTTP API type.
Specify a name.
Specify method as POST
Specify a stage name or leave as $default
Finish
7. Gateway would have been added to Lambda
8. Add Environment Variable SLACK_SIGNING_SECRET in the Lambda from the Configuration tab
9. Create a DynamoDB with the name as given in the policy.
Steps to add Lex
- Create a Lex bot with intents -> here (We are using v1)
- Use the aws-sdk library to communicate with the bot from Nodejs.
- Manage the return output with the help of the intentName and nluIntentConfidence(to be added).
- Send an interactive message to slack for feedback.
Enhance Lex for multiple intents
- Create a dynamoDB table
2. Create a lambda function for handling the fulfillment of intent https://docs.aws.amazon.com/lex/latest/dg/gs2-prepare.html
3. In the intent’s fulfillment section select AWS Lambda function and specify the function.
4. In the lambda function call the dynamoDB for the returning the intent specific result
5. For filling the dynamoDB we can use this function and for creating the lex bot we can use the function to import a lex bot.
6. For creating a bot from import, we need to grant permission through resource-based policy to lambda function created by going to Configuration > Permissions
Adding heartbeat to Lambda to keep it warm
- Open Cloudwatch from AWS console.
- Go to Events > Rules and select Create rule.
- Give the scheduling configuration.
4. Give a name and Create rule.