本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在 Amazon Keyspaces 中建立新資料表時啟用 CDC 串流
若要在建立資料表時啟用 CDC 串流,您可以在 CQL 或 create-table
命令中使用 CREATE TABLE
陳述式與 AWS CLI。
對於資料表中每個變更的資料列,Amazon Keyspaces 可以根據您cdc_specification
選取的 view_type
的 擷取下列變更:
如需如何標記串流的詳細資訊,請參閱 建立資料表時,將標籤新增至新串流。
Amazon Keyspaces CDC 需要存在服務連結角色 (AWSServiceRoleForAmazonKeyspacesCDC
),以代表您將指標資料從 Amazon Keyspaces CDC 串流發佈到 CloudWatch 帳戶中"cloudwatch:namespace": "AWS/Cassandra"
的 。系統會自動建立此角色。如需詳細資訊,請參閱使用 Amazon Keyspaces CDC 串流的角色。
- Cassandra Query Language (CQL)
-
使用 CQL 建立資料表時啟用 CDC 串流
-
CREATE TABLE mykeyspace.mytable (a text, b text, PRIMARY KEY(a))
WITH CUSTOM_PROPERTIES={'cdc_specification': {'view_type': 'NEW_IMAGE'}} AND CDC = TRUE;
若要確認串流設定,您可以使用下列陳述式。
SELECT keyspace_name, table_name, cdc, custom_properties FROM system_schema_mcs.tables WHERE keyspace_name = 'mykeyspace' AND table_name = 'mytable';
該陳述式的輸出看起來應該與此類似。
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': '1741383893782', 'throughput_mode': 'PAY_PER_REQUEST'}, 'cdc_specification': {'latest_stream_arn': 'arn:aws:cassandra:aws-region
:111122223333:/keyspace/mykeyspace/table/mytable/stream/2025-03-07T21:44:53.783', 'status': 'ENABLED', 'view_type': 'NEW_IMAGE'}, 'encryption_specification': {'encryption_type': 'AWS_OWNED_KMS_KEY'}, 'point_in_time_recovery': {'status': 'disabled'}}
>
- CLI
-
當您使用 建立資料表時,啟用 CDC 串流 AWS CLI
-
若要建立串流,您可以使用下列語法。
aws keyspaces create-table \
--keyspace-name 'mykeyspace' \
--table-name 'mytable' \
--schema-definition 'allColumns=[{name=a,type=text},{name=b,type=text}],partitionKeys=[{name=a}]' \
--cdc-specification status=ENABLED,viewType=NEW_IMAGE
該命令的輸出會顯示標準create-table
回應,看起來與此範例類似。
{ "resourceArn": "arn:aws:cassandra:us-east-1:111222333444:/keyspace/mykeyspace/table/mytable" }