This article shows how you can use the DataRobot Prime Model functionality to download a DataRobot model and deploy it using AWS Lambda. This example is based on a hospital readmissions dataset, but it can be customized to fit your specific requirements and use cases.
DataRobot Prime can be initiated on most DataRobot models and allows you to download an approximation of a DataRobot model either as a Python or Java module. The code is then easily deployable in any environment and is not dependent on the DataRobot application.
Take a look at this other community article to learn more about DataRobot prime models and how to create and download one, as well as caveats and restrictions. For the purposes of this tutorial, we assume that you already have a DataRobot Prime model downloaded as a Java module.
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 may want to deploy on AWS Lambda:
Company policy or governance decision.
Custom functionality on top of the DataRobot model.
The ability to integrate models into systems that can’t necessarily communicate with the DataRobot API.
In addition, there are also some drawbacks:
No data drift and accuracy tracking out-of-the-box unless MLOps Agents are configured.
Additional time overhead resulting from deploying to AWS Sagemaker.
All in all, it is up to you and your use case to decide where you would want your model to be deployed; DataRobot supports multiple integration options.
The first step to deploying a DataRobot Prime model is to rename the Java file. Your filename should be the same as the public class that in this file so rename *.java → Prediction.java
Then create/Import example project “lambda_prime_example” into the IDE of your choice and:
Copy Prediction.java to Project in the file specified in Figure 1.
Figure 1. Project file structure
Compile the package using the mvn package command.
Click Create function to create a new AWS function.
Figure 2. Create new function
Choose Java 11 to create Lambda.
Figure 3. Programming Language menu
Give the function a name and choose permissions as shown in Figure 4.
Figure 4. Basic Information page
Upload the compiled JAR file to Lambda.
Figure 5. Function code menu
Change the Lambda handler to your Java package . method name to: com.datarobot.examples.scoring.prime.PrimeLambdaExample::handleRequest
The setup is now complete. All that remains is to do some testing to see that the deployment is working as intended.
Testing the Lambda function
To test the Lambda function:
Go to the TEST event configuration page.
Figure 6. TEST event configuration
Put JSON with features as test event: Figure 7. JSON with Features
Click the Test button.
Figure 8. Testing Lambda function
You are all set. Now you can configure the integration with AWS API Gateway or other services so that data is sent to the Lambda function and you receive results back.