【发布时间】:2021-05-06 03:25:52
【问题描述】:
我在两个不同区域有两个 DynamoDB 表,名称相同,都启用了流,都显示 Global Table 版本 2019.11.21,一个有数据,一个是空的。如果我举个例子,它们可以如下所示:
- 地区:us-east-1
- 表名:MyTable
- 全局表版本:2019.11.21
- 表有项目:是
- 地区:us-east-2
- 表名:MyTable
- 全局表版本:2019.11.21
- 表有项目:否
我使用boto3 DynamoDB client.create_global_table() 和client.update_global_table() 没有任何成功。
#1。尝试创建全局表
import boto3
client = boto3.client('dynamodb')
response = client.create_global_table(
GlobalTableName='MyTable',
ReplicationGroup=[
{
'RegionName': 'us-east-1'
},
]
)
输出:
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the CreateGlobalTable operation: One or more parameter values were invalid: Tables must be empty. These tables contain items: [TableReplica{regionName=us-east-1, tableName=MyTable}]
我了解client.create_global_table() API 调用仅适用于 DynamoDB 表版本2017.11.29,它要求表为空。所以,这对我不起作用。 Ref: here
#2。正在尝试更新全局表
import boto3
client = boto3.client('dynamodb')
update_response = client.update_global_table(
GlobalTableName='MyTable',
ReplicaUpdates=[
{
'Create': {
'RegionName': 'us-east-1'
}
}
]
)
输出:
botocore.errorfactory.GlobalTableNotFoundException: An error occurred (GlobalTableNotFoundException) when calling the UpdateGlobalTable operation: Global table not found: Global table with name: 'Mytable' does not exist.
添加第二个区域us-east-2 也无济于事。
boto3 文档版本 1.17.66 没有具体说明适用于该操作的 DynamoDB 表版本。所以,我相信这应该适用于 2019.11.21 版本,但首先必须有全局表。 Ref: here
根据this blog post,可以将单个区域现有的带有项目的Local Table 转换为Global table。博文中使用的示例是使用 AWS CLI,但提到也可以使用 AWS 开发工具包。
那么,我该如何用 boto3 做到这一点?
【问题讨论】:
-
那么你用过update_table吗?这与您在问题中显示的功能不同。所以它变得有点混乱。
-
您应该使用 update_table。你可以试试吗?
-
您引用的 AWS 博客为此使用了更新表。所以我不确定你的情况有什么不同?
-
呃!它有
{ 'Create': {...}, 'Update': {...}, 'Delete': {...} }和区域。我会试一试。 -
您的表必须是自动缩放的。所以先更新它以自动缩放,然后再为全局表更新它。
标签: amazon-web-services amazon-dynamodb boto3