AWS DynamoDB

Setting up DynamoDB in local for development

Use the downloadable version

  1. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html
  2. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html
  3. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.UsageNotes.html

The docker image did not work when I tried it.

As an alternative, I used the jar file.

  1. Download the jar file and use the command to start it
    java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb
    
  2. Testing
    aws dynamodb list-tables --endpoint-url http://localhost:8000
    

Amazon DynamoDB Documentation

  1. https://docs.amazonaws.cn/en_us/dynamodb/index.html
  2. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html

Access Pattern Strategies - https://dashbird.io/knowledge-base/dynamodb/access-pattern-strategies/

Best practices for designing and architecting with DynamoDB - https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/best-practices.html

Handling future changes to your DynamoDB access patterns - https://serverlessfirst.com/emails/handling-future-changes-to-your-dynamodb-access-patterns/

Advanced Design Patterns for Amazon DynamoDB - https://medium.com/@nabtechblog/advanced-design-patterns-for-amazon-dynamodb-c31d65d2e3de

Spring Data DynamoDB - https://boostchicken.github.io/spring-data-dynamodb/

Using Amazon DynamoDB with the AWS CLI - https://docs.aws.amazon.com/cli/latest/userguide/cli-services-dynamodb.html

How to tell if the table already exists in AWS?

  1. The CreateTable API throws a ResourceInUseException if the table already exists. Wrap the create_table method with try except to catch this
  2. You can use the ListTables API to get the list of table names associated with the current account and endpoint. Check if the table name is present in the list of table names you get in the response.
  3. The DescribeTable API will throw a ResourceNotFoundException if the table name you request doesn’t exist.

In java:

public boolean doesTableExist(String tableName) {
    try {
        TableDescription tableDescription = dynamoDB.getTable(tableName).describe();
        System.out.println('Table description: ' + tableDescription.getTableStatus());

        return true;
    } catch (com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException rnfe) {
        System.out.println("Table does not exist");
    }
    return false;
}

Links to this note