Class AWSDynamoUtils

java.lang.Object
com.erudika.para.server.persistence.AWSDynamoUtils

public final class AWSDynamoUtils extends Object
Helper utilities for connecting to AWS DynamoDB.
Author:
Alex Bogdanovski [[email protected]]
  • Method Details

    • getClient

      public static software.amazon.awssdk.services.dynamodb.DynamoDbClient getClient()
      Returns a client instance for AWS DynamoDB.
      Returns:
      a client that talks to DynamoDB
    • existsTable

      public static boolean existsTable(String appid)
      Checks if the main table exists in the database.
      Parameters:
      appid - name of the App
      Returns:
      true if the table exists
    • createTable

      public static boolean createTable(String appid)
      Creates a DynamoDB table.
      Parameters:
      appid - name of the App
      Returns:
      true if created
    • createTable

      public static boolean createTable(String appid, int maxReadCapacity, int maxWriteCapacity)
      Creates a table in AWS DynamoDB.
      Parameters:
      appid - name of the App
      maxReadCapacity - max read capacity for autoscaling (only applicable in PROVISIONED billing mode)
      maxWriteCapacity - max write capacity for autoscaling (only applicable in PROVISIONED billing mode)
      Returns:
      true if created
    • updateTable

      public static boolean updateTable(String appid, long readCapacity, long writeCapacity)
      Updates the table settings (read and write capacities).
      Parameters:
      appid - name of the App
      readCapacity - read capacity
      writeCapacity - write capacity
      Returns:
      true if updated
    • deleteTable

      public static boolean deleteTable(String appid)
      Deletes the main table from AWS DynamoDB.
      Parameters:
      appid - name of the App
      Returns:
      true if deleted
    • createSharedTable

      public static boolean createSharedTable(long readCapacity, long writeCapacity)
      Creates a table in AWS DynamoDB which will be shared between apps.
      Parameters:
      readCapacity - read capacity
      writeCapacity - write capacity
      Returns:
      true if created
    • getTableStatus

      public static Map<String,Object> getTableStatus(String appid)
      Gives basic information about a DynamoDB table (status, creation date, size).
      Parameters:
      appid - name of the App
      Returns:
      a map
    • listAllTables

      public static List<String> listAllTables()
      Lists all table names for this account.
      Returns:
      a list of DynamoDB tables
    • getTableNameForAppid

      public static String getTableNameForAppid(String appIdentifier)
      Returns the table name for a given app id. Table names are usually in the form 'prefix-appid'.
      Parameters:
      appIdentifier - app id
      Returns:
      the table name
    • getKeyForAppid

      public static String getKeyForAppid(String key, String appIdentifier)
      Returns the correct key for an object given the appid (table name).
      Parameters:
      key - a row id
      appIdentifier - appid
      Returns:
      the key
    • readPageFromTable

      public static <P extends ParaObject> List<P> readPageFromTable(String appid, Pager p)
      Reads a page from a standard DynamoDB table.
      Type Parameters:
      P - type of object
      Parameters:
      appid - the app identifier (name)
      p - a Pager
      Returns:
      the last row key of the page, or null.
    • readPageFromSharedTable

      public static <P extends ParaObject> List<P> readPageFromSharedTable(String appid, Pager pager)
      Reads a page from a "shared" DynamoDB table. Shared tables are tables that have global secondary indexes and can contain the objects of multiple apps.
      Type Parameters:
      P - type of object
      Parameters:
      appid - the app identifier (name)
      pager - a Pager
      Returns:
      the id of the last object on the page, or null.
    • deleteAllFromSharedTable

      public static void deleteAllFromSharedTable(String appid)
      Deletes all objects in a shared table, which belong to a given appid, by scanning the GSI.
      Parameters:
      appid - app id
    • getSharedGlobalIndex

      public static software.amazon.awssdk.services.dynamodb.model.GlobalSecondaryIndexDescription getSharedGlobalIndex()
      Returns the Index object for the shared table.
      Returns:
      the Index object or null
    • isSharedAppid

      public static boolean isSharedAppid(String appIdentifier)
      Returns true if appid starts with a space " ".
      Parameters:
      appIdentifier - appid
      Returns:
      true if appid starts with " "
    • getReplicaRegions

      public static List<String> getReplicaRegions()
      Returns the list of regions where a table should be replicated (global table).
      Returns:
      a list of regions