Summer is famous for its
In just a couple of hours in a relaxed summer atmosphere (courtesy of our HR department for providing these amazing lounge chairs) our devs were able to test AWS Lambda by making a Slack Bot. The idea was to check how we could automize and build a development environment for a healthcare client - meaning it needed to be HIPAA compliant (whence AWS Lambda and Slack).
AWS Lambda Slack Bot
To create AWS Lambda Slack bot we first needed to configure the following resources:
AWS API Gateway
AWS Service that enables users to create API endpoints.
AWS Lambda Function
Implementation of bot logic.
Slack can be integrated with AWS Lambda using: Slack Slash Commands, Slack WebHooks or with Slack Application. In this
For those who have no prior knowledge of Lambda, we scraped up some information from several online resources.
What is AWS Lambda?
AWS Lambda is a
Details can be found in the following location: http://docs.aws.amazon.com/lambda/latest/dg/welcome.html
One key to Lambda is that customers only pay for the service when functions are executed (so, this may or may not suit you, but is an interesting setup).
Possible use cases for AWS Lambda are given in the AWS documentation: http://docs.aws.amazon.com/lambda/latest/dg/use-cases.html.
The use case covered in this presentation is: “On-demand Lambda function invocation over HTTPS (Amazon API Gateway)”.
In this use case, the AWS Lambda function is invoked over HTTPS. To accomplish this we need to create the API endpoint and then configure it so that it invokes our Lambda on request. For
You can find a description of the Lambda function programming model at this link: http://docs.aws.amazon.com/lambda/latest/dg/programming-model-v2.html
The simple function can be programmed directly in the AWS console online interface. In cases when the Lambda function logic is more complex it can be coded locally and uploaded as a ZIP file.
The following are some
Building the bot
We need to install and configure the AWS
Setup AWS CLI (Command Line Interface)
The AWS CLI is a command line utility that provides a consistent interface for interacting with all parts of AWS. The documentation can be found here: https://aws.amazon.com/documentation/cli/.
The best way to install it on windows is to use the MSI Installer: http://docs.aws.amazon.com/cli/latest/userguide/awscli-install-windows.html#install-msi-on-windows.
Once the client is installed we need to
The profile consists of:
You can generate the id and key in the AWS online web console, by going to:
Services > IAM > Users > (Select user) > Security credentials > Create access key.
It is recommended to create a developer user and use it for id and key generation and not to use your master AWS user for this.
Implement the function
Before we start the implementation, we need to install the Claudia node package globally:
Run the following command:
npm install claudia –g
Create new node project by running the command:
Install the Claudia Bot Builder package:
npm install claudia-bot-builder –S
Create a file named bot.js in the project root folder and insert the following code in it:
var botBuilder = require('claudia-bot-builder');
Deploy and connect with Slack
Setup Slack Slash Command
To create Slash Commands, go to the custom integrations page on slack, select “Slash Commands,” and select Add Configuration.
The custom integrations Slack page URL is similar to the following, just replace “
The Token will be generated for the slash command. The token value will be needed to configure the AWS Lambda bot.
Deploy Lambda Function
To deploy the function to AWS we run the following command:
claudia create --region us-west-1 --api-module bot --configure-slack-slash-command
Please note that you can use a different region if you need.
You will be prompted to enter the:
- Slack token - Paste the value from the Slack Slash Command token page.
- Outgoing webhook token - type none, because it is needed by
claudiaand we are not using it.
After the command creates all resources on AWS, it will display the URL of the AWS API Gateway that was created.
Your Slack slash command Request URL (POST only) is https://iefuytia4l.execute-api.eu-west-1.amazonaws.com/latest/slack/slash-command
This URL needs to be copied to the Slack Slash Command page URL field.
Open slack and insert your slash command followed by any other text.
If I enter the command in the Slack:
The response AWS sends is:
The following AWS resources were created in this process:
The API Gateway
The Lambda Function
The security role for the function
Possible use cases in healthcare?
This is a great way to do a quick test of your ideas in a secure way. All healthcare segments (payers,
In the meantime, IBM prepared their response to AWS’s Lambda, thanks to deeper partnerships with Apple, GitHub, and VMware. IBM is also launching a new cloud service called Bluemix OpenWhisk. We also had the chance to play with it and if we must pick a winner for us it would be OpenWhisk, but then again being IBM’s premier partner we might be biased.
Until the next episode of Summer in the Health Cloud our team wishes you sunny SF weather.