快速入門:使用 ARM 範本建立 Azure 數據工廠

適用於: Azure Data Factory Azure Synapse Analytics

秘訣

Data Factory in Microsoft Fabric 是下一代的 Azure Data Factory,擁有更簡單的架構、內建 AI 及新功能。 如果你是資料整合新手,建議先從 Fabric Data Factory 開始。 現有的 ADF 工作負載可升級至 Fabric,以存取資料科學、即時分析與報告等新能力。

此快速入門說明如何使用 Azure Resource Manager 範本(ARM 範本)來建立 Azure 資料工廠。 你在這個資料工廠建立的管線會將資料從 Azure Blob 儲存體中的一個資料夾複製到另一個資料夾。 關於如何使用 Azure Data Factory transform 資料的教學,請參見 Tutorial: Transform data with Spark。

Azure Resource Manager 模板 是一個 JavaScript 物件符號(JSON)檔案,用來定義你專案的基礎架構與設定。 範本使用宣告式語法。 您可以描述預期的部署,而不需要撰寫程式設計命令順序來建立部署。

注意

本文不提供數據處理站服務的詳細簡介。 關於Azure Data Factory服務的介紹,請參見Azure Data Factory介紹。

如果你的環境符合前提條件,且熟悉使用 ARM 範本,請選擇 部署到 Azure 按鈕。 範本會在 Azure 入口網站開啟。

按鈕,將Resource Manager範本部署到 Azure.

必要條件

Azure 訂閱

如果你沒有Azure訂閱,請在開始前建立一個free帳號。

建立檔案

請開啟文字編輯器 (例如 [記事本]) 並使用下列內容建立名為 emp.txt 的檔案:

John, Doe
Jane, Doe

將該檔案儲存在 C:\ADFv2QuickStartPSH 資料夾中。 (如果該資料夾不存在,請予以建立。)

檢閱範本

