First published on MSDN on Oct 09, 2017
In my previous blog, I talked about creating https://blogs.msdn.microsoft.com/mlserver/2017/10/04/enterprise-friendly-java-client-for-microsoft-machine-learning-server/ . In this blog, we will see how easily we can extend this Java client to (1) work with https://aws.amazon.com/lambda/ function and (2) call this lambda function from a https://developer.amazon.com/alexa skill.
For this demo, I will assume that you have published a 'rainService' prediction service that takes a zipcode and returns a percentage number for rain prediction for that day. https://github.com/Microsoft/microsoft-r/blob/master/mlserver-java-clients/Alexa-Lambda-Enabled-RainService/rainService-swagger.json . You can also find the code here: https://github.com/Microsoft/microsoft-r/tree/master/mlserver-java-clients/Alexa-Lambda-Enabled-RainService for rainService.
We can extend the Java client generated from step 1 to handle inputs from Amazon Alexa skill.
I am excited to see all the things that you can achieve using Microsoft Machine Learning Server to make your Alexa skills smarter! Happy coding :)
In my previous blog, I talked about creating https://blogs.msdn.microsoft.com/mlserver/2017/10/04/enterprise-friendly-java-client-for-microsoft-machine-learning-server/ . In this blog, we will see how easily we can extend this Java client to (1) work with https://aws.amazon.com/lambda/ function and (2) call this lambda function from a https://developer.amazon.com/alexa skill.
For this demo, I will assume that you have published a 'rainService' prediction service that takes a zipcode and returns a percentage number for rain prediction for that day. https://github.com/Microsoft/microsoft-r/blob/master/mlserver-java-clients/Alexa-Lambda-Enabled-RainService/rainService-swagger.json . You can also find the code here: https://github.com/Microsoft/microsoft-r/tree/master/mlserver-java-clients/Alexa-Lambda-Enabled-RainService for rainService.
1. Java Client with AWS Lambda function:
- Install AWS Lambda SDK/ toolkit for your IDE. I used this for eclipse: http://docs.aws.amazon.com/toolkit-for-eclipse/v1/user-guide/lambda.html
- Create an AWS Lambda Java project
-
- Make sure you select Input trigger as type "Custom"
-
- Download swagger client for our service's swagger from http://editor.swagger.io . Extract the zip and copy the "io" folder under your Lambda project we just created.
- Edit the handleRequest() method to login to Machine Learning Server, and get response from web server
-
-
- Let's go ahead and build this project by running "maven install" in your IDE/command line. This will generate the JAR for your project.
- You can now login to https://console.aws.amazon.com/lambda , create your lambda function and upload the JAR.
- Congratulations! You have successfully used the Machine Learning Server 'web-services' from an AWS lambda function.
2. Use Machine Learning Server web service with Amazon's Alexa:
We can extend the Java client generated from step 1 to handle inputs from Amazon Alexa skill.
- We will follow steps https://developer.amazon.com/docs/custom-skills/handle-requests-sent-by-alexa.html and create 2 additional classes https://github.com/Microsoft/microsoft-r/blob/master/mlserver-java-clients/Alexa-Lambda-Enabled-RainService/microsoft.mlserver.lambda/src/main/java/com/amazonaws/lambda/demo/MySpeechlet.java and https://github.com/Microsoft/microsoft-r/blob/master/mlserver-java-clients/Alexa-Lambda-Enabled-RainService/microsoft.mlserver.lambda/src/main/java/com/amazonaws/lambda/demo/MlsDemoHandler.java . These will help us process the inputs from Alexa skill.
- Okay, our backend is now ready to handle requests from Alexa skill. Let's setup the Alexa skill now on https://developer.amazon.com/edw/home.html#/skills
- Enter Skill name and invocation details.
-
- Save changes and copy the Application ID. You will need to copy this to your MlsDemoHandler.java class.
-
- Let's recompile the Java client and upload the updated JAR file to our lambda function from step 1.
- Continue making changes to the Alexa skills:
-
- Specify the lambda function's ARN identifier in the Alexa skill as shown below.
-
- We now test the skill on next screen:
-
- At this stage, if your Alexa device is registered under same Amazon account, you can also test using your actual device.
- Congratulations! You have successfully used Microsoft's Machine Learning Server web-service from your Amazon Alexa skill :) if you wish, you can go ahead and publish the skill for all Amazon Alexa users.
I am excited to see all the things that you can achieve using Microsoft Machine Learning Server to make your Alexa skills smarter! Happy coding :)
Updated Mar 23, 2019
Version 2.0SQL-Server-Team
Former Employee
Joined March 23, 2019
SQL Server Blog
Follow this blog board to get notified when there's new activity