Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there conditions under which DynamoDB allows for a duplicate primary key?

While performing an updateItem operation to a dynamo table using the AWS Javascript SDK, I am instead seeing a second row written with the same primary key, which certainly seems contrary to the documentation.

I am using a hash string key "user_id".

The initial write:

var params = {
  Item: {
    user_id : {S: "foo"},
    is_authorized: {BOOL: false},
  },
  TableName: 'MyTable'
};
db.putItem(params, function(err, data){
  if(err){
    console.log(err);
  }else{
    console.log(data);
  }
});

The Update Attempt

var updateParams = {
  Key: {
    user_id : {S: "foo"},
  },
  AttributeUpdates: {
    confirmationCode: {Action: "PUT", Value: {S: "key"}},
    phone: {Action: 'PUT', Value: {S: "1234567}},
    is_authorized: {Action: 'PUT', Value: {BOOL: false}},
    confirmAttempts: {Action: 'PUT', Value: {N: "1"}}
  },
  TableName: 'MyTable'
};

db.updateItem(params, function(err, data){
  if(err){
    response = err;
    console.log("The error was: " + err);
  }else{
    response = data;
    console.log(data);
  }
});
like image 740
Thomas Murphy Avatar asked Sep 03 '25 04:09

Thomas Murphy


1 Answers

For reference to others who might come across this issue:

This issue was caused by whitespace, specifically a trailing space at the end of some primary key strings. Viewing Dynamo records, at least from within the console, does not convert whitespace characters, so it was an invisible issue.

like image 166
Thomas Murphy Avatar answered Sep 07 '25 04:09

Thomas Murphy