1
votes

I have two DynamoDB tables in two different regions, with the same name, both stream enabled, both showing Global Table version 2019.11.21, one has data and one is empty. If I give example, they can be shown like below:

  • Region: us-east-1
  • Table name: MyTable
  • Global Table Version: 2019.11.21
  • Table has items: Yes
  • Region: us-east-2
  • Table name: MyTable
  • Global Table Version: 2019.11.21
  • Table has items: No

I used boto3 DynamoDB client.create_global_table() and client.update_global_table() without any success.

#1. Trying to create Global Table

import boto3
client = boto3.client('dynamodb')
response = client.create_global_table(
    GlobalTableName='MyTable',
    ReplicationGroup=[
        {
            'RegionName': 'us-east-1'
        },
    ]
)

Output:

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}]

I understand that client.create_global_table() API call only applies to DynamoDB Table version 2017.11.29 which requires the tables to be empty. So, this won't work for me. Ref: here

#2. Trying to update Global Table

import boto3
client = boto3.client('dynamodb')
update_response = client.update_global_table(
    GlobalTableName='MyTable',
    ReplicaUpdates=[
        {
            'Create': {
                'RegionName': 'us-east-1'
            }
        }
    ]
)

Output:

botocore.errorfactory.GlobalTableNotFoundException: An error occurred (GlobalTableNotFoundException) when calling the UpdateGlobalTable operation: Global table not found: Global table with name: 'Mytable' does not exist.

Adding second region us-east-2 also do not help.

The boto3 documentation version 1.17.66 does not specify anything particular about the DynamoDB table version in which this operation applies to. So, I believe this should work for version 2019.11.21, but the Global Table first has to be in place. Ref: here

According to this blog post, a single region existing Local Table with items can be converted to a Global table. The example used in the blog post was using AWS CLI, but mentioned that AWS SDKs also could be used.

So, what how can I do this with boto3?

1
So have you used update_table? This is different function to what you shown in the question. So its getting a bit confusing.Marcin
You should be using update_table. Can you try with that?Marcin
The AWS blog that you referenced uses update table for this. So I'm not sure what is different in your case?Marcin
Uhha! It has { 'Create': {...}, 'Update': {...}, 'Delete': {...} } with region. I will give a shot.Rafiq
Your table must be autoscaled. So update it first to be autoscaled, and then update it again for global table.Marcin

1 Answers

2
votes

Based on the comments.

To update the existing local dynamodb table to global table, two steps need to be executed, both can be done using update_table:

  1. The existing table must be set to PAY_PER_REQUEST mode or AutoScale using update_table.
  2. Once the table is in one of these mode, update_table can be used again to set the table to global mode as explained in AWS blog.