這個快速入門中使用的範本來自 Azure Quickstart Templates。

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "metadata": {
    "_generator": {
      "name": "bicep",
      "version": "0.26.54.24096",
      "templateHash": "17339534711754973978"
    }
  },
  "parameters": {
    "dataFactoryName": {
      "type": "string",
      "defaultValue": "[format('datafactory{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Data Factory Name"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location of the data factory."
      }
    },
    "storageAccountName": {
      "type": "string",
      "defaultValue": "[format('storage{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Name of the Azure storage account that contains the input/output data."
      }
    },
    "blobContainerName": {
      "type": "string",
      "defaultValue": "[format('blob{0}', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "Name of the blob container in the Azure Storage account."
      }
    }
  },
  "variables": {
    "dataFactoryLinkedServiceName": "ArmtemplateStorageLinkedService",
    "dataFactoryDataSetInName": "ArmtemplateTestDatasetIn",
    "dataFactoryDataSetOutName": "ArmtemplateTestDatasetOut",
    "pipelineName": "ArmtemplateSampleCopyPipeline"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts/blobServices",
      "apiVersion": "2023-01-01",
      "name": "[format('{0}/{1}', parameters('storageAccountName'), 'default')]",
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
      ]
    },
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2023-01-01",
      "name": "[parameters('storageAccountName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard_LRS"
      },
      "kind": "StorageV2",
      "properties": {
        "minimumTlsVersion": "TLS1_2",
        "supportsHttpsTrafficOnly": true,
        "allowBlobPublicAccess": false
      }
    },
    {
      "type": "Microsoft.Storage/storageAccounts/blobServices/containers",
      "apiVersion": "2023-01-01",
      "name": "[format('{0}/{1}/{2}', parameters('storageAccountName'), 'default', parameters('blobContainerName'))]",
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts/blobServices', parameters('storageAccountName'), 'default')]"
      ]
    },
    {
      "type": "Microsoft.DataFactory/factories",
      "apiVersion": "2018-06-01",
      "name": "[parameters('dataFactoryName')]",
      "location": "[parameters('location')]",
      "identity": {
        "type": "SystemAssigned"
      }
    },
    {
      "type": "Microsoft.DataFactory/factories/linkedservices",
      "apiVersion": "2018-06-01",
      "name": "[format('{0}/{1}', parameters('dataFactoryName'), variables('dataFactoryLinkedServiceName'))]",
      "properties": {
        "type": "AzureBlobStorage",
        "typeProperties": {
          "connectionString": "[format('DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}', parameters('storageAccountName'), listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2023-01-01').keys[0].value)]"
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.DataFactory/factories', parameters('dataFactoryName'))]",
        "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
      ]
    },
    {
      "type": "Microsoft.DataFactory/factories/datasets",
      "apiVersion": "2018-06-01",
      "name": "[format('{0}/{1}', parameters('dataFactoryName'), variables('dataFactoryDataSetInName'))]",
      "properties": {
        "linkedServiceName": {
          "referenceName": "[variables('dataFactoryLinkedServiceName')]",
          "type": "LinkedServiceReference"
        },
        "type": "Binary",
        "typeProperties": {
          "location": {
            "type": "AzureBlobStorageLocation",
            "container": "[parameters('blobContainerName')]",
            "folderPath": "input",
            "fileName": "emp.txt"
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.DataFactory/factories', parameters('dataFactoryName'))]",
        "[resourceId('Microsoft.DataFactory/factories/linkedservices', parameters('dataFactoryName'), variables('dataFactoryLinkedServiceName'))]"
      ]
    },
    {
      "type": "Microsoft.DataFactory/factories/datasets",
      "apiVersion": "2018-06-01",
      "name": "[format('{0}/{1}', parameters('dataFactoryName'), variables('dataFactoryDataSetOutName'))]",
      "properties": {
        "linkedServiceName": {
          "referenceName": "[variables('dataFactoryLinkedServiceName')]",
          "type": "LinkedServiceReference"
        },
        "type": "Binary",
        "typeProperties": {
          "location": {
            "type": "AzureBlobStorageLocation",
            "container": "[parameters('blobContainerName')]",
            "folderPath": "output"
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.DataFactory/factories', parameters('dataFactoryName'))]",
        "[resourceId('Microsoft.DataFactory/factories/linkedservices', parameters('dataFactoryName'), variables('dataFactoryLinkedServiceName'))]"
      ]
    },
    {
      "type": "Microsoft.DataFactory/factories/pipelines",
      "apiVersion": "2018-06-01",
      "name": "[format('{0}/{1}', parameters('dataFactoryName'), variables('pipelineName'))]",
      "properties": {
        "activities": [
          {
            "name": "MyCopyActivity",
            "type": "Copy",
            "typeProperties": {
              "source": {
                "type": "BinarySource",
                "storeSettings": {
                  "type": "AzureBlobStorageReadSettings",
                  "recursive": true
                }
              },
              "sink": {
                "type": "BinarySink",
                "storeSettings": {
                  "type": "AzureBlobStorageWriteSettings"
                }
              },
              "enableStaging": false
            },
            "inputs": [
              {
                "referenceName": "[variables('dataFactoryDataSetInName')]",
                "type": "DatasetReference"
              }
            ],
            "outputs": [
              {
                "referenceName": "[variables('dataFactoryDataSetOutName')]",
                "type": "DatasetReference"
              }
            ]
          }
        ]
      },
      "dependsOn": [
        "[resourceId('Microsoft.DataFactory/factories', parameters('dataFactoryName'))]",
        "[resourceId('Microsoft.DataFactory/factories/datasets', parameters('dataFactoryName'), variables('dataFactoryDataSetInName'))]",
        "[resourceId('Microsoft.DataFactory/factories/datasets', parameters('dataFactoryName'), variables('dataFactoryDataSetOutName'))]"
      ]
    }
  ],
  "outputs": {
    "name": {
      "type": "string",
      "value": "[variables('pipelineName')]"
    },
    "resourceId": {
      "type": "string",
      "value": "[resourceId('Microsoft.DataFactory/factories/pipelines', parameters('dataFactoryName'), variables('pipelineName'))]"
    },
    "resourceGroupName": {
      "type": "string",
      "value": "[resourceGroup().name]"
    },
    "location": {
      "type": "string",
      "value": "[parameters('location')]"
    }
  }
}

模板中有定義的 Azure 資源:

更多Azure Data Factory範本範例可在 quickstart 範本畫廊找到。

部署範本

  1. 選擇以下圖片登入 Azure 並開啟範本。 這個範本會建立一個 Azure Data Factory 帳號、一個儲存帳號和一個 blob 容器。

    按鈕,將Resource Manager範本部署到 Azure.

  2. 選取或輸入下列值。

    部署ADF ARM範本

    除非特別指定,否則請使用預設值來建立 Azure Data Factory 資源:

    • Subscription:選擇Azure訂閱。
    • 資源群組:選取 [新建],輸入資源群組的唯一名稱,並選取 [確定]。
    • 區域:選取位置。 例如,「美國東部」。
    • Data Factory 名稱:使用預設值。
    • 位置:使用預設值。
    • 儲存體帳戶名稱:使用預設值。
    • Blob 容器:使用預設值。

檢閱已部署的資源

  1. 選取 前往資源群組。

    資源群組

  2. 請確認你的 Azure Data Factory 已經建立。

    1. 你的Azure Data Factory名稱格式是 datafactory<uniqueid>。

    範例資料工廠

  3. 確認已建立儲存體帳戶。

    1. 儲存體帳戶名稱的格式為 - storage<uniqueid>。

    儲存體帳戶

  4. 選取建立的儲存體帳戶,然後選取 [容器] 。

    1. 在 容器 頁面中,選取您建立的 Blob 容器。
      1. Blob 容器名稱的格式為 - blob<uniqueid>。

    Blob 容器

上傳檔案

  1. 在 [容器] 頁面上,選取 [上傳]。

  2. 在右窗格中,選取 [檔案] 方塊,然後瀏覽並選取您稍早建立的 emp.txt 檔案。

  3. 展開 進階 標題。

  4. 在 [上傳至資料夾] 方塊中,輸入 input。

  5. 選取上傳按鈕。 您應該會在清單中看到 emp.txt 檔案以及上傳的狀態。

  6. 選取「關閉」 圖示(X)以關閉「上傳 Blob」 頁面。

    將檔案上傳至輸入資料夾

將 [容器] 頁面保持開啟,因為您可以用該頁面來驗證本快速入門結尾處的輸出。

啟動觸發程序

  1. 瀏覽至 [資料處理站] 頁面,選取您建立的資料管理站。

  2. 在 Open Azure Data Factory Studio 圖塊上選擇 Open。

    作者 & 監視器

  3. 選取作者索引標籤。

  4. 選取已建立的管線 - ArmtemplateSampleCopyPipeline。

    ARM 範本管線

  5. 選取 新增觸發>立即觸發。

    觸發程序

  6. 在右側窗格的管線執行下,選取確定。

監視管線

  1. 選取 監視 索引標籤。

  2. 您會看到與管線執行相關聯的活動執行。 在本快速入門中,管線只有一個活動,類型為:Copy。 因此,您會看到該活動的執行。

    成功執行

驗證輸出檔案

管道會自動在 Blob 容器中建立輸出資料夾。 然後,它會將 emp.txt 檔案從輸入資料夾複製到輸出資料夾。

  1. 在Azure入口網站的 Containers頁面,選擇 Refresh 以查看輸出資料夾。

  2. 在資料夾清單中,選取 [輸出]。

  3. 確認 emp.txt 已複製到輸出資料夾。

    輸出

清除資源

您有兩種方式可以清除您在本快速入門中建立的資源。 你可以刪除Azure資源群組,這包含了該資源群組中的所有資源。 如果您想要讓其他資源保持不變,請僅刪除您在本教學課程中建立的資料處理站。

刪除資源群組將會刪除所有資源,包括其中的資料工廠。 執行下列命令來刪除整個資源群組:

Remove-AzResourceGroup -ResourceGroupName $resourcegroupname

如果您需要只刪除 Data Factory,而非整個資源群組,請執行下列命令:

Remove-AzDataFactoryV2 -Name $dataFactoryName -ResourceGroupName $resourceGroupName

在這個快速入門中,你用 ARM 範本建立了 Azure Data Factory,並驗證了部署。 欲了解更多關於 Azure Data Factory 與 Azure Resource Manager 的資訊,請繼續閱讀以下文章。