建立 DynamoDB 的零 ETL 整合 - Amazon Redshift

Amazon Redshift 自 2025 年 11 月 1 日起不再支援建立新的 Python UDF。如果您想要使用 Python UDF,請在該日期之前建立 UDF。現有 Python UDF 將繼續正常運作。如需詳細資訊,請參閱部落格文章

建立 DynamoDB 的零 ETL 整合

在建立零 ETL 整合之前,請先檢閱 將零 ETL 整合與 Amazon Redshift 搭配使用的考量 中所述的考量事項和需求。依照此一般流程進行,以建立從 DynamoDB 到 Amazon Redshift 的零 ETL 整合

透過零 ETL 整合將 DynamoDB 資料複寫至 Amazon Redshift
  1. 確認您的登入憑證允許使用零 ETL 整合搭配 Amazon Redshift 和 DynamoDB 的許可。請參閱 要搭配 DynamoDB 零 ETL 整合使用的 IAM 政策 中的範例 IAM 政策。

  2. 從 DynamoDB 主控台,設定您的 DynamoDB 資料表,使其具有時間點復原 (PITR)、資源政策、身分型政策和加密金鑰許可,如《Amazon DynamoDB 開發人員指南》中所述。

  3. 從 Amazon Redshift 主控台:建立和設定目標 Amazon Redshift 資料倉儲

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

  5. 從 Amazon Redshift 主控台,在您的 Amazon Redshift 資料倉儲中建立目的地資料庫。如需更多詳細資訊,請參閱 在 Amazon Redshift 中建立目的地資料庫

  6. 從 Amazon Redshift 主控台,查詢 Amazon Redshift 資料倉儲中的複寫資料。如需更多詳細資訊,請參閱 在 Amazon Redshift 中查詢複寫的資料

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

Amazon Redshift console
使用 Amazon Redshift 主控台建立與 Amazon Redshift 的 Amazon DynamoDB 零 ETL 整合
  1. 從 Amazon Redshift 主控台,選擇零 ETL 整合。在列出零 ETL 整合的窗格中,選擇建立零 ETL 整合建立 DynamoDB 整合

  2. 在建立整合的頁面上,輸入整合的相關資訊,如下所示:

    • 輸入整合名稱 - 這是可用來參考整合的唯一名稱。

    • 輸入說明 - 說明要從來源複寫到目標的資料。

    • 選擇 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 中標記資源

    • 選擇加密選項 - 加密整合。如需更多詳細資訊,請參閱 使用客戶自管金鑰加密 DynamoDB 整合

      當您加密整合時,您也可以新增其他加密內容。如需更多詳細資訊,請參閱 加密內容

  3. 此時會出現檢閱頁面,您可以在此選擇建立 DynamoDB 整合

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

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

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

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

AWS CLI

若要使用 AWS CLI 建立與 Amazon Redshift 的 Amazon DynamoDB 零 ETL 整合,請使用 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:CreateGrantkms: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 政策

建立零 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 整合

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

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

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

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

下列政策陳述式允許請求者帳戶或角色新增授權至 KMS 金鑰。kms:ViaService 條件金鑰會將 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 開發人員指南》中的建立金鑰政策

加密內容

當您加密零 ETL 整合時,您可以將金鑰-值對新增為其他加密內容。您可能希望新增這些金鑰-值對,以新增有關複寫資料的其他內容資訊。如需詳細資訊,請參閱 AWS Key Management Service 開發人員指南中的加密內容

除了您新增的任何項目之外,Amazon Redshift 還會新增下列加密內容對:

  • aws:redshift:integration:arn - IntegrationArn

  • aws:servicename:id - Redshift

這會將您可以新增的整體配對數量從 8 減少為 6,並對授予限制的整體字元限制造成影響。如需詳細資訊,請參閱《AWS Key Management Service 開發人員指南》中的使用授予限制條件