javaamazon-web-servicesamazon-dynamodbaws-sdk-java-2.0

Why do I get Unable to unmarshall exception response using the AWS SDK for Java?


I have a Java 17 project, which interacts with DynamoDB Local and configures and deploys it while running tests.

Here is some of the code I have in my test:

var mapper = new DynamoDBMapper(amazonDynamoDB);
Map<String, AttributeValue> attributes = new HashMap<>();
attributes.put(":test", new AttributeValue().withS("tomato"));

var query = " ( contains(value, :test)) ";


mapper.batchSave(Arrays.asList(
        DynamoTestModel.builder().value("mango").build(),
        DynamoTestModel.builder().value("avocado").build(),
        DynamoTestModel.builder().value("other fruit").build(),
        DynamoTestModel.builder().value("other other fruit").build(),
        DynamoTestModel.builder().value("jack fruit").build(),
        DynamoTestModel.builder().value("tomato").build()
));

var scanResult = mapperscanPage(DynamoTestModel.class, new DynamoDBScanExpression()
        .withFilterExpression(query)
        .withExpressionAttributeValues(attributes));


Assertions.assertEquals(1, scanResult.getCount());
Assertions.assertEquals("tomato", scanResult.getResults().get(0).getValue());

The above produces this error:

Unable to unmarshall exception response with the unmarshallers provided (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 0AS59VHPQ7IO0OIEQI4J9PEQIRVV4KQNSO5AEMVJF66Q9ASUAAJG; Proxy: null) com.amazonaws.AmazonServiceException: Unable to unmarshall exception response with the unmarshallers provided (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 0AS59VHPQ7IO0OIEQI4J9PEQIRVV4KQNSO5AEMVJF66Q9ASUAAJG; Proxy: null)

What's the issue?


Solution

  • This is not an issue with DynamoDB Local.

    Unable to unmarshall exception response with the unmarshallers provided

    The first part of your exception is just an issue with your setup, which I explain in detail here.

    Error Code: ValidationException

    This is the real issue. ValidationException is usually related to a syntax which is not correct.

    var query = " ( contains(value, :test)) ";
    

    What is value here? It should be an attribute name. value is a reserved keyword in DynamoDB, if your attribute name is called value then you should use ExpressionAttributeNames.

    And if you are not using a reserved keyword and value is not the name of your attribute, you can simply do it like this:

    var query = "contains(myAttributeName, :test)";
    

    And one final note is that you are being returned a RequestId in the stack trace which means you are not hitting DynamoDB Local but the web service.