如何使用 boto3 将现有的 AWS DynamoDB Locals 表转换为全局表

How do I convert existing AWS DynamoDB Locals Tables into Global Tables using boto3

我在两个不同的区域有两个 DynamoDB table,名称相同,都启用了流,都显示 Global Table 版本 2019.11.21,一个有数据,一个为空。如果我举个例子,它们可以如下所示:

我使用了 boto3 DynamoDB client.create_global_table()client.update_global_table() 但没有成功。

#1。尝试创建全局 Table

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 Table 版本 2017.11.29,它要求 table 为空。所以,这对我不起作用。 Ref: here

#2。正在尝试更新全局 Table

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 table 版本。所以,我相信这应该适用于版本 2019.11.21,但首先必须要有 Global Table。 Ref: here

根据 this blog post,单个区域现有本地 Table 和项目可以转换为全球 table。博客 post 中使用的示例使用的是 AWS CLI,但提到也可以使用 AWS SDK。

那么,我该如何使用 boto3 执行此操作?

根据评论。

要将现有的本地 dynamodb table 更新为全局 table,需要执行两个步骤,都可以使用 update_table:

完成
  1. 现有 table 必须设置为 PAY_PER_REQUEST 模式或 AutoScale 使用 update_table
  2. 一旦 table 处于其中一种模式,update_table 可再次用于将 table 设置为全局模式,如 AWS blog 中所述。