AciWebservice Class

Represents a machine learning model deployed as a web service endpoint on Azure Container Instances.

A deployed service is created from a model, script, and associated files. The resulting web service is a load-balanced, HTTP endpoint with a REST API. You can send data to this API and receive the prediction returned by the model.

For more information, see Deploy a model to Azure Container Instances.

Initialize the Webservice instance.

The Webservice constructor retrieves a cloud representation of a Webservice object associated with the provided workspace. It will return an instance of a child class corresponding to the specific type of the retrieved Webservice object.

Inheritance
AciWebservice

Constructor

AciWebservice(workspace, name)

Parameters

Name Description
workspace
Required

The workspace object containing the Webservice object to retrieve.

name
Required
str

The name of the of the Webservice object to retrieve.

Remarks

The recommended deployment pattern is to create a deployment configuration object with the deploy_configuration method and then use it with the deploy method of the Model class as shown below.


   from azureml.core.model import InferenceConfig
   from azureml.core.webservice import AciWebservice


   service_name = 'my-custom-env-service'

   inference_config = InferenceConfig(entry_script='score.py', environment=environment)
   aci_config = AciWebservice.deploy_configuration(cpu_cores=1, memory_gb=1)

   service = Model.deploy(workspace=ws,
                          name=service_name,
                          models=[model],
                          inference_config=inference_config,
                          deployment_config=aci_config,
                          overwrite=True)
   service.wait_for_deployment(show_output=True)

There are a number of ways to deploy a model as a webservice, including with the:

  • deploy method of the Model for models already registered in the workspace.

  • deploy_from_image method of Webservice.

  • deploy_from_model method of Webservice for models already registered in the workspace. This method will create an image.

  • deploy method of the Webservice, which will register a model and create an image.

For information on working with webservices, see

The Variables section lists attributes of a local representation of the cloud AciWebservice object. These variables should be considered read-only. Changing their values will not be reflected in the corresponding cloud object.

Variables

Name Description
enable_app_insights

Whether or not AppInsights logging is enabled for the Webservice.

cname
str

The cname for the Webservice.

container_resource_requirements

The container resource requirements for the Webservice.

encryption_properties

The encryption properties for the Webservice.

vnet_configuration

The virtual network properties for the Webservice, configuration should be created and provided by user.

azureml.core.webservice.AciWebservice.location
str

The location the Webservice is deployed to.

public_ip
str

The public ip address of the Webservice.

azureml.core.webservice.AciWebservice.scoring_uri
str

The scoring endpoint for the Webservice

ssl_enabled

Whether or not SSL is enabled for the Webservice

public_fqdn
str

The public FQDN for the Webservice

environment

The Environment object that was used to create the Webservice

azureml.core.webservice.AciWebservice.models

A list of Models deployed to the Webservice

azureml.core.webservice.AciWebservice.swagger_uri
str

The swagger endpoint for the Webservice

Methods

add_properties

Add key value pairs to this Webservice's properties dictionary.

add_tags

Add key value pairs to this Webservice's tags dictionary.

deploy_configuration

Create a configuration object for deploying an AciWebservice.

get_token

Retrieve auth token for this Webservice, scoped to the current user.

Note

Not implemented.

remove_tags

Remove the specified keys from this Webservice's dictionary of tags.

run

Call this Webservice with the provided input.

serialize

Convert this Webservice into a JSON serialized dictionary.

update

Update the Webservice with provided properties.

Values left as None will remain unchanged in this Webservice.

add_properties

Add key value pairs to this Webservice's properties dictionary.

add_properties(properties)

Parameters

Name Description
properties
Required

The dictionary of properties to add.

add_tags

Add key value pairs to this Webservice's tags dictionary.

add_tags(tags)

Parameters

Name Description
tags
Required

The dictionary of tags to add.

Exceptions

Type Description

deploy_configuration

Create a configuration object for deploying an AciWebservice.

static deploy_configuration(cpu_cores=None, memory_gb=None, tags=None, properties=None, description=None, location=None, auth_enabled=None, ssl_enabled=None, enable_app_insights=None, ssl_cert_pem_file=None, ssl_key_pem_file=None, ssl_cname=None, dns_name_label=None, primary_key=None, secondary_key=None, collect_model_data=None, cmk_vault_base_url=None, cmk_key_name=None, cmk_key_version=None, vnet_name=None, subnet_name=None)

