Reputation: 843
When I am running a DeleteItemRequest on a dynamoDB table, I am getting an exception which says "the provided key size doesn't match with that of the schema". All I am doing is
DeleteItemRequest deleteRequest = new
DeleteItemRequest().withTableName(dynamoDbTableName).withKey(key);
client.deleteItem(deleteRequest);
Do I need to specify something more? Am I missing something?
Upvotes: 2
Views: 2981
Reputation: 22451
It could mean that the key passed to the method does not match the type of the primary key in the table. For example, you are passing a numerical key but the table uses a string key. The type of the key depends on the method used when creating the AttributeValue. The method withN()
creates a numerical key, while the method .withS()
creates a string key.
Numerical key example:
Key key = new Key().withHashKeyElement(new AttributeValue().withN("120"));
String key example:
Key key = new Key().withHashKeyElement(new AttributeValue().withS("johndoe"));
There are methods for other types as well, like binary types and sets. See the javadoc for the AttributeValue class for more details.
Upvotes: 2