How to transfer dynamodb data to change the main table?

Structures and requirements change during the development process. It is necessary to change the key and index parameters, which may violate the incremental update of the table. So my solution so far is to delete the table and recreate it from the cloudformation package.

But how to solve this problem with production deployment? Is it possible to automate the deployment of dynamodb as follows?

  • Create a new table
  • Transfer data from an old table to a new table
  • Delete old table
+4
source share
1 answer

, ​​ . , , , , - . , , .

, - , Java.

Java- , , dynamo:

 /**
 * Creates a single table with its appropriate configuration (CreateTableRequest)
 */
public void createTable(Class tableClass) {
    DynamoDBMapper mapper = createMapper(); // you'll need your own function to do this.

    ProvisionedThroughput pt = new ProvisionedThroughput(1L, 1L);
    CreateTableRequest ctr = mapper.generateCreateTableRequest(tableClass);
    ctr.withProvisionedThroughput(new ProvisionedThroughput(1L, 1L));

    // Provision throughput and configure projection for secondary indices.
    if (ctr.getGlobalSecondaryIndexes() != null) {
        for (GlobalSecondaryIndex idx : ctr.getGlobalSecondaryIndexes()) {
            if (idx != null) {
                idx.withProvisionedThroughput(pt).withProjection(new Projection().withProjectionType("ALL"));
            }
        }
    }

    TableUtils.createTableIfNotExists(client, ctr);
}

Java- :

private static void deleteTable(String tableName) {
    AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().build();
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.getTable(tableName);
    try {
        System.out.println("Issuing DeleteTable request for " + tableName);
        table.delete();
        System.out.println("Waiting for " + tableName + " to be deleted...this may take a while...");
        table.waitForDelete();

    }
    catch (Exception e) {
        System.err.println("DeleteTable request failed for " + tableName);
        System.err.println(e.getMessage());
    }
}

, , , , , , , , . , , , , .

+2

Source: https://habr.com/ru/post/1676318/


All Articles