【发布时间】:2018-04-18 01:32:28
【问题描述】:
是否可以在创建后向现有 DynamoDB 表添加全局二级索引?我正在将 Python 3.x 与 Boto3 一起使用,并且在创建表后无法找到将它们添加到表中的任何示例。
【问题讨论】:
标签: amazon-dynamodb boto3 python-ggplot
是否可以在创建后向现有 DynamoDB 表添加全局二级索引?我正在将 Python 3.x 与 Boto3 一起使用,并且在创建表后无法找到将它们添加到表中的任何示例。
【问题讨论】:
标签: amazon-dynamodb boto3 python-ggplot
一般来说,是的,可以在创建表后添加全局二级索引 (GSI)。
但是,更改可能需要很长时间才能生效,因为构建 GSI 需要进行表扫描。
boto3的情况看the documentation for update_table
例如,你尝试这样的事情:
response = client.update_table(
TableName = 'YourTableName',
# ...snip...
GlobalSecondaryIndexUpdates=[
{
'Create': {
'IndexName': 'YourGSIName',
'KeySchema': [
{
'AttributeName': 'YourGSIFieldName',
'KeyType': 'HASH'
}
],
'Projection': {
'ProjectionType': 'ALL'
},
'ProvisionedThroughput': {
'ReadCapacityUnits': 1,
'WriteCapacityUnits': 1
}
}
}
],
# ...snip...
)
【讨论】: