

 Amazon Redshift 將不再支援從修補程式 198 開始建立新的 Python UDFs。現有 Python UDF 將繼續正常運作至 2026 年 6 月 30 日。如需詳細資訊，請參閱[部落格文章](https://aws.amazon.com/blogs/big-data/amazon-redshift-python-user-defined-functions-will-reach-end-of-support-after-june-30-2026/)。

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

# 建立 DynamoDB 的零 ETL 整合
<a name="zero-etl-setting-up.create-integration-ddb"></a>

在建立零 ETL 整合之前，請先檢閱 [將零 ETL 整合與 Amazon Redshift 搭配使用的考量](zero-etl.reqs-lims.md) 中所述的考量事項和需求。依照此一般流程進行，以建立從 DynamoDB 到 Amazon Redshift 的零 ETL 整合

**透過零 ETL 整合將 DynamoDB 資料複寫至 Amazon Redshift**

1. 確認您的登入憑證允許使用零 ETL 整合搭配 Amazon Redshift 和 DynamoDB 的許可。請參閱 [要搭配 DynamoDB 零 ETL 整合使用的 IAM 政策](#zero-etl-signin-iam-policy) 中的範例 IAM 政策。

1. 從 DynamoDB 主控台，[設定您的 DynamoDB 資料表](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/RedshiftforDynamoDB-zero-etl.html#RedshiftforDynamoDB-zero-etl-prereqs)，使其具有時間點復原 (PITR)、資源政策、身分型政策和加密金鑰許可，如《Amazon DynamoDB 開發人員指南》**中所述。

1. 從 Amazon Redshift 主控台：[建立和設定目標 Amazon Redshift 資料倉儲](zero-etl-setting-up.rs-data-warehouse.md)。
   + 從 AWS CLI 或 Amazon Redshift 主控台：[為資料倉儲開啟區分大小寫功能](zero-etl-setting-up.case-sensitivity.md)。
   + 從 Amazon Redshift 主控台：[設定 Amazon Redshift 資料倉儲的授權](zero-etl-using.redshift-iam.md)。

1. 從 Amazon Redshift 主控台建立零 ETL 整合，如本主題稍後所述。

1. 從 Amazon Redshift 主控台，在您的 Amazon Redshift 資料倉儲中建立目的地資料庫。如需詳細資訊，請參閱[在 Amazon Redshift 中建立目的地資料庫](zero-etl-using.creating-db.md)。

1. 從 Amazon Redshift 主控台，查詢 Amazon Redshift 資料倉儲中的複寫資料。如需詳細資訊，請參閱[在 Amazon Redshift 中查詢複寫的資料](zero-etl-using.querying-and-creating-materialized-views.md)。

在此步驟中，您會建立與 Amazon Redshift 的 Amazon DynamoDB 零 ETL 整合。

------
#### [ Amazon Redshift console ]

**使用 Amazon Redshift 主控台建立與 Amazon Redshift 的 Amazon DynamoDB 零 ETL 整合**

1. 從 Amazon Redshift 主控台，選擇**零 ETL 整合**。在列出零 ETL 整合的窗格中，選擇**建立零 ETL 整合**、**建立 DynamoDB 整合**。

1. 在建立整合的頁面上，輸入整合的相關資訊，如下所示：
   + 輸入**整合名稱** - 這是可用來參考整合的唯一名稱。
   + 輸入**說明** - 說明要從來源複寫到目標的資料。
   + 選擇 DynamoDB **來源資料表** - 可以選擇一個 DynamoDB 資料表。必須在資料表上啟用時間點復原 (PITR)。只會顯示資料表大小不超過上限 100 TB (TiB) 的資料表。來源 DynamoDB 資料表必須加密。來源也必須具有包含授權主體和整合來源的資源政策。如果這些政策不正確，您會看到**為我修正**選項。
   + 選擇目標 **Amazon Redshift 資料倉儲** - 資料倉儲可以是 Amazon Redshift 佈建叢集或 Redshift Serverless 工作群組。如果您的目標 Amazon Redshift 位於相同的帳戶中，您就可以選取目標。如果目標位於不同的帳戶中，您可以指定 **Redshift 資料倉儲 ARN**。目標必須具有包含授權主體和整合來源的資源政策，且 `enable_case_sensitive_identifier` 參數設定為 true。如果您的目標上沒有正確的資源政策，且您的目標位於相同的帳戶中，您可以選取**為我修正**選項，以便在建立整合程序期間自動套用資源政策。如果您的目標位於不同的 AWS 帳戶中，則須在 Amazon Redshift 倉儲上手動套用資源政策。如果您的目標 Amazon Redshift 資料倉儲未將正確的參數群組選項 `enable_case_sensitive_identifier` 設定為 `true`，您可以選取**為我修正**選項，以在建立整合的過程中自動更新此參數群組並重新啟動倉儲。
   + 最多可輸入 50 個標籤**索引鍵**和選用的**值** - 提供有關整合的其他中繼資料。如需詳細資訊，請參閱[在 Amazon Redshift 中標記資源](amazon-redshift-tagging.md)。
   + 選擇**加密**選項 - 加密整合。如需詳細資訊，請參閱[使用客戶自管金鑰加密 DynamoDB 整合](#zero-etl.create-encrypt)。

     當您加密整合時，您也可以新增**其他加密內容**。如需詳細資訊，請參閱[加密內容](#zero-etl.add-encryption-context)。

1. 此時會出現檢閱頁面，您可以在此選擇**建立 DynamoDB 整合**。

1. 此時會出現進度頁面，您可以在此檢視建立零 ETL 整合的各種不同任務的進度。

1. 整合建立並處於作用中狀態後，在整合的詳細資訊頁面上，選擇**連線至資料庫**。若是第一次建立 Amazon Redshift 資料倉儲，則也會建立資料庫。您需要連線到目標資料倉儲中的任何資料庫，才能為整合建立另一個資料庫。在**連線至資料庫**頁面中，判斷您是否可以使用最近的連線，並選擇**身分驗證**方法。根據您的身分驗證方法，輸入資訊以連線至目標中的現有資料庫。此身分驗證資訊可包含現有的**資料庫名稱** (通常是 `dev`)，以及使用 Amazon Redshift 資料倉儲建立資料庫時指定的**資料庫使用者**。

1. 連線至資料庫之後，選擇**從整合建立資料庫**，即可建立資料庫，以便從來源接收資料。當您建立資料庫時，您會提供**整合 ID**、**資料倉儲名稱**和**資料庫名稱**。

1. 整合狀態和目的地資料庫為 `Active` 之後，資料就會開始從 DynamoDB 資料表複寫至目標資料表。隨著您新增資料至來源，資料會自動複寫到目標 Amazon Redshift 資料倉儲。

------
#### [ AWS CLI ]

若要使用 建立與 Amazon Redshift 的 Amazon DynamoDB 零 ETL 整合 AWS CLI，請使用 `create-integration`命令搭配下列選項：
+ `integration-name` - 指定整合的名稱。
+ `source-arn` - 指定 DynamoDB 來源的 ARN。
+ `target-arn` - 指定 Amazon Redshift 佈建叢集或 Redshift Serverless 工作群組目標的命名空間 ARN。

下列範例藉由提供整合名稱、來源 ARN 和目標 ARN 來建立整合。整合不會經過加密。

```
aws redshift create-integration \
--integration-name ddb-integration \
--source-arn arn:aws:dynamodb:us-east-1:123456789012:table/books \
--target-arn arn:aws:redshift:us-east-1:123456789012:namespace:a1b2c3d4-5678-90ab-cdef-EXAMPLE22222
          
{
    "Status": "creating",
    "IntegrationArn": "arn:aws:redshift:us-east-1:123456789012:integration:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",
    "Errors": [],
    "ResponseMetadata": {
        "RetryAttempts": 0,
        "HTTPStatusCode": 200,
        "RequestId": "132cbe27-fd10-4f0a-aacb-b68f10bb2bfb",
        "HTTPHeaders": {
            "x-amzn-requestid": "132cbe27-fd10-4f0a-aacb-b68f10bb2bfb",
            "date": "Sat, 24 Aug 2024 05:44:08 GMT",
            "content-length": "934",
            "content-type": "text/xml"
        }
    },
    "Tags": [],
    "CreateTime": "2024-08-24T05:44:08.573Z",
    "KMSKeyId": "arn:aws:kms:us-east-1:123456789012:key/a1b2c3d4-5678-90ab-cdef-EXAMPLE33333",
    "AdditionalEncryptionContext": {},
    "TargetArn": "arn:aws:redshift:us-east-1:123456789012:namespace:a1b2c3d4-5678-90ab-cdef-EXAMPLE22222",
    "IntegrationName": "ddb-integration",
    "SourceArn": "arn:aws:dynamodb:us-east-1:123456789012:table/books"
}
```

下列範例會使用客戶自管金鑰進行加密來建立整合。建立整合之前：
+ 在來源 DynamoDB 資料表的相同帳戶 (範例中稱為 "AccountA") 中建立客戶自管金鑰 (範例中稱為 "CMCMK")。
+ 確定用於建立整合的使用者/角色 (範例中稱為 "RoleA") 具有此 KMS 金鑰的 `kms:CreateGrant` 和 `kms:DescribeKey` 許可。
+ 將以下各項新增至金鑰政策。

```
{
    "Sid": "Enable RoleA to create grants with key",
    "Effect": "Allow",
    "Principal": {
        "AWS": "RoleA-ARN"
    },
    "Action": "kms:CreateGrant",
    "Resource": "*",
    "Condition": {
        // Add "StringEquals" condition if you plan to provide additional encryption context
        // for the zero-ETL integration. Ensure that the key-value pairs added here match
        // the key-value pair you plan to use while creating the integration.
        // Remove this if you don't plan to use additional encryption context
        "StringEquals": {
            "kms:EncryptionContext:context-key1": "context-value1"
        },
        "ForAllValues:StringEquals": {
            "kms:GrantOperations": [
                "Decrypt",
                "GenerateDataKey",
                "CreateGrant"
            ]
        }
    }
},
{
    "Sid": "Enable RoleA to describe key",
    "Effect": "Allow",
    "Principal": {
        "AWS": "RoleA-ARN"
    },
    "Action": "kms:DescribeKey",
    "Resource": "*"
},
{
    "Sid": "Allow use by RS SP",
    "Effect": "Allow",
    "Principal": {
        "Service": "redshift.amazonaws.com" 
           },
    "Action": "kms:CreateGrant",
    "Resource": "*"
}
```

```
aws redshift create-integration \
--integration-name ddb-integration \
--source-arn arn:aws:dynamodb:us-east-1:123456789012:table/books \
--target-arn arn:aws:redshift:us-east-1:123456789012:namespace:a1b2c3d4-5678-90ab-cdef-EXAMPLE22222 \
--kms-key-id arn:aws:kms:us-east-1:123456789012:key/a1b2c3d4-5678-90ab-cdef-EXAMPLE33333 \
--additional-encryption-context key33=value33  // This matches the condition in the key policy.
          {
    "IntegrationArn": "arn:aws:redshift:us-east-1:123456789012:integration:a1b2c3d4-5678-90ab-cdef-EXAMPLE11111",
    "IntegrationName": "ddb-integration",
    "SourceArn": "arn:aws:dynamodb:us-east-1:123456789012:table/books",
    "SourceType": "dynamodb",
    "TargetArn": "arn:aws:redshift:us-east-1:123456789012:namespace:a1b2c3d4-5678-90ab-cdef-EXAMPLE22222",
    "Status": "creating",
    "Errors": [],
    "CreateTime": "2024-10-02T18:29:26.710Z",
    "KMSKeyId": "arn:aws:kms:us-east-1:123456789012:key/a1b2c3d4-5678-90ab-cdef-EXAMPLE33333",
    "AdditionalEncryptionContext": {
        "key33": "value33"
    },
    "Tags": []
}
```

------

## 要搭配 DynamoDB 零 ETL 整合使用的 IAM 政策
<a name="zero-etl-signin-iam-policy"></a>

建立零 ETL 整合時，您的登入憑證必須同時具有 DynamoDB 和 Amazon Redshift 動作的許可，以及具有作為整合來源和目標之資源的許可。以下範例示範所需的最低許可。

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

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:ListTables"
            ],
            "Resource": "*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:GetResourcePolicy",
                "dynamodb:PutResourcePolicy",
                "dynamodb:UpdateContinuousBackups"
            ],
            "Resource": [
            "arn:aws:dynamodb:us-east-1:111122223333:table/my-ddb-table"
            ]
        },
        {
            "Sid": "AllowRedshiftDescribeIntegration",
            "Effect": "Allow",
            "Action": [
                "redshift:DescribeIntegrations"
            ],
            "Resource": "*"
        },
        {
            "Sid": "AllowRedshiftCreateIntegration",
            "Effect": "Allow",
            "Action": "redshift:CreateIntegration",
            "Resource": "arn:aws:redshift:us-east-1:111122223333:integration:*"
        },
        {
            "Sid": "AllowRedshiftModifyDeleteIntegration",
            "Effect": "Allow",
            "Action": [
                "redshift:ModifyIntegration",
                "redshift:DeleteIntegration"
            ],
            "Resource": "arn:aws:redshift:us-east-1:111122223333:integration:<uuid>"
        },
        {
            "Sid": "AllowRedshiftCreateInboundIntegration",
            "Effect": "Allow",
            "Action": "redshift:CreateInboundIntegration",
            "Resource": "arn:aws:redshift:us-east-1:111122223333:namespace:<uuid>"
        }
    ]
}
```

------

## 使用客戶自管金鑰加密 DynamoDB 整合
<a name="zero-etl.create-encrypt"></a>

如果您在建立 DynamoDB 零 ETL 整合 AWS 擁有的金鑰 時指定自訂 KMS 金鑰，而不是 ，則金鑰政策必須提供 Amazon Redshift 服務主體對 `CreateGrant`動作的存取權。此外，政策必須允許請求者帳戶或角色許可執行 `DescribeKey` 和 `CreateGrant` 動作。

下列範例金鑰政策陳述式示範政策中所需的許可。有些範例包含內容索引鍵，可進一步縮減許可範圍。

### 範例金鑰政策陳述式
<a name="zero-etl.kms-sample-policy"></a>

下列政策陳述式允許請求者帳戶或角色擷取 KMS 金鑰的相關資訊。

```
{
   "Effect":"Allow",
   "Principal":{
      "AWS":"arn:aws:iam::{account-ID}:role/{role-name}"
   },
   "Action":"kms:DescribeKey",
   "Resource":"*"
}
```

下列政策陳述式允許請求者帳戶或角色新增授權至 KMS 金鑰。[https://docs.aws.amazon.com/kms/latest/developerguide/conditions-kms.html#conditions-kms-via-service](https://docs.aws.amazon.com/kms/latest/developerguide/conditions-kms.html#conditions-kms-via-service) 條件金鑰會將 KMS 金鑰的使用限於來自 Amazon Redshift 的請求。

```
{
   "Effect":"Allow",
   "Principal":{
      "AWS":"arn:aws:iam::{account-ID}:role/{role-name}"
   },
   "Action":"kms:CreateGrant",
   "Resource":"*",
   "Condition":{
      "StringEquals":{
         "kms:EncryptionContext:{context-key}":"{context-value}",
         "kms:ViaService":"redshift.{region}.amazonaws.com"
      },
      "ForAllValues:StringEquals":{
         "kms:GrantOperations":[
            "Decrypt",
            "GenerateDataKey",
            "CreateGrant"
         ]
      }
   }
}
```

下列政策陳述式允許 Amazon Redshift 服務主體將授權新增至 KMS 金鑰。

```
{
   "Effect":"Allow",
   "Principal":{
      "Service":"redshift.amazonaws.com"
   },
   "Action":"kms:CreateGrant",
   "Resource":"*",
   "Condition":{
      "StringEquals":{
         "kms:EncryptionContext:{context-key}":"{context-value}",
         "aws:SourceAccount":"{account-ID}"
      },
      "ForAllValues:StringEquals":{
         "kms:GrantOperations":[
            "Decrypt",
            "GenerateDataKey",
            "CreateGrant"
         ]
      },
      "ArnLike":{
         "aws:SourceArn":"arn:aws:*:{region}:{account-ID}:integration:*"
      }
   }
}
```

如需詳細資訊，請參閱《AWS Key Management Service 開發人員指南》**中的[建立金鑰政策](https://docs.aws.amazon.com/kms/latest/developerguide/key-policy-overview.html)。

## 加密內容
<a name="zero-etl.add-encryption-context"></a>

當您加密零 ETL 整合時，您可以將金鑰-值對新增為**其他加密內容**。您可能希望新增這些金鑰-值對，以新增有關複寫資料的其他內容資訊。如需詳細資訊，請參閱 *AWS Key Management Service 開發人員指南*中的[加密內容](https://docs.aws.amazon.com//kms/latest/developerguide/encrypt_context.html)。

除了您新增的任何項目之外，Amazon Redshift 還會新增下列加密內容對：
+ `aws:redshift:integration:arn` - `IntegrationArn`
+ `aws:servicename:id` - `Redshift`

這會將您可以新增的整體配對數量從 8 減少為 6，並對授予限制的整體字元限制造成影響。如需詳細資訊，請參閱《AWS Key Management Service 開發人員指南》**中的[使用授予限制條件](https://docs.aws.amazon.com/kms/latest/developerguide/create-grant-overview.html#grant-constraints)。