快速入門:使用ARM範本建立 Azure Data Factory

適用於:Azure Data Factory Azure Synapse Analytics

提示

試用 Microsoft Fabric 中的 Data Factory,這是適用於企業的全方位分析解決方案。 Microsoft Fabric 涵蓋從資料移動到資料科學、即時分析、商業智慧和報告等所有項目。 了解如何免費啟動新的試用版

本快速入門說明如何使用 Azure Resource Manager 範本 (ARM 範本) 來建立 Azure Data Factory。 您在此資料處理站 中建立的管線會將 資料從一個資料夾複製到 Azure Blob 記憶體中的另一個資料夾。 如需如何使用 Azure Data Factory 轉換 數據的教學課程,請參閱 教學課程:使用 Spark 轉換數據。

Azure Resource Manager 範本是 JavaScript 物件表示法 (JSON) 檔案,可定義專案的基礎結構和組態。 範本使用宣告式語法。 您不需要撰寫程式設計命令順序來建立部署,即可描述預定的部署。

注意

本文不提供Data Factory 服務的詳細簡介。 如需 Azure Data Factory 服務簡介,請參閱 Azure Data Factory 簡介

如果您的環境符合必要條件,而且您很熟悉 ARM 範本,請選取 [部署至 Azure] 按鈕。 範本會在 Azure 入口網站中開啟。

Button to deploy the Resource Manager template to Azure.

必要條件

Azure 訂用帳戶

如尚未擁有 Azure 訂用帳戶,請在開始之前先建立免費帳戶

建立檔案

開啟 記事本 之類的文字編輯器,並使用下列內容建立名為 emp.txt 的檔案:

John, Doe
Jane, Doe

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

檢閱範本

本快速入門中使用的範本是來自 Azure 快速入門範本

{
  "$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 範例,請參閱 快速入門範本資源庫

部署範本

  1. 選取以下影像來登入 Azure 並開啟範本。 此範本會建立 Azure Data Factory 帳戶、記憶體帳戶和 Blob 容器。

    Button to deploy the Resource Manager template to Azure.

  2. 選取或輸入下列值。

    Deploy ADF ARM template

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

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

檢閱已部署的資源

  1. 選取 [移至資源群組]。

    Resource Group

  2. 確認已建立您的 Azure Data Factory。

    1. 您的 Azure Data Factory 名稱格式為 - datafactory<uniqueid>。

    Sample Data Factory

  3. 確認您的記憶體帳戶已建立。

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

    Storage Account

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

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

    Blob container

上傳檔案

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

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

  3. 展開 [進階] 標題。

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

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

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

    Upload file to input folder

讓容器頁面保持開啟,因為您可以使用它來驗證本快速入門結尾的輸出。

啟動觸發程式

  1. 流覽至 [ 數據處理站 ] 頁面,然後選取您建立的數據處理站。

  2. 在 [開啟 Azure Data Factory Studio] 圖格上選取 [開啟]。

    Author & Monitor

  3. 選擇 [作者] 索引標籤

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

    ARM template pipeline

  5. 選取 [立即新增觸發程式>]。

    Trigger

  6. 在 [管線執行] 下方的右窗格中,選取 [確定]。

監視管線

  1. 選取 [監視] 索引標籤

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

    Successful run

確認輸出檔案

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

  1. 在 [Azure 入口網站] 的 [容器] 頁面上,選取 [重新整理] 以查看輸出資料夾。

  2. 選取 資料夾清單中的輸出

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

    Output

清除資源

您可以透過兩種方式清除您在快速入門中建立的資源。 您可以 刪除 Azure 資源群組,其中包含資源群組中的所有資源。 如果您想要保留其他資源,請只刪除您在本教學課程中建立的數據處理站。

刪除資源群組會刪除包括數據處理站在內的所有資源。 執行下列命令以刪除整個資源群組:

Remove-AzResourceGroup -ResourceGroupName $resourcegroupname

如果您要只刪除資料處理站,而不是整個資源群組,請執行下列命令:

Remove-AzDataFactoryV2 -Name $dataFactoryName -ResourceGroupName $resourceGroupName

在本快速入門中,您已使用ARM範本建立 Azure Data Factory,並驗證部署。 若要深入瞭解 Azure Data Factory 和 Azure Resource Manager,請繼續閱讀下列文章。