Tablestore SDK for Python を使用して、Tablestore のデータテーブルを作成します。必要に応じて、テーブルスキーマ、オプション、セカンダリインデックス、および暗号化設定を構成してください。
注意事項
データテーブルを作成した後は、操作を実行する前にロードが完了するまでお待ちください。通常、数秒かかります。テーブルの準備が完了する前に操作を試みると失敗します。
前提条件
開始する前に、以下の要件を満たしていることを確認してください。
メソッド
def create_table(self, table_meta, table_options, reserved_throughput, secondary_indexes=[], sse_spec)
使用例
次の例では、STRING 型のプライマリキーカラムを 1 つ持つ test_table という名前のデータテーブルを作成します。
# データテーブルには少なくとも 1 つのプライマリキーカラムが必要です。
schema_of_primary_key = [('id', 'STRING')]
# テーブルスキーマを定義します。
table_meta = TableMeta('test_table', schema_of_primary_key)
# テーブルオプションを構成します。
table_options = TableOptions(time_to_live=-1, max_version=1, max_time_deviation=86400, allow_update=True)
# 予約スループットを設定します。デフォルトは 0 CU です。
# 0 以外の値は、CU モードの高性能インスタンスでのみ有効になります。
reserved_throughput = ReservedThroughput(CapacityUnit(0,0))
try:
client.create_table(table_meta, table_options, reserved_throughput)
print("Create table succeeded.")
except Exception as e:
print("Create table failed. %s" % e)
次の例では、データテーブル作成時に特定の設定を構成する方法を示します。
-
事前定義列の追加
defined_columns = [('name', 'STRING')] # テーブルスキーマに事前定義列を含めます。 table_meta = TableMeta('test_table', schema_of_primary_key, defined_columns) -
セカンダリインデックスの追加
# セカンダリインデックスのリストを定義します。 secondary_indexes = [ # インデックス名、プライマリキーカラム、事前定義列、インデックスタイプを指定します。 SecondaryIndexMeta('test_table_index', ['id', 'name'], [], index_type= SecondaryIndexType.LOCAL_INDEX) ] client.create_table(table_meta, table_options, reserved_throughput, secondary_indexes) -
データ暗号化の構成
SSESpecificationクラスを使用して、データテーブルのサーバ側暗号化 (SSE) を構成します。-
KMS 暗号化
sse_specification = SSESpecification(enable=True, key_type=SSEKeyType.SSE_KMS_SERVICE, key_id=None, role_arn=None) client.create_table(table_meta, table_option, reserved_throughput, sse_spec=sse_specification) -
BYOK 暗号化
説明このコードを実行する前に、CMK ID および RAM ロールの ARN を取得してください。詳細については、「BYOK 暗号化」をご参照ください。
key_id = "key-hzz6*****************" role_arn = "acs:ram::1705************:role/tabletorebyok" sse_specification = SSESpecification(enable=True, key_type=SSEKeyType.SSE_BYOK, key_id=key_id, role_arn=role_arn) client.create_table(table_meta, table_option, reserved_throughput, sse_spec=sse_specification)
-