user886827
user886827

Reputation: 101

Dynamo DB : Deleting entries within a table with HashKey + Range

I have DynamoDB table with Hashkey + RangeKey. I am facing the following error while deleting an entry for a given HashKey and RangeKey.

Tried following approaches

  1. Used a DynamoDBMapper to get the record (Obj) from DB using DynamoDBQueryExpression that includes both HashKey + RangeKey in KeyCondition. Performed dynamoDBMapper.delete(Obj).
  2. Referred to other post - DynamoDb: Delete all items having same Hash Key and tried
HashMap<String, AttributeValue> eav = new HashMap<String, AttributeValue>();
eav.put(":v1", new AttributeValue().withS(value));
DynamoDBQueryExpression<DocumentTable> queryExpression = new DynamoDBQueryExpression<DocumentTable>()
            .withKeyConditionExpression("documentId = :v1")
            .withExpressionAttributeValues(eav);
List<DocumentTable> ddbResults = dynamoDBMapper.query(DocumentTable.class, queryExpression);
dynamoDBMapper.batchDelete(ddbResults);

In both the above cases I see the following exception

com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: The provided key element does not match the schema (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: I12MUB0FSQNAQT6AH0RHE1B12JVV4KQNSO5AEMVJF66Q9ASUAAJG)

Upvotes: 1

Views: 432

Answers (1)

Joey Kilpatrick
Joey Kilpatrick

Reputation: 1602

You tried to specify an item by giving a value for the key documentId. The error is trying to tell you that documentId isn't the name of the key in your table.

Replace documentId with the name of the key in you table.

Upvotes: 0

Related Questions