Using Scoring Code Models with AWS Lambda

cancel
Showing results for 
Search instead for 
Did you mean: 

Using Scoring Code Models with AWS Lambda

This article shows how you can use DataRobot’s Scoring Code functionality to download the scoring code of a model and then deploy it using AWS Lambda. This example is based on a hospital readmissions dataset but can be customized to fit your specific requirements and use cases.

Overview

DataRobot automatically runs code generation for those models that support it, and indicates code availability with an icon on the Leaderboard.

fig1. scorecode-icon.png

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 someone 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 can’t necessarily 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.

In addition, there are some drawbacks to this as managing and monitoring externally deployed models requires DataRobot MLOps monitoring agents.

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.

Scoring Code Download

The first step to deploying a DataRobot model to AWS Lambda is to download the scoring code JAR file. Select the model from the Leaderboard, then select Predict > Downloads (Figure 1). Depending on your DataRobot license, the code might only be available through the Deployments page.

Figure 1. DownloadsFigure 1. Downloads

Then, you need to either create your own or import the example project provided here into your IDE.

Figure 2. Lambda Scoring ProjectFigure 2. Lambda Scoring Project

In the pom.xml you need to change the path to the downloaded JAR file:

Figure 3. JAR path placeholderFigure 3. JAR path placeholder

Compiling the project

After you have successfully completed the above steps, it's time to finalize the setup and compile the project.

To start with, find this line in CodeGenLambdaExample.java file 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.

Deploying to AWS Lambda

To deploy to AWS Lambda:

  1. Select Create function from the AWS menu:

    Figure 4. AWS Lambda Function MenuFigure 4. AWS Lambda Function Menu
  2. Choose Java 11 or Java 8 to create the Lambda function:
    Figure 5. Programming Language MenuFigure 5. Programming Language Menu
  3. Enter a name for the function.
    Figure 6. Function NameFigure 6. Function Name

  4. Choose Lambda Permissions as shown in Figure 7.
    Figure 7. Lambda PermissionsFigure 7. Lambda Permissions

  5. Upload the compiled *.jar file to Lambda.

    Figure 8. Upload OptionFigure 8. Upload Option

    Figure 9. JAR file locationFigure 9. JAR file location
  6. Choose the Lambda handler to your Java package name:

    Figure 10. Lambda handlerFigure 10. Lambda handler

The setup should now be complete and 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:

  1. Go to the TEST event configuration page.
    Figure 11. TEST event configurationFigure 11. TEST event configuration
  2. Put JSON with features as a test event.
    Figure 12. JSON with FeaturesFigure 12. JSON with Features

  3. Click the Test button.
    Figure 13. Testing the Lambda functionFigure 13. Testing the 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.

More Information

Check out this community article, Codegen/Scoring Code Feature.

And if you’re a licensed DataRobot customer, search the in-app Platform Documentation for Scoring Code.

Labels (2)
Version history
Last update:
‎06-01-2020 06:35 AM
Updated by:
Contributors