

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 設定零 ETL 整合的先決條件
<a name="zero-etl-prerequisites"></a>

設定來源與目標之間的整合需要一些先決條件，例如設定 IAM 角色，其 AWS Glue 使用 從來源存取資料並寫入目標，以及使用 KMS 金鑰加密中繼或目標位置的資料。

**Topics**
+ [設定來源資源](#zero-etl-setup-source-resources)
+ [設定目標資源](#zero-etl-setup-target-resources)
+ [建立 Amazon Redshift 資料倉儲](#zero-etl-setup-target-redshift-data-warehouse)
+ [為您的零 ETL 整合設定 VPC](#zero-etl-setup-vpc)
+ [設定零 ETL 跨帳戶整合](#zero-etl-setup-cross-account-integration)

## 設定來源資源
<a name="zero-etl-setup-source-resources"></a>

視需要為您的來源執行下列設定任務。

### 設定來源角色
<a name="zero-etl-setup-source-role"></a>

本節說明如何傳遞來源角色，以允許零 ETL 整合存取您的連線。這也僅適用於 SaaS 來源。

**注意**  
若要限制僅存取幾個連線，可以先建立連線以取得連線 ARN。請參閱 [設定零 ETL 整合的來源](zero-etl-sources.md)。

建立具有整合許可從而存取連線的角色：

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Sid": "GlueConnections",
            "Effect": "Allow",
            "Action": [
                "glue:GetConnections",
                "glue:GetConnection"
            ],
            "Resource": [
							"arn:aws:glue:*:111122223333:catalog",
							"arn:aws:glue:us-east-1:111122223333:connection/*"
            ]
        },
        {
            "Sid": "GlueActionBasedPermissions",
            "Effect": "Allow",
            "Action": [
                "glue:ListEntities",
                "glue:RefreshOAuth2Tokens"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
```

------

信任政策：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "glue.amazonaws.com"
        ]
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
```

------

## 設定目標資源
<a name="zero-etl-setup-target-resources"></a>

針對 AWS Glue Data Catalog 或 Amazon Redshift 資料倉儲整合目標，視需要執行下列設定任務。

對於與 AWS Glue 資料庫目標的整合：
+ [設定 AWS Glue 資料庫](#zero-etl-setup-target-resources-glue-database)
+ [提供目錄資源型存取 (RBAC) 政策](#zero-etl-setup-target-resources-rbac-policy)
+ [建立目標 IAM 角色](#zero-etl-setup-target-resources-target-iam-role)

對於與 Amazon Redshift 資料倉儲目標的整合：
+ [https://docs.aws.amazon.com/glue/latest/dg/zero-etl-prerequisites.html#zero-etl-setup-target-redshift-data-warehouse](https://docs.aws.amazon.com/glue/latest/dg/zero-etl-prerequisites.html#zero-etl-setup-target-redshift-data-warehouse)

### 設定 AWS Glue 資料庫
<a name="zero-etl-setup-target-resources-glue-database"></a>

對於使用 AWS Glue 資料庫的整合：

若要使用 Amazon S3 位置在 AWS Glue Data Catalog 中設定目標資料庫：

1. 在 AWS Glue 主控台首頁中，選取 Data Catalog 下的**資料庫**。

1. 選擇右上角的**新增資料**。如果已建立資料庫，請確保已針對資料庫設定具有 Amazon S3 URI 的位置。

1. 輸入名稱和**位置** (Amazon S3 URI)。請注意，零 ETL 整合需要位置。完成後，按一下**建立資料庫**。
**注意**  
Amazon S3 儲存貯體必須與 AWS Glue 資料庫位於相同的區域。

如需在 中建立新資料庫的資訊 AWS Glue，請參閱 [AWS Glue Data Catalog 入門](https://docs.aws.amazon.com/glue/latest/dg/start-data-catalog.htm)。

也可以使用 [https://docs.aws.amazon.com/cli/latest/reference/glue/create-database.html](https://docs.aws.amazon.com/cli/latest/reference/glue/create-database.html) CLI 在 AWS Glue中建立資料庫。請注意，需要 `--database-input` 中的 `LocationUri`。

#### 最佳化處理 Iceberg 資料表
<a name="zero-etl-common-setup-table-optimization"></a>

在 AWS Glue 目標資料庫中由 建立資料表後，您可以啟用壓縮以加速 Amazon Athena 中的查詢。如需有關設定壓縮資源 (IAM 角色) 的資訊，請參閱[資料表最佳化先決條件](https://docs.aws.amazon.com/glue/latest/dg/optimization-prerequisites.html)。

如需在整合建立的 AWS Glue 資料表上設定壓縮的詳細資訊，請參閱[最佳化 Iceberg 資料表](https://docs.aws.amazon.com/glue/latest/dg/table-optimizers.html)。

### 提供目錄資源型存取 (RBAC) 政策
<a name="zero-etl-setup-target-resources-rbac-policy"></a>

對於使用 AWS Glue 資料庫的整合，請將下列許可新增至目錄 RBAC 政策，以允許來源和目標之間的整合。

**注意**  
對於跨帳戶整合，Alice (建立整合的使用者) 角色政策和目錄資源政策都需要在資源上允許 `glue:CreateInboundIntegration`。對於相同帳戶，在資源上允許 `glue:CreateInboundIntegration` 的資源政策或角色政策就足夠。這兩種情況仍然需要允許 `glue.amazonaws.com` 進行 `glue:AuthorizeInboundIntegration`。

可以在 **Data Catalog** 下存取**目錄設定**。然後提供下列許可，並填寫缺少的資訊。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Principal": {
        "AWS": [
        	"arn:aws:iam::123456789012:user/Alice"
        ]
      },
      "Effect": "Allow",
      "Action": [
        "glue:CreateInboundIntegration"
      ],
      "Resource": [
      	"arn:aws:glue:us-east-1:111122223333:catalog",
				"arn:aws:glue:us-east-1:111122223333:database/DatabaseName"
      ],
      "Condition": {
        "StringLike": {
        "aws:SourceArn": "arn:aws:dynamodb:us-east-1:444455556666:table/<table-name>"
        }
      }
    },
    {
      "Principal": {
        "Service": [
          "glue.amazonaws.com"
        ]
      },
      "Effect": "Allow",
      "Action": [
        "glue:AuthorizeInboundIntegration"
      ],
      "Resource": [
      	"arn:aws:glue:us-east-1:111122223333:catalog",
				"arn:aws:glue:us-east-1:111122223333:database/DatabaseName"
      ],
      "Condition": {
        "StringEquals": {
        "aws:SourceArn": "arn:aws:dynamodb:us-east-1:444455556666:table/<table-name>"
        }
      }
    }
  ]
}
```

------

### 建立目標 IAM 角色
<a name="zero-etl-setup-target-resources-target-iam-role"></a>

建立具有下列許可和信任關係的目標 IAM 角色：

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket",
            "Effect": "Allow"
        },
        {
            "Action": [
                "s3:GetObject",
                "s3:PutObject",
                "s3:DeleteObject"
            ],
            "Resource": "arn:aws:s3:::amzn-s3-demo-bucket/prefix/*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "glue:GetDatabase"
            ],
            "Resource": [
                "arn:aws:glue:us-east-1:111122223333:catalog",
                "arn:aws:glue:us-east-1:111122223333:database/DatabaseName"
            ],
            "Effect": "Allow"
        },
        {
            "Action": [
                "glue:CreateTable",
                "glue:GetTable",
                "glue:GetTables",
                "glue:DeleteTable",
                "glue:UpdateTable",
                "glue:GetTableVersion",
                "glue:GetTableVersions",
                "glue:GetResourcePolicy"
            ],
            "Resource": [
                "arn:aws:glue:us-east-1:111122223333:catalog",
                "arn:aws:glue:us-east-1:111122223333:database/DatabaseName",
                "arn:aws:glue:us-east-1:111122223333:table/DatabaseName/*"
            ],
            "Effect": "Allow"
        },
        {
            "Action": [
                "cloudwatch:PutMetricData"
            ],
            "Resource": "*",
            "Condition": {
                "StringEquals": {
                    "cloudwatch:namespace": "AWS/Glue/ZeroETL"
                }
            },
            "Effect": "Allow"
        },
        {
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}
```

------

新增下列信任政策，以允許 AWS Glue 服務擔任該角色：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "glue.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
```

------

## 建立 Amazon Redshift 資料倉儲
<a name="zero-etl-setup-target-redshift-data-warehouse"></a>

當您的零 ETL 整合目標是 Amazon Redshift 資料倉儲時，如果還沒有資料倉儲，請建立一個。若要建立 Amazon Redshift Serverless 工作群組，請參閱[建立含命名空間的工作群組](https://docs.aws.amazon.com/redshift/latest/mgmt/serverless-console-workgroups-create-workgroup-wizard.html)。若要建立 Amazon Redshift 叢集，請參閱[建立叢集](https://docs.aws.amazon.com/redshift/latest/mgmt/create-cluster.html)。

目標 Amazon Redshift 工作群組或叢集必須開啟 `enable_case_sensitive_identifier` 參數，才能成功整合。如需啟用區分大小寫的詳細資訊，請參閱《Amazon Redshift 管理指南》中的[為您的資料倉儲開啟區分大小寫](https://docs.aws.amazon.com/redshift/latest/mgmt/zero-etl-setting-up.case-sensitivity.html)。

 Amazon Redshift 工作群組或叢集設定完成後，您需要設定資料倉儲。如需詳細資訊，請參閱[《 管理指南》中的零 ETL 整合入門](https://docs.aws.amazon.com/redshift/latest/mgmt/zero-etl-using.setting-up.html)。 Amazon Redshift 

## 為您的零 ETL 整合設定 VPC
<a name="zero-etl-setup-vpc"></a>

若要為您的零 ETL 整合設定 VPC：

1. 前往 **VPC** > 您的 VPC，然後選擇**建立 VPC**。

   1. 選取 **VPC 及其他選項**。

   1. 設定 VPC 名稱。

   1. 設定 IPv4 CIDR: 10.0.0.0/16。

   1. 將 AZ 數目設定為 1。

   1. 將公有和私有子網路的數目設定為 1。

   1. 將 **NAT 閘道**設定為 None。

   1. 將 **VPC 端點**設定為 S3 Gateway。

   1. 啟用 DNS 主機名稱和 DNS 解析。

1. 在**端點**下，選擇**建立端點**。

1. 在 VPC 的私有子網路中為這些服務建立端點 (使用預設安全群組)：

   1. com.amazonaws.us-east-1.lambda

   1. com.amazonaws.us-east-1.glue

   1. com.amazonaws.us-east-1.sts

建立 AWS Glue 連線：

1. 移至 **AWS Glue** > **資料連線**，然後選擇**建立連線**。

1. 選取**網路**。

1. 選取您建立的 VPC、子網路 (私有) 和預設安全群組。

### 設定 VPC 的目標角色
<a name="zero-etl-setup-vpc-target-role"></a>

目標角色必須具有以下許可 (除了零 ETL 整合所需的其他許可之外)：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "CustomerVpc",
      "Effect": "Allow",
      "Action": [
        "ec2:CreateTags",
        "ec2:DeleteTags",
        "ec2:DescribeRouteTables",
        "ec2:DescribeVpcEndpoints",
        "ec2:DescribeSecurityGroups",
        "ec2:DescribeSubnets",
        "ec2:CreateNetworkInterface",
        "ec2:DeleteNetworkInterface",
        "glue:GetConnection"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}
```

------

### 設定目標腿部資源屬性
<a name="zero-etl-setup-vpc-target-leg"></a>



如果您使用 CLI，請將目標腿部資源屬性設定為您建立的目標 AWS Glue 資料庫。傳遞目標角色 ARN，以及 AWS Glue 連線名稱。

```
aws glue create-integration-resource-property \
--resource-arn arn:aws:glue:us-east-1:<account-id>:database/exampletarget \
--target-processing-properties '{"RoleArn" : "arn:aws:iam::<account-id>:role/example-role", "ConnectionName":"example-vpc-3"}' \
--endpoint-url https://example.amazonaws.com --region us-east-1
```

### 可能的用戶端錯誤
<a name="zero-etl-setup-vpc-client-errors"></a>

以下是使用 VPC 設定的整合可能會發生的用戶端錯誤。


| 錯誤訊息 | 需執行的動作 | 
| --- | --- | 
| 提供的角色無權在連線時執行 glue:GetConnection。將此許可新增至角色政策，然後等待整合復原。 | 更新角色政策 | 
| 提供的角色未獲授權執行 ec2:DescribeSubnets。將此許可新增至角色政策，然後等待整合復原。 | 更新角色政策 | 
| 提供的角色未獲授權執行 ec2:DescribeSecurityGroups。將此許可新增至角色政策，然後等待整合復原。 | 更新角色政策 | 
| 提供的角色未獲授權執行 ec2:DescribeVpcEndpoints。將此許可新增至角色政策，然後等待整合復原。 | 更新角色政策 | 
| 提供的角色未獲授權執行 ec2:DescribeRouteTables。將此許可新增至角色政策，然後等待整合復原。 | 更新角色政策 | 
| 提供的角色未獲授權執行 ec2:CreateTags。將此許可新增至角色政策，然後等待整合復原。 | 更新角色政策 | 
| 提供的角色未獲授權執行 ec2:CreateNetworkInterface。將此許可新增至角色政策，然後等待整合復原。 | 更新角色政策 | 
| 提供的連線子網路不包含有效的 S3 端點或 NAT 閘道。更新子網路，然後等待整合復原。 | 更新 VPC 子網路端點 | 
| 找不到連線子網路。更新連線子網路，然後等待整合復原。 | 更新 AWS Glue 連線 | 
| 找不到連線安全群組。更新連線安全群組，然後等待整合復原。 | 更新 AWS Glue 連線 | 
| 無法透過提供的 VPC 連線來連線至 S3。更新子網路組態，然後等待整合復原。 | 更新 VPC 子網路端點 | 
| 無法透過提供的 VPC 連線來連線至 Lambda。更新子網路組態，然後等待整合復原。 | 更新 VPC 子網路端點 | 

## 設定零 ETL 跨帳戶整合
<a name="zero-etl-setup-cross-account-integration"></a>

若要設定零 ETL 跨帳戶整合：

1. 設定目標資源政策，如 [提供目錄資源型存取 (RBAC) 政策](#zero-etl-setup-target-resources-rbac-policy) 中所述。確保在目標資源上明確允許來源帳戶角色。

1. 檢查來源帳戶角色 (用來建立整合的角色) 是否具有下列權限：

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Sid": "Stmt123456789012",
               "Action": [
                   "glue:CreateInboundIntegration"
               ],
               "Effect": "Allow",
               "Resource": [
               	"arn:aws:glue:us-east-1:111122223333:catalog",
   							"arn:aws:glue:us-east-1:111122223333:database/DatabaseName"
               ]
           }
       ]
   }
   ```

------

1. 建立整合，如 [建立整合](zero-etl-common-integration-tasks.md#zero-etl-creating) 中所述。