createGlobalTable method

Future<CreateGlobalTableOutput> createGlobalTable({
  1. required String globalTableName,
  2. required List<Replica> replicationGroup,
})

Creates a global table from an existing table. A global table creates a replication relationship between two or more DynamoDB tables with the same table name in the provided Regions.

To determine which version you're using, see Determining the global table version you are using. To update existing global tables from version 2017.11.29 (Legacy) to version 2019.11.21 (Current), see Upgrading global tables. If you want to add a new replica table to a global table, each of the following conditions must be true:

  • The table must have the same primary key as all of the other replicas.
  • The table must have the same name as all of the other replicas.
  • The table must have DynamoDB Streams enabled, with the stream containing both the new and the old images of the item.
  • None of the replica tables in the global table can contain any data.
If global secondary indexes are specified, then the following conditions must also be met:
  • The global secondary indexes must have the same name.
  • The global secondary indexes must have the same hash key and sort key (if present).
If local secondary indexes are specified, then the following conditions must also be met:
  • The local secondary indexes must have the same name.
  • The local secondary indexes must have the same hash key and sort key (if present).

Implementation

Future<CreateGlobalTableOutput> createGlobalTable({
  required String globalTableName,
  required List<Replica> replicationGroup,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.0',
    'X-Amz-Target': 'DynamoDB_20120810.CreateGlobalTable'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'GlobalTableName': globalTableName,
      'ReplicationGroup': replicationGroup,
    },
  );

  return CreateGlobalTableOutput.fromJson(jsonResponse.body);
}