本快速入門說明如何使用 Azure CLI 來建立 Azure Data Factory。 您在此數據處理站中建立的管線會將資料從一個資料夾複製到 Azure Blob 儲存體中的另一個資料夾。 如需如何使用 Azure Data Factory 轉換資料的資訊,請參閱 在 Azure Data Factory 中轉換資料。
如需 Azure Data Factory 服務的簡介,請參閱 Azure Data Factory 簡介。
如尚未擁有 Azure 訂用帳戶,請在開始之前先建立免費帳戶。
先決條件
使用 Azure Cloud Shell 中的 Bash 環境。 如需詳細資訊,請參閱開始使用 Azure Cloud Shell。
若要在本地執行 CLI 參考命令,請安裝 Azure CLI。 若您在 Windows 或 macOS 上執行,請考慮在 Docker 容器中執行 Azure CLI。 如需詳細資訊,請參閱 如何在 Docker 容器中執行 Azure CLI。
如果您使用的是本機安裝,請使用 az login 命令,透過 Azure CLI 來登入。 請遵循您終端機上顯示的步驟,完成驗證程序。 如需其他登入選項,請參閱 使用 Azure CLI 向 Azure 進行驗證。
出現提示時,請在第一次使用時安裝 Azure CLI 延伸模組。 如需擴充功能的詳細資訊,請參閱 使用和管理 Azure CLI 的擴充功能。
執行 az version 以尋找已安裝的版本和相依程式庫。 若要升級至最新版本,請執行 az upgrade。
備註
若要建立 Data Factory 執行個體,您用來登入 Azure 的使用者帳戶必須是參與者或擁有者角色的成員,或是 Azure 訂用帳戶的系統管理員。 如需詳細資訊,請參閱 Azure 角色。
準備容器和測試檔案
本快速入門會使用 Azure 儲存體帳戶,其中包含具有檔案的容器。
若要建立名為
ADFQuickStartRG的資源群組,請使用 az group create 命令:az group create --name ADFQuickStartRG --location eastus使用 az storage account create 命令建立儲存體帳戶:
az storage account create --resource-group ADFQuickStartRG \ --name adfquickstartstorage --location eastus-
az storage container create --resource-group ADFQuickStartRG --name adftutorial \ --account-name adfquickstartstorage --auth-mode key 在本機目錄中,建立名為 to upload 的
emp.txt檔案。 如果您在 Azure Cloud Shell 中工作,您可以使用echo $PWDBash 命令來尋找目前的工作目錄。 您可以使用標準 Bash 指令 (例如cat) 來建立檔案:cat > emp.txt This is text.使用 Ctrl+D 儲存新檔案。
若要將新檔案上傳至 Azure 儲存體容器,請使用 az storage blob upload 命令:
az storage blob upload --account-name adfquickstartstorage --name input/emp.txt \ --container-name adftutorial --file emp.txt --auth-mode key此命令會上傳至名為
input的新資料夾。
建立數據處理站
若要建立 Azure 資料處理站,請執行 az datafactory create 命令:
az datafactory create --resource-group ADFQuickStartRG \
--factory-name ADFTutorialFactory
這很重要
取代 ADFTutorialFactory 為全域唯一的數據處理站名稱,例如 ADFTutorialFactorySP1127。
您可以查看使用 az datafactory show 命令建立的資料處理站:
az datafactory show --resource-group ADFQuickStartRG \
--factory-name ADFTutorialFactory
建立連結服務和資料集
接下來,建立連結服務和兩個資料集。
使用 az storage account show-connection-string 命令取得儲存體帳戶的連接字串:
az storage account show-connection-string --resource-group ADFQuickStartRG \ --name adfquickstartstorage --key primary在您的工作目錄中,建立包含此內容的 JSON 檔案,其中包含您上一個步驟中的連接字串。 將檔案
AzureStorageLinkedService.json命名為:{ "type": "AzureBlobStorage", "typeProperties": { "connectionString": "DefaultEndpointsProtocol=https;AccountName=<accountName>;AccountKey=<accountKey>;EndpointSuffix=core.windows.net" } }使用
AzureStorageLinkedService命令建立名為 的連結服務:az datafactory linked-service create --resource-group ADFQuickStartRG \ --factory-name ADFTutorialFactory --linked-service-name AzureStorageLinkedService \ --properties AzureStorageLinkedService.json在您的工作目錄中,建立包含此內容的JSON檔案,名為
InputDataset.json:{ "linkedServiceName": { "referenceName": "AzureStorageLinkedService", "type": "LinkedServiceReference" }, "annotations": [], "type": "Binary", "typeProperties": { "location": { "type": "AzureBlobStorageLocation", "fileName": "emp.txt", "folderPath": "input", "container": "adftutorial" } } }-
az datafactory dataset create --resource-group ADFQuickStartRG \ --dataset-name InputDataset --factory-name ADFTutorialFactory \ --properties InputDataset.json 在您的工作目錄中,建立包含此內容的JSON檔案,名為
OutputDataset.json:{ "linkedServiceName": { "referenceName": "AzureStorageLinkedService", "type": "LinkedServiceReference" }, "annotations": [], "type": "Binary", "typeProperties": { "location": { "type": "AzureBlobStorageLocation", "folderPath": "output", "container": "adftutorial" } } }使用
OutputDataset命令建立名為的輸出資料集:az datafactory dataset create --resource-group ADFQuickStartRG \ --dataset-name OutputDataset --factory-name ADFTutorialFactory \ --properties OutputDataset.json
建立並執行管線
最後,建立並執行流水線。
在您的工作目錄中,建立具有以下內容的
Adfv2QuickStartPipeline.jsonJSON 檔案:{ "name": "Adfv2QuickStartPipeline", "properties": { "activities": [ { "name": "CopyFromBlobToBlob", "type": "Copy", "dependsOn": [], "policy": { "timeout": "7.00:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "typeProperties": { "source": { "type": "BinarySource", "storeSettings": { "type": "AzureBlobStorageReadSettings", "recursive": true } }, "sink": { "type": "BinarySink", "storeSettings": { "type": "AzureBlobStorageWriteSettings" } }, "enableStaging": false }, "inputs": [ { "referenceName": "InputDataset", "type": "DatasetReference" } ], "outputs": [ { "referenceName": "OutputDataset", "type": "DatasetReference" } ] } ], "annotations": [] } }使用
Adfv2QuickStartPipeline命令建立名為的管線:az datafactory pipeline create --resource-group ADFQuickStartRG \ --factory-name ADFTutorialFactory --name Adfv2QuickStartPipeline \ --pipeline Adfv2QuickStartPipeline.json使用 az datafactory pipeline create-run 命令來執行管線:
az datafactory pipeline create-run --resource-group ADFQuickStartRG \ --name Adfv2QuickStartPipeline --factory-name ADFTutorialFactory此命令會傳回執行標識碼。 複製它以用於下一個命令。
使用 az datafactory pipeline-run show 命令確認管線執行成功:
az datafactory pipeline-run show --resource-group ADFQuickStartRG \ --factory-name ADFTutorialFactory --run-id 00000000-0000-0000-0000-000000000000
您也可以使用 Azure 入口網站 驗證管線是否如預期般執行。 如需詳細資訊,請參閱 檢閱已部署的資源。
清理資源
本快速入門中的所有資源都是相同資源群組的一部分。 若要全部移除它們,請使用 az group delete 命令:
az group delete --name ADFQuickStartRG
如果您將此資源群組用於其他任何項目,請改為刪除個別資源。 例如,若要移除連結的服務,請使用 az datafactory linked-service delete 命令。
在本快速入門中,您已建立下列 JSON 檔案:
- AzureStorageLinkedService.json
- InputDataset.json
- OutputDataset.json
- Adfv2QuickStartPipeline.json
使用標準 Bash 命令刪除它們。