Parameters

Name Description
cpu_cores

The number of CPU cores to allocate for this Webservice. Can be a decimal. Defaults to 0.1

Default value: None
memory_gb

The amount of memory (in GB) to allocate for this Webservice. Can be a decimal. Defaults to 0.5

Default value: None
tags

A dictionary of key value tags to give this Webservice.

Default value: None
properties

A dictionary of key value properties to give this Webservice. These properties cannot be changed after deployment, however new key value pairs can be added.

Default value: None
description
str

A description to give this Webservice.

Default value: None
location
str

The Azure region to deploy this Webservice to. If not specified the Workspace location will be used. For more details on available regions, see Products by region.

Default value: None
auth_enabled

Whether or not to enable auth for this Webservice. Defaults to False.

Default value: None
ssl_enabled

Whether or not to enable SSL for this Webservice. Defaults to False.

Default value: None
enable_app_insights

Whether or not to enable AppInsights for this Webservice. Defaults to False.

Default value: None
ssl_cert_pem_file
str

The cert file needed if SSL is enabled.

Default value: None
ssl_key_pem_file
str

The key file needed if SSL is enabled.

Default value: None
ssl_cname
str

The cname for if SSL is enabled.

Default value: None
dns_name_label
str

The DNS name label for the scoring endpoint. If not specified a unique DNS name label will be generated for the scoring endpoint.

Default value: None
primary_key
str

A primary auth key to use for this Webservice.

Default value: None
secondary_key
str

A secondary auth key to use for this Webservice.

Default value: None
collect_model_data

Whether or not to enabled model data collection for the Webservice.

Default value: None
cmk_vault_base_url
str

customer managed key vault base url

Default value: None
cmk_key_name
str

customer managed key name.

Default value: None
cmk_key_version
str

customer managed key version.

Default value: None
vnet_name
str

virtual network name.

Default value: None
subnet_name
str

subnet name within virtual network.

Default value: None

Returns

Type Description

A configuration object to use when deploying a Webservice object.

Exceptions

Type Description

get_token

Retrieve auth token for this Webservice, scoped to the current user.

Note

Not implemented.

get_token()

Returns

Type Description

The auth token for this Webservice and when it should be refreshed after.

Exceptions

Type Description
azureml.exceptions.NotImplementedError

remove_tags

Remove the specified keys from this Webservice's dictionary of tags.

remove_tags(tags)

Parameters

Name Description
tags
Required

The list of keys to remove.

run

Call this Webservice with the provided input.

run(input_data)

Parameters

Name Description
input_data
Required
<xref:varies>

The input to call the Webservice with.

Returns

Type Description

The result of calling the Webservice.

Exceptions

Type Description

serialize

Convert this Webservice into a JSON serialized dictionary.

serialize()

Returns

Type Description

The JSON representation of this Webservice object.

update

Update the Webservice with provided properties.

Values left as None will remain unchanged in this Webservice.

update(image=None, tags=None, properties=None, description=None, auth_enabled=None, ssl_enabled=None, ssl_cert_pem_file=None, ssl_key_pem_file=None, ssl_cname=None, enable_app_insights=None, models=None, inference_config=None)

Parameters

Name Description
image

A new Image to deploy to the Webservice.

Default value: None
tags

A dictionary of key value tags to give this Webservice. Will replace existing tags.

Default value: None
properties

A dictionary of key value properties to add to existing properties dictionary.

Default value: None
description
str

A description to give this Webservice.

Default value: None
auth_enabled

Enable or disable auth for this Webservice.

Default value: None
ssl_enabled

Whether or not to enable SSL for this Webservice.

Default value: None
ssl_cert_pem_file
str

The cert file needed if SSL is enabled.

Default value: None
ssl_key_pem_file
str

The key file needed if SSL is enabled.

Default value: None
ssl_cname
str

The cname for if SSL is enabled.

Default value: None
enable_app_insights

Whether or not to enable AppInsights for this Webservice.

Default value: None
models

A list of Model objects to package into the updated service.

Default value: None
inference_config

An InferenceConfig object used to provide the required model deployment properties.

Default value: None

Returns

Type Description