Use Scoring Code with AWS Lambda¶
This topic describes how you can use DataRobot’s Scoring Code functionality to download a model's Scoring Code and deploy it using AWS Lambda.
DataRobot automatically runs code generation for those models that support it, and indicates code availability with an icon on the Leaderboard.
This option allows you to download validated Java Scoring Code for a predictive model without approximation; the code is easily deployable in any environment and is not dependent on the DataRobot application.
Why deploy on AWS Lambda¶
While DataRobot provides its own scalable prediction servers that are fully integrated with the platform, there are multiple reasons why you would want to deploy on AWS Lambda:
-
Company policy or governance decision.
-
Serverless architecture.
-
Cost reduction.
-
Custom functionality on top of the DataRobot model.
-
The ability to integrate models into systems that cannot communicate with the DataRobot API. In this case, AWS Lambda can be used either as a primary means of scoring for fully offline systems or as a backend for systems that are using the DataRobot API.
Download Scoring Code¶
The first step to deploying a DataRobot model to AWS Lambda is to download the Scoring Code JAR file from the Leaderboard or the deployment.
Next, create your own Lambda scoring project.
In pom.xml
, change the path to the downloaded JAR file.
Compile the project¶
After downloading Scoring Code and creating a Lambda project, finalize the setup by compiling the project.
To start with, find this line in CodeGenLambdaExample.java
and impute with your model ID:
public static String modelId = "<Put exported Scoring Code model\_id here>";
If you have a classification model, you need to use the IClassificationPredictor interface:
public static IClassificationPredictor model;
If it’s a regression model, use the the IRegressionPredictor interface:
public static IRegressionPredictor model;
Now you can run the maven command mvn package
to compile the code. The packaged JAR file will appear in the target folder of the project.
Deploy to AWS Lambda¶
To deploy to AWS Lambda, use the following steps:
-
Select Create function from the AWS menu:
-
Choose Java 11 or Java 8 to create the Lambda function:
-
Enter a name for the function.
-
Configure Lambda permissions as shown below.
-
Upload the compiled JAR file to Lambda. View the upload options below.
You can view the JAR file location below.
-
Choose the Lambda handler for your Java package name:
The setup is now complete. DataRobot recommends testing the function to see that the deployment is working as intended.
Test the Lambda function¶
To test the Lambda function:
-
Go to the TEST event configuration page.
-
Add JSON with features as a test event.
-
Click the Test button.
After testing is complete, you can integrate with the AWS API Gateway or other services so that data is sent to the Lambda function and it returns results.