I have two DynamoDB tables in two different regions, with the same name, both streams enabled, both showing Global Table version 2019.11.21, one has data and one is empty. If I give examples, they can be shown below:
- Region: us-east-1
- Table name: MyTable
- Global Table Version: 2019.11.21
- The table has items: Yes
- Region: us-east-2
- Table name: MyTable
- Global Table Version: 2019.11.21
- The 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 a second region us-east-2 also does not help.
The boto3 documentation version 1.17.66 does not specify anything particular about the DynamoDB table version to which this operation applies. 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, how can I do this with boto3?