Amazon DynamoDB
开发人员指南 (API 版本 2012-08-10)
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 Amazon AWS 入门

01-create-table.py

01-create-table.py 程序创建一个表 (TryDaxTable)。本部分的其他 Python 程序都将依赖此表。

#!/usr/bin/env python3 from __future__ import print_function import os import amazondax import botocore.session region = os.environ.get('AWS_DEFAULT_REGION', 'us-west-2') session = botocore.session.get_session() dynamodb = session.create_client('dynamodb', region_name=region) # low-level client table_name = "TryDaxTable" params = { 'TableName' : table_name, 'KeySchema': [ { 'AttributeName': "pk", 'KeyType': "HASH"}, # Partition key { 'AttributeName': "sk", 'KeyType': "RANGE" } # Sort key ], 'AttributeDefinitions': [ { 'AttributeName': "pk", 'AttributeType': "N" }, { 'AttributeName': "sk", 'AttributeType': "N" } ], 'ProvisionedThroughput': { 'ReadCapacityUnits': 10, 'WriteCapacityUnits': 10 } } # Create the table dynamodb.create_table(**params) # Wait for the table to exist before exiting print('Waiting for', table_name, '...') waiter = dynamodb.get_waiter('table_exists') waiter.wait(TableName=table_name)