Question 27
Domain 4: Deploy and operationalize machine learning solutionsYour team has deployed a model to an Azure Managed Online Endpoint using Azure Machine Learning SDK v2. You need to invoke the endpoint using Python code and pass JSON input to it. The deployed endpoint is named 'credit-risk-endpoint', and the deployment is called 'blue'. The input data is stored in a dictionary called `input_payload`. What is the correct method to invoke the endpoint?
Correct answer: A
Explanation
Azure Machine Learning SDK v2 uses the `MLClient` to manage and call online endpoints, and the `online_endpoints.invoke` method is the API for sending a request body to a deployed endpoint. Passing `endpoint_name='credit-risk-endpoint'`, `deployment_name='blue'`, and `request_body=input_payload` matches the required invocation pattern for a Managed Online Endpoint.
Why each option is right or wrong
A. from azure.ai.ml import MLClient from azure.identity import DefaultAzureCredential client = MLClient(DefaultAzureCredential(), subscription_id, resource_group, workspace) response = client.online_endpoints.invoke(endpoint_name='credit-risk-endpoint', deployment_name='blue', request_body=input_payload)
Azure Machine Learning SDK v2 invokes managed online endpoints through `MLClient.online_endpoints.invoke`, not the older `ServicePrincipalAuthentication`/`Webservice` patterns. The call must identify the endpoint and deployment explicitly—here `endpoint_name='credit-risk-endpoint'` and `deployment_name='blue'`—and the JSON payload is supplied in `request_body`, which is the parameter used for the request content sent to the scoring URI.
B. from azureml.core.webservice import Webservice service = Webservice(name='credit-risk-endpoint', workspace=ws) predictions = service.run(input_payload)
C. client = MLClient(DefaultAzureCredential()) predictions = client.endpoints.run_json(input_payload)
D. from azure.ai.ml import MLClient client = MLClient(DefaultAzureCredential()) response = client.batch_endpoints.invoke(input=input_payload)