akka-persistence-dynamodb icon indicating copy to clipboard operation
akka-persistence-dynamodb copied to clipboard

JSON to create table

Open calvinlfer opened this issue 9 years ago • 3 comments

Hello Akka team,

Just a suggestion. Would you consider including the JSON that is needed to create the table for the event journal in the documentation?

I know you have tests that do this but it would be nice to have something in the documentation. When I was testing this out using local DynamoDB, I used the local shell and executed the createTable function using the JavaScript AWS SDK

dynamodb.describeTable(params, function(err, data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});

var params = {
    TableName: 'test-journal',
    KeySchema: [ 
        // The type of of schema.  Must start with a HASH type, with an optional second RANGE.
        { // Required HASH type attribute
            AttributeName: 'par',
            KeyType: 'HASH',
        },
        { // Optional RANGE key type for HASH + RANGE tables
            AttributeName: 'num', 
            KeyType: 'RANGE', 
        }
    ],
    AttributeDefinitions: [ // The names and types of all primary and index key attributes only
        {
            AttributeName: 'par',
            AttributeType: 'S', // (S | N | B) for string, number, binary
        },
        {
            AttributeName: 'num',
            AttributeType: 'N', // (S | N | B) for string, number, binary
        }
    ],
    ProvisionedThroughput: { // required provisioned throughput for the table
        ReadCapacityUnits: 10000, 
        WriteCapacityUnits: 10000, 
    }
};

dynamodb.createTable(params, function(err, data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});

Thanks a lot Cal

calvinlfer avatar Feb 20 '16 01:02 calvinlfer

Something like this would suit the README better :

aws --endpoint-url=http://localhost:8000 dynamodb create-table \
    --table-name akka-persistence \
    --attribute-definitions \
        AttributeName=par,AttributeType=S \
        AttributeName=num,AttributeType=N \
    --key-schema AttributeName=par,KeyType=HASH AttributeName=num,KeyType=RANGE \
    --provisioned-throughput ReadCapacityUnits=1000,WriteCapacityUnits=1000

However even if I do that :

{
    "TableDescription": {
        "TableSizeBytes": 0,
        "KeySchema": [
            {
                "KeyType": "HASH",
                "AttributeName": "par"
            },
            {
                "KeyType": "RANGE",
                "AttributeName": "num"
            }
        ],
        "TableArn": "arn:aws:dynamodb:ddblocal:000000000000:table/akka-persistence",
        "AttributeDefinitions": [
            {
                "AttributeType": "S",
                "AttributeName": "par"
            },
            {
                "AttributeType": "N",
                "AttributeName": "num"
            }
        ],
        "ProvisionedThroughput": {
            "LastIncreaseDateTime": 0.0,
            "ReadCapacityUnits": 1000,
            "LastDecreaseDateTime": 0.0,
            "WriteCapacityUnits": 1000,
            "NumberOfDecreasesToday": 0
        },
        "ItemCount": 0,
        "TableName": "akka-persistence",
        "TableStatus": "ACTIVE",
        "CreationDateTime": 1507151061.035
    }
}

I get this error :

[ERROR] [10/04/2017 21:06:10.711] [pool-1-thread-1] [DynamoDBClient(akka://example)] failure while executing DescribeTableRequest(akka-persistence)
com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException: Cannot do operations on a non-existent table (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: f1ff5cf0-52f4-4044-b4b9-74ff6ac7f8ef)

I'm connecting with this configuration :

    """
        akka {
          persistence.journal.plugin = "my-dynamodb-journal"
        }
        my-dynamodb-journal = ${dynamodb-journal}
        my-dynamodb-journal {
          endpoint =  "http://dynamo:8000"
        }
        """.stripMargin

Any idea what is wrong here?

aws --endpoint-url=http://localhost:8000 dynamodb describe-table --table-name=akka-persistence

works...

l15k4 avatar Oct 04 '17 21:10 l15k4

Resolved, I had to run the Local DynamoDB with -sharedDb flag, uff :-)

l15k4 avatar Oct 04 '17 21:10 l15k4

I can change the setup to rely on the localstack dynamo db with a setup container for the ddb, which will do exactly this.

teroxik avatar Feb 03 '20 20:02 teroxik