use of software.amazon.awssdk.services.dynamodb.model.ReplicaUpdate in project para by Erudika.
the class AWSDynamoUtils method deleteTable.
/**
* Deletes the main table from AWS DynamoDB.
* @param appid name of the {@link com.erudika.para.core.App}
* @return true if deleted
*/
public static boolean deleteTable(String appid) {
if (StringUtils.isBlank(appid) || !existsTable(appid)) {
return false;
}
try {
String table = getTableNameForAppid(appid);
if (!getReplicaRegions().isEmpty() && !App.isRoot(appid)) {
List<ReplicaUpdate> replicaUpdates = new LinkedList<>();
getReplicaRegions().stream().forEach(region -> {
logger.info("Removing replica from global table '{}' in region {}...", table, region);
replicaUpdates.add(ReplicaUpdate.builder().delete(d -> d.regionName(region)).build());
});
try {
// this only removes the replicas for each region - it DOES NOT delete the actual replica tables
getClient().updateGlobalTable(b -> b.globalTableName(table).replicaUpdates(replicaUpdates));
getReplicaRegions().stream().forEach(region -> {
DynamoDbAsyncClient asyncdb = DynamoDbAsyncClient.builder().region(Region.of(region)).build();
asyncdb.deleteTable(b -> b.tableName(table));
logger.info("Deleted DynamoDB table '{}' in region {}.", table, region);
});
} catch (Exception ex) {
logger.error(null, ex);
}
} else {
getClient().deleteTable(b -> b.tableName(table));
logger.info("Deleted DynamoDB table '{}'.", table);
}
} catch (Exception e) {
logger.error(null, e);
return false;
}
return true;
}
Aggregations