為 Amazon Keyspaces 中的現有資料表啟用 CDC 串流 - Amazon Keyspaces (適用於 Apache Cassandra)

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

為 Amazon Keyspaces 中的現有資料表啟用 CDC 串流

若要為現有資料表啟用 CDC 串流,您可以在 CQL 中使用 ALTER TABLE陳述式、將 update-table命令與 搭配使用 AWS CLI,也可以使用 主控台。

對於資料表中每個變更的資料列,Amazon Keyspaces 可以根據您cdc_specification選取的 view_type 的 擷取下列變更:

  • NEW_AND_OLD_IMAGES – 變更前後的兩個資料列版本。此為預設值。

  • NEW_IMAGE – 變更後的列版本。

  • OLD_IMAGE – 變更前的資料列版本。

  • KEYS_ONLY – 已變更之資料列的分割區和叢集索引鍵。

如需如何標記串流的詳細資訊,請參閱 將新標籤新增至串流

注意

Amazon Keyspaces CDC 需要存在服務連結角色 (AWSServiceRoleForAmazonKeyspacesCDC),以代表您將指標資料從 Amazon Keyspaces CDC 串流發佈到 CloudWatch 帳戶中"cloudwatch:namespace": "AWS/Cassandra"的 。系統會自動建立此角色。如需詳細資訊,請參閱使用 Amazon Keyspaces CDC 串流的角色

Cassandra Query Language (CQL)
使用 CQL 啟用串流 (CDC 串流)

您可以使用 ALTER TABLE為現有資料表啟用串流。

  1. 下列範例會建立僅擷取已變更資料列之分割區和叢集索引鍵變更的串流。

    ALTER TABLE mykeyspace.mytable WITH cdc = TRUE WITH CUSTOM_PROPERTIES={'cdc_specification': {'view_type': 'KEYS_ONLY'}};
  2. 若要驗證串流設定,您可以使用下列陳述式。

    SELECT keyspace_name, table_name, cdc, custom_properties FROM system_schema_mcs.tables WHERE keyspace_name = 'mykeyspace' AND table_name = 'mytable';

    陳述式的輸出看起來與此類似。

    keyspace_name | table_name | cdc | custom_properties ---------------+------------+------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- mykeyspace | mytable | True | {'capacity_mode': {'last_update_to_pay_per_request_timestamp': '1741385897045', 'throughput_mode': 'PAY_PER_REQUEST'}, 'cdc_specification': {'latest_stream_arn': 'arn:aws:cassandra:aws-region:111122223333:/keyspace/mykeyspace/table/mytable/stream/2025-03-07T22:20:10.454', 'status': 'ENABLED', 'view_type': 'KEYS_ONLY'}, 'encryption_specification': {'encryption_type': 'AWS_OWNED_KMS_KEY'}, 'point_in_time_recovery': {'status': 'disabled'}}
CLI
使用 建立 CDC 串流 AWS CLI
  1. 若要為現有資料表建立串流,您可以使用下列語法。

    aws keyspaces update-table \ --keyspace-name 'mykeyspace' \ --table-name 'mytable' \ --cdc-specification status=ENABLED,viewType=NEW_AND_OLD_IMAGES
  2. 該命令的輸出會顯示標準create-table回應,看起來與此範例類似。

    { "resourceArn": "arn:aws:cassandra:us-east-1:111222333444:/keyspace/mykeyspace/table/mytable" }
Console
使用 Amazon Keyspaces 主控台啟用 CDC 串流
  1. 登入 AWS Management Console,並在 https://https://console.aws.amazon.com/keyspaces/home 開啟 Amazon Keyspaces 主控台。

  2. 在導覽窗格中,選擇資料表,然後從清單中選擇資料表。

  3. 選擇串流索引標籤。

  4. 選擇編輯以啟用串流。

  5. 選取開啟串流

  6. 選擇串流的檢視類型。以下是可用的選項。請注意,您無法在建立串流之後變更串流的檢視類型。

    • 新舊映像 – Amazon Keyspaces 會擷取變更前後的兩個資料列版本。此為預設值。

    • 新映像 – Amazon Keyspaces 只會擷取變更後的資料列版本。

    • 舊映像 – Amazon Keyspaces 只會擷取變更前的資料列版本。

    • 僅限主索引鍵 – Amazon Keyspaces 只會擷取已變更資料列的分割區和叢集索引鍵資料欄。

  7. 若要完成,請選擇儲存變更