|
167 | 167 | "image.wait_for_creation(show_output = True)"
|
168 | 168 | ]
|
169 | 169 | },
|
| 170 | + { |
| 171 | + "cell_type": "markdown", |
| 172 | + "metadata": {}, |
| 173 | + "source": [ |
| 174 | + "#### Use a custom Docker image\n", |
| 175 | + "\n", |
| 176 | + "You can also specify a custom Docker image to be used as base image if you don't want to use the default base image provided by Azure ML. Please make sure the custom Docker image has Ubuntu >= 16.04, Conda >= 4.5.\\* and Python(3.5.\\* or 3.6.\\*).\n", |
| 177 | + "\n", |
| 178 | + "Only Supported for `ContainerImage`(from azureml.core.image) with `python` runtime.\n", |
| 179 | + "```python\n", |
| 180 | + "# use an image available in public Container Registry without authentication\n", |
| 181 | + "image_config.base_image = \"mcr.microsoft.com/azureml/o16n-sample-user-base/ubuntu-miniconda\"\n", |
| 182 | + "\n", |
| 183 | + "# or, use an image available in a private Container Registry\n", |
| 184 | + "image_config.base_image = \"myregistry.azurecr.io/mycustomimage:1.0\"\n", |
| 185 | + "image_config.base_image_registry.address = \"myregistry.azurecr.io\"\n", |
| 186 | + "image_config.base_image_registry.username = \"username\"\n", |
| 187 | + "image_config.base_image_registry.password = \"password\"\n", |
| 188 | + "\n", |
| 189 | + "# or, use an image built during training.\n", |
| 190 | + "image_config.base_image = run.properties[\"AzureML.DerivedImageName\"]\n", |
| 191 | + "```\n", |
| 192 | + "You can get the address of training image from the properties of a Run object. Only new runs submitted with azureml-sdk>=1.0.22 to AMLCompute targets will have the 'AzureML.DerivedImageName' property. Instructions on how to get a Run can be found in [manage-runs](../../training/manage-runs/manage-runs.ipynb). \n" |
| 193 | + ] |
| 194 | + }, |
170 | 195 | {
|
171 | 196 | "cell_type": "markdown",
|
172 | 197 | "metadata": {},
|
|
191 | 216 | " provisioning_configuration = prov_config)"
|
192 | 217 | ]
|
193 | 218 | },
|
| 219 | + { |
| 220 | + "cell_type": "markdown", |
| 221 | + "metadata": {}, |
| 222 | + "source": [ |
| 223 | + "# Create AKS Cluster in an existing virtual network (optional)\n", |
| 224 | + "See code snippet below. Check the documentation [here](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-enable-virtual-network#use-azure-kubernetes-service) for more details." |
| 225 | + ] |
| 226 | + }, |
| 227 | + { |
| 228 | + "cell_type": "code", |
| 229 | + "execution_count": null, |
| 230 | + "metadata": {}, |
| 231 | + "outputs": [], |
| 232 | + "source": [ |
| 233 | + "'''\n", |
| 234 | + "from azureml.core.compute import ComputeTarget, AksCompute\n", |
| 235 | + "\n", |
| 236 | + "# Create the compute configuration and set virtual network information\n", |
| 237 | + "config = AksCompute.provisioning_configuration(location=\"eastus2\")\n", |
| 238 | + "config.vnet_resourcegroup_name = \"mygroup\"\n", |
| 239 | + "config.vnet_name = \"mynetwork\"\n", |
| 240 | + "config.subnet_name = \"default\"\n", |
| 241 | + "config.service_cidr = \"10.0.0.0/16\"\n", |
| 242 | + "config.dns_service_ip = \"10.0.0.10\"\n", |
| 243 | + "config.docker_bridge_cidr = \"172.17.0.1/16\"\n", |
| 244 | + "\n", |
| 245 | + "# Create the compute target\n", |
| 246 | + "aks_target = ComputeTarget.create(workspace = ws,\n", |
| 247 | + " name = \"myaks\",\n", |
| 248 | + " provisioning_configuration = config)\n", |
| 249 | + "'''" |
| 250 | + ] |
| 251 | + }, |
| 252 | + { |
| 253 | + "cell_type": "markdown", |
| 254 | + "metadata": {}, |
| 255 | + "source": [ |
| 256 | + "# Enable SSL on the AKS Cluster (optional)\n", |
| 257 | + "See code snippet below. Check the documentation [here](https://docs.microsoft.com/en-us/azure/machine-learning/service/how-to-secure-web-service) for more details" |
| 258 | + ] |
| 259 | + }, |
| 260 | + { |
| 261 | + "cell_type": "code", |
| 262 | + "execution_count": null, |
| 263 | + "metadata": {}, |
| 264 | + "outputs": [], |
| 265 | + "source": [ |
| 266 | + "# provisioning_config = AksCompute.provisioning_configuration(ssl_cert_pem_file=\"cert.pem\", ssl_key_pem_file=\"key.pem\", ssl_cname=\"www.contoso.com\")" |
| 267 | + ] |
| 268 | + }, |
194 | 269 | {
|
195 | 270 | "cell_type": "code",
|
196 | 271 | "execution_count": null,
|
|
270 | 345 | "cell_type": "markdown",
|
271 | 346 | "metadata": {},
|
272 | 347 | "source": [
|
273 |
| - "# Test the web service\n", |
274 |
| - "We test the web sevice by passing data." |
| 348 | + "# Test the web service using run method\n", |
| 349 | + "We test the web sevice by passing data.\n", |
| 350 | + "Run() method retrieves API keys behind the scenes to make sure that call is authenticated." |
275 | 351 | ]
|
276 | 352 | },
|
277 | 353 | {
|
|
293 | 369 | "print(prediction)"
|
294 | 370 | ]
|
295 | 371 | },
|
| 372 | + { |
| 373 | + "cell_type": "markdown", |
| 374 | + "metadata": {}, |
| 375 | + "source": [ |
| 376 | + "# Test the web service using raw HTTP request (optional)\n", |
| 377 | + "Alternatively you can construct a raw HTTP request and send it to the service. In this case you need to explicitly pass the HTTP header. This process is shown in the next 2 cells." |
| 378 | + ] |
| 379 | + }, |
| 380 | + { |
| 381 | + "cell_type": "code", |
| 382 | + "execution_count": null, |
| 383 | + "metadata": {}, |
| 384 | + "outputs": [], |
| 385 | + "source": [ |
| 386 | + "# retreive the API keys. AML generates two keys.\n", |
| 387 | + "'''\n", |
| 388 | + "key1, Key2 = aks_service.get_keys()\n", |
| 389 | + "print(key1)\n", |
| 390 | + "'''" |
| 391 | + ] |
| 392 | + }, |
| 393 | + { |
| 394 | + "cell_type": "code", |
| 395 | + "execution_count": null, |
| 396 | + "metadata": {}, |
| 397 | + "outputs": [], |
| 398 | + "source": [ |
| 399 | + "# construct raw HTTP request and send to the service\n", |
| 400 | + "'''\n", |
| 401 | + "%%time\n", |
| 402 | + "\n", |
| 403 | + "import requests\n", |
| 404 | + "\n", |
| 405 | + "import json\n", |
| 406 | + "\n", |
| 407 | + "test_sample = json.dumps({'data': [\n", |
| 408 | + " [1,2,3,4,5,6,7,8,9,10], \n", |
| 409 | + " [10,9,8,7,6,5,4,3,2,1]\n", |
| 410 | + "]})\n", |
| 411 | + "test_sample = bytes(test_sample,encoding = 'utf8')\n", |
| 412 | + "\n", |
| 413 | + "# Don't forget to add key to the HTTP header.\n", |
| 414 | + "headers = {'Content-Type':'application/json', 'Authorization': 'Bearer ' + key1}\n", |
| 415 | + "\n", |
| 416 | + "resp = requests.post(aks_service.scoring_uri, test_sample, headers=headers)\n", |
| 417 | + "\n", |
| 418 | + "\n", |
| 419 | + "print(\"prediction:\", resp.text)\n", |
| 420 | + "'''" |
| 421 | + ] |
| 422 | + }, |
296 | 423 | {
|
297 | 424 | "cell_type": "markdown",
|
298 | 425 | "metadata": {},
|
|
317 | 444 | "metadata": {
|
318 | 445 | "authors": [
|
319 | 446 | {
|
320 |
| - "name": "raymondl" |
| 447 | + "name": "aashishb" |
321 | 448 | }
|
322 | 449 | ],
|
323 | 450 | "kernelspec": {
|
|
0 commit comments