azure-resource-manager - 使用 ARM 模板创建 Azure Databricks token

标签 azure-resource-manager azure-databricks

我需要使用 ARM 模板在 Azure Databricks 中创建一个 token 。
我可以使用 ARM 模板创建 Azure Databricks,但无法使用 ARM 模板在 Azure Databricks 中创建 token

以下是我用来创建 Azure Databricks 的模板

{
"$schema": "https://schema.management.azure.com/schemas/2015-01- 
01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceName": {
"type": "string",
  "metadata": {
    "description": "The name of the Azure Databricks workspace to create."
  }
},
"pricingTier": {
  "type": "string",
  "defaultValue": "premium",
  "allowedValues": [
    "standard",
    "premium"
  ],
  "metadata": {
    "description": "The pricing tier of workspace."
  }
},
"location": {
  "type": "string",
  "defaultValue": "[resourceGroup().location]",
  "metadata": {
    "description": "Location for all resources."
  }
}
},
"variables": {
"managedResourceGroupName": "[concat('databricks-rg-', 
parameters('workspaceName'), '-', uniqueString(parameters('workspaceName'), 
resourceGroup().id))]"
},
"resources": [
{
  "type": "Microsoft.Databricks/workspaces",
  "name": "[parameters('workspaceName')]",
  "location": "[parameters('location')]",
  "apiVersion": "2018-04-01",
  "sku": {
    "name": "[parameters('pricingTier')]"
  },
  "properties": {
    "ManagedResourceGroupId": "[concat(subscription().id, '/resourceGroups/', variables('managedResourceGroupName'))]"
  }
}
],
"outputs": {
"workspace": {
  "type": "object",
  "value": "[reference(resourceId('Microsoft.Databricks/workspaces', parameters('workspaceName')))]"
}
}
}

请让我知道如何使用 ARM 模板在 Azure Databricks 中创建 token

最佳答案

我在评论中看到您询问是否可以使用脚本创建 token 。现在可以了!

Databricks 有一个 token API:https://docs.databricks.com/dev-tools/api/latest/tokens.html

查看此博客:https://cloudarchitected.com/2020/01/using-azure-ad-with-the-azure-databricks-api/

它展示了使用 AAD 和其他一些方法创建数据块 token 是多么容易。

我有一些 Python 代码可用于自动执行此任务。我会扩展它以自动将 token 添加到某种 key 保管库。这是一个示例:

import requests
import adal
import json

# set variables 
clientId = "<Service Principal Id>"
tenantId = "<Tenant Id>"
clientSecret = "<Service Principal Secret>"
subscription_id = "<Subscription Id>"
resource_group = "<Resource Group Name>"
databricks_workspace = "<Databricks Workspace Name>"
dbricks_location = "<Databricks Azure Region i.e. westus>"



# Acquire a token to authenticate against Azure management API
authority_url = 'https://login.microsoftonline.com/'+tenantId
context = adal.AuthenticationContext(authority_url)
token = context.acquire_token_with_client_credentials(
    resource='https://management.core.windows.net/',
    client_id=clientId,
    client_secret=clientSecret
)
azToken = token.get('accessToken')



# Acquire a token to authenticate against the Azure Databricks Resource
token = context.acquire_token_with_client_credentials(
    resource="2ff814a6-3304-4ab8-85cb-cd0e6f879c1d",
    client_id=clientId,
    client_secret=clientSecret
)
adbToken = token.get('accessToken')


# Format Request API Url
dbricks_api = "https://{}.azuredatabricks.net/api/2.0".format(dbricks_location)


# Request Authentication
dbricks_auth = {
    "Authorization": "Bearer {}".format(adbToken),
    "X-Databricks-Azure-SP-Management-Token": azToken,
    "X-Databricks-Azure-Workspace-Resource-Id": ("/subscriptions/{}/resourceGroups/{}/providers/Microsoft.Databricks/workspaces/{}".format(subscription_id, resource_group, databricks_workspace) )
    }


# Optional Paramters 
payload = {
    "comment": "This token is generated through AAD and Databricks APIs", # optional parameter
    # "lifetime_seconds": 3600 # optional parameter. If not passed then it is indefinte
}


# Request and Send Data to Create a Databricks Token
data = requests.post("{}/token/create".format(dbricks_api), headers= dbricks_auth, json=payload)

# display the response data
data.status_code
data.content

# Decode response, get token, and print token
dict_content = json.loads(data.content.decode('utf-8'))
token = dict_content.get('token_value')
print("This is the databricks token: {}".format(token))

关于azure-resource-manager - 使用 ARM 模板创建 Azure Databricks token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54090321/

相关文章:

Azure linux waagent 在配置后未运行

sql - 如何在 Azure databricks SQL 中将字段值转换为逗号分隔

azure - 在 python init 脚本中为 databricks 集群设置 Sparkconf

apache-spark - Databricks Pyspark - 组相关行

azure - 如何结合多订阅和多区域功能在 Bicep 中创建 Azure 警报

azure - Azure 部署中的deployment().name 值来自哪里?

azure - 是否可以在 YAML 管道中创建带有标签的 Azure 资源组?

azure - 二头肌模板在存储帐户中创建容器

azure - 是否可以在 Azure databricks 中使用基于 Parquet 文件名的增量表跟踪器?

azure - 如何删除databricks azure中的所有集群,而不是搜索和复制cluster_id?