如何在 Azure 机器学习服务中为 ACI web 服务启用身份验证?
How to enable authentication for an ACI webservice in Azure Machine Learning service?
我能够使用语法
在我的工作区 ws
中部署 Azure 机器学习预测服务
aciconfig = AciWebservice.deploy_configuration(cpu_cores=1,
memory_gb=8,
tags={"method" : "some method"},
description='Predict something')
然后
service = Webservice.deploy_from_image(deployment_config = aciconfig,
image = image,
name = service_name,
workspace = ws)
如documentation所述。
但是,这公开了一项服务,这并不是最佳选择。
屏蔽ACI服务最简单的方法是什么?我知道传递 auth_enabled=True
参数可能会完成这项工作,但是我该如何指示客户端(例如,使用 curl
或 Postman)之后使用该服务?
有关示例(在 C# 中),请参阅 here。启用身份验证时,您需要在 HTTP 请求中的 "Authorization" header 中发送 API 密钥:
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authKey);
参见here如何检索密钥。
首先,使用类似于
的(Python)语法检索主键和辅助键
service.get_keys()
如果您使用 curl
,语法可能如下所示:
curl -H "Content-Type:application/json" -H "Authorization: Bearer <authKey>" -X POST -d '{"data": [some data]}' http://<url>:<port>/<method>
其中 <authKey>
是上面检索到的键之一。
我能够使用语法
在我的工作区ws
中部署 Azure 机器学习预测服务
aciconfig = AciWebservice.deploy_configuration(cpu_cores=1,
memory_gb=8,
tags={"method" : "some method"},
description='Predict something')
然后
service = Webservice.deploy_from_image(deployment_config = aciconfig,
image = image,
name = service_name,
workspace = ws)
如documentation所述。
但是,这公开了一项服务,这并不是最佳选择。
屏蔽ACI服务最简单的方法是什么?我知道传递 auth_enabled=True
参数可能会完成这项工作,但是我该如何指示客户端(例如,使用 curl
或 Postman)之后使用该服务?
有关示例(在 C# 中),请参阅 here。启用身份验证时,您需要在 HTTP 请求中的 "Authorization" header 中发送 API 密钥:
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authKey);
参见here如何检索密钥。
首先,使用类似于
的(Python)语法检索主键和辅助键service.get_keys()
如果您使用 curl
,语法可能如下所示:
curl -H "Content-Type:application/json" -H "Authorization: Bearer <authKey>" -X POST -d '{"data": [some data]}' http://<url>:<port>/<method>
其中 <authKey>
是上面检索到的键之一。