クイック スタート: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 Object Notation (JSON) ファイルであり、プロジェクトのインフラストラクチャと構成が定義されています。 このテンプレートでは、宣言型の構文が使用されています。 デプロイしようとしているものを、デプロイを作成する一連のプログラミング コマンドを記述しなくても記述できます。

Note

この記事では、Data Factory サービスの概要については詳しく取り上げません。 Azure Data Factory サービスの概要については、「Azure Data Factory の概要」をご覧ください。

環境が前提条件を満たしていて、ARM テンプレートの使用に慣れている場合は、 [Azure へのデプロイ] ボタンを選択します。 Azure portal でテンプレートが開きます。

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 サブスクリプションを選択します。
    • [リソース グループ] : [新規作成] を選択し、リソース グループの一意の名前を入力し、 [OK] を選択します。
    • [リージョン] :場所を選択します。 たとえば、East US などとします。
    • データ ファクトリ名: 規定値を使用します。
    • [場所] :既定値を使用します。
    • [ストレージ アカウント名] : 既定値を使用します。
    • 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. [Open Azure Data Factory Studio](Azure Data Factory Studio を開く) タイルで [開く] を選択します。

    Author & Monitor

  3. [作成] タブ を選択します。

  4. 作成したパイプライン (ArmtemplateSampleCopyPipeline) を選択します。

    ARM template pipeline

  5. [トリガーの追加]>[Trigger Now](今すぐトリガー) の順に選択します。

    Trigger

  6. [パイプラインの実行] の下の右側のウィンドウで、 [OK] を選択します。

パイプラインの監視

  1. [監視] タブを選択します。

  2. パイプラインの実行に関連付けられたアクティビティの実行が表示されます。 このクイック スタートでは、パイプラインに、コピーという種類のアクティビティが 1 つのみ含まれます。 そのため、そのアクティビティの実行が表示されます。

    Successful run

出力ファイルを検証する

パイプラインでは、BLOB コンテナー内に出力フォルダーが自動的に作成されます。 そのうえで、input フォルダーから output フォルダーに emp.txt ファイルをコピーします。

  1. Azure portal の [コンテナー] ページで、 [最新の情報に更新] を選択して出力フォルダーを表示します。

  2. フォルダー一覧で、 [output] を選択します。

  3. emp.txt が output フォルダーにコピーされていることを確認します。

    Output

リソースをクリーンアップする

このクイックスタートで作成したリソースは、2 とおりの方法でクリーンアップすることができます。 Azure リソース グループを削除します。この場合、そのリソース グループに含まれているすべてのリソースが対象となります。 他のリソースをそのまま維持する場合は、このチュートリアルで作成したデータ ファクトリだけを削除してください。

リソース グループを削除すると、その中のデータ ファクトリも含めて、すべてのリソースが削除されます。 次のコマンドを実行して、リソース グループ全体を削除します。

Remove-AzResourceGroup -ResourceGroupName $resourcegroupname

リソース グループ全体ではなく、データ ファクトリだけを削除する場合は、次のコマンドを実行します。

Remove-AzDataFactoryV2 -Name $dataFactoryName -ResourceGroupName $resourceGroupName

このクイックスタートでは、ARM テンプレートを使用して Azure Data Factory を作成し、デプロイを検証しました。 Azure Data Factory と Azure Resource Manager の詳細については、引き続き以下の記事を参照してください。