I am using DynamoDB locally with NoSQL Workbench and an Express API.
I have a table generated as such:
const params = {
AttributeDefinitions: [
{
AttributeName: 'id',
AttributeType: 'S',
},
],
KeySchema: [
{
AttributeName: 'id',
KeyType: 'HASH',
}
]
TableName: table.name,
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
},
}
dynamo.createTable(params).promise() // ... simplified version
I update an item using the DocumentClient as such:
const db = new AWS.DynamoDB.DocumentClient(configOptions);
const data = await db.put({
TableName,
Item,
}) // ... interact with result
Occasionally, it creates a new item in DynamoDB with the exact same id
value even though I created it as a HASH and made it the partition key.
However, it doesn't happen every time. I can't seem to recreate it consistently.
Is there something I'm doing wrong with how I'm creating this table or updating this item that is leading to this?
See items 97/98 here, this image is of my NoSQL Workbench and you can see there are two items with the same id
After getting in touch with AWS Support, it turns out this is a known issue with using DynamoDB locally. They provided the following guidance for fixing it:
As you mentioned that you are using the docker image for deploying DynamoDB local [1], please go ahead and remove the '-optimizeDbBeforeStartup' flag given in step 2 ('Docker tab') (and then save it as docker-compose.yml):
Removing '-optimizeDbBeforeStartup' from the argument list: ========== .. .. command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ./data" .. .. ==========
Create tables and insert item
docker-compose down
docker-compose up