【问题标题】:How do I convert existing AWS DynamoDB Locals Tables into Global Tables using boto3如何使用 boto3 将现有 AWS DynamoDB 本地表转换为全局表
【发布时间】: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


【解决方案1】:

基于 cmets。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-21
    • 2020-02-27
    • 1970-01-01
    • 2018-06-07
    • 2017-07-28
    相关资源
    最近更新 更多