# Automated deployment and replacement of Scoring Code in AzureML
URL: https://docs.datarobot.com/en/docs/workbench/nxt-console/nxt-prediction-environments/nxt-prediction-environment-integrations/nxt-azureml-pred-env-integration.html

> Create a DataRobot-managed AzureML prediction environment to deploy and replace DataRobot Scoring Code in AzureML.

# Automated deployment and replacement of Scoring Code in AzureML

> [!NOTE] Premium
> Automated deployment and replacement of Scoring Code in AzureML is a premium feature. Contact your DataRobot representative or administrator for information on enabling this feature.
> 
> Feature flag: Enable the Automated Deployment and Replacement of Scoring Code in AzureML ( Premium feature)

Create a DataRobot-managed AzureML prediction environment to deploy DataRobot Scoring Code in AzureML. With DataRobot management enabled, the external AzureML deployment has access to MLOps features, including automatic Scoring Code replacement.

> [!NOTE] Service health information for external models and monitoring jobs
> Service health information is unavailable for external [agent-monitored deployments](https://docs.datarobot.com/en/docs/classic-ui/mlops/deployment/mlops-agent/monitoring-agent/index.html) and deployments with predictions uploaded through a [prediction monitoring job](https://docs.datarobot.com/en/docs/workbench/nxt-console/nxt-monitoring/nxt-monitoring-jobs.html).

## Create an AzureML prediction environment

To deploy a model in AzureML, first create a custom AzureML prediction environment:

1. Open theConsole > Prediction environmentspage and click+ Add prediction environment.
2. In theAdd prediction environmentdialog box, configure the prediction environment settings: TheSupported model formatssettings are automatically set toDataRobotandDataRobot Scoring Code onlyand can't be changed, as this is the only model format supported by AzureML.
3. In theManagement settingssection, select the related Azure service principalCredentials. Configure theAzure Subscription,Azure Resource Group, andAzureML Workspacefields accessible using the providedCredentials. Azure service principal credentials requiredDataRobot management of Scoring Code in AzureML requires existing Azure Service PrincipalCredentials. If you don't have existing credentials, theAzure Service Principal credentials requiredalert appears, directing you toGo to Credentialstocreate Azure Service Principal credentials.To create the required credentials, forCredential type, selectAzure Service Principal. Then, enter aClient ID,Client Secret,Azure Tenant ID, and aDisplay name. To validate and save the credentials, clickSave and sign in.You can find these IDs and the display name on Azure'sApp registrations>Overviewtab (1) and generate secrets on theApp registration > Certificates and secretstab(2): In addition, if you are using tags for governance and resource management in AzureML, clickAzureML tagsand then+ Add new tagto add the required tags to the prediction environment.
4. (Optional) If you want to connect to and retrieve data from Azure Event Hubs for monitoring, in theMonitoring settingssection, clickEnable monitoringand configure theEvent Hubs Namespace,Event Hubs Instance, andManaged Identitiesfields. This requires validCredentials, anAzure Subscription ID, and anAzure Resource Group. You can also clickEnvironment variablesand then+ New environment variablesto add environment variables to the prediction environment.
5. After configuring the environment settings, clickAdd environment. The AzureML environment is now available from thePrediction environmentspage.

## Deploy a model to the AzureML prediction environment

Once you've created an AzureML prediction environment, you can deploy a model to it:

1. On theRegistry > Modelstab, in the table of registered models, click the registered model containing the version you want to deploy, opening the list of versions. Model supportAzureML prediction environmentsdo notsupport models without Scoring Code support.
2. From the list of versions, click the Scoring Code enabled version you want to deploy, opening the registered model version panel.
3. In the upper-right corner of any tab in the registered model version panel, clickDeploy.
4. In thePrediction history and service healthsettings, underChoose prediction environment, clickChange.
5. In theSelect prediction environmentpanel, clickAzureML, and then click the prediction environment you want to deploy to.
6. With an AzureML environment selected, in thePrediction history and service healthsection, underEndpoint, click+ Add endpoint.
7. In theSelect endpointdialog box, define anOnlineorBatchendpoint, depending on your expected workload, and then clickNext.
8. (Optional) On the next page, define additionalEnvironment key-value pairsto provide extra parameters to the Azure deployment interface. Then, clickConfirm.
9. Configure the remaining deployment settingsand clickDeploy model.

While the deployment is Launching, you can monitor the status events on the deployment's Monitoring > Service health tab under Recent activity > Agent activity

## Make predictions in AzureML

After deploying a model to an AzureML prediction environment, you can use the code snippet from the Predictions > Portable predictions tab to score data in AzureML. Before running the code snippet, you must provide the required credentials in either of the following ways:

- Export the Azure Service Principal’s secrets as environment variables locally before running the snippet: Environment variableDescriptionAZURE_CLIENT_IDTheApplication IDin theApp registration > Overviewtab.AZURE_TENANT_IDTheDirectory IDin theApp registration > Overviewtab.AZURE_CLIENT_SECRETThe secret token generated in theApp registration > Certificates and secretstab.
- Install theAzure CLI, and run theaz logincommand to allow the portable predictions snippet to use your personal Azure credentials.

> [!NOTE] Important
> Deployments to AzureML Batch and Online endpoints utilize different APIs than standard DataRobot deployments.
> 
> Online endpoints support JSON or CSV as input and outputs results to JSON.
> Batch endpoints support CSV input and output the results to a CSV file.

---
