Automation

Bedrock supports the use of automation tools like Jenkins through its REST API.

This tutorial demonstrates how to orchestrate the deployment of a machine learning service on Bedrock. You will set up a Jenkins pipeline to:

  1. Query the Model Store for new versions of a model

  2. Deploy a new version of a model to an HTTP endpoint if it meets specific training performance metrics like accuracy, precision and recall.

Prerequisites

  • A Bedrock account with an Environment provisioned,

  • A running Jenkins instance with the HTTP Request plugin,

  • Some familiarity with Groovy, and

  • Successfully created an end-to-end ML service on Bedrock using our demonstration project.

The Jenkins HTTP Request plugin is not a requirement to using Jenkins with Bedrock, but allows us to simplify this tutorial. It can be replaced by any tool/library for making HTTP requests.

Review your ML service on Bedrock

After completing the demonstration project, you should have have successfully:

  • Created and run a Training Pipeline from a remote git repository that you can find by clicking Pipelines on the top menu bar.

  • Produced a model that you can find by clicking Models on the top menu bar.

  • Deployed an endpoint backed by a model server that you can find by clicking Endpoints on the top menu bar.

Create a Bedrock Personal API Token

As Jenkins will interact with Bedrock over its REST API, we need to provide Jenkins with the appropriate credentials to authenticate with Bedrock. This is done using a Bedrock Personal API token.

To generate a personal API token, follow the instructions in this guide.

Load your Bedrock Personal API Token into Jenkins

Load your Personal API Token into Jenkins's credential management system by following the instructions here.

To work with the demonstration project, save the API token as a secret text under the name bedrock-access-token.

In a production setting, your team might have additional policies on how secrets should be organised within and without Jenkins.

Create a deployment pipeline on Jenkins

  1. On the Jenkins web UI, click New item.

  2. In the Enter an item name field, specify the name for your new Pipeline project (e.g. churn-prediction-service).

  3. Select a Pipeline project type, then click OK.

  4. On the next page, scroll down to the Pipeline section.

  5. In the Definition field, choose the Pipeline script from SCM option. This option instructs Jenkins to obtain your Pipeline from a Source Control Management system.

  6. In the SCM field, choose Git.

  7. In the Repository URL field, enter the path of the demonstration project repository https://github.com/basisai/churn_prediction.

  8. In the Script Path field, enter jenkins/Jenkinsfile. This is the path to the file Jenkins uses to define a build pipeline.

  9. Click Save to save your new Pipeline project.

Review your deployment pipeline

In this tutorial, we make use of Jenkins's declarative pipeline syntax. A working example has been provided as part of the demonstration project that you can review here.

This example pipeline does the following:

  1. Checks for the latest Model Version for a specific Model‚Äč

  2. Concurrently,

    1. Runs (simulated) unit tests on the serving code.

    2. Checks if the latest version of the model fulfils certain accuracy, precision and recall requirements. If these requirements are not met, the build is failed.

  3. Deploys the model serving code and latest Model Version to a specified endpoint.

  4. Waits up to 5 minutes for the Model Server to pass Bedrock's health check and become active. If the model does not become active within a set time, the build is failed.

Run your deployment pipeline

This step will deploy a Model Server and its associated infrastructure to your Bedrock Environment. This will result in charges from your cloud service provider depending on the resources requested.

  1. On Jenkins, click Open Blue Ocean on the left panel.

  2. In the This job has not been run message box, click Run. This will open an Input required message box.

  3. In the Model repository field, enter the ID of the Model you want to deploy - e.g. my-model-123.

  4. In the Endpoint field, enter the ID of the of the Endpoint you want to deploy your Model Server and Model to - e.g. my-endpoint-123.

  5. Review the default values in the rest of the fields.

  6. Click Run.

Your deployment pipeline should now be running and may take a few minutes to complete. After it completes, you should see a success report similar to the following.

A successful deployment using Jenkins.

Cleaning up

To avoid incurring additional charges from your cloud service provider, it is important to remove running Model Servers on Bedrock that you no longer need.

  1. On Bedrock, click Endpoints.

  2. Find the endpoint you targeted as part of your deployment pipeline and click on it.

  3. On the endpoint page, click on the Deployed models tab.

  4. Click Undeploy on the models you no longer need.