0

I am executing this code from my Elastic beanstalk instance. In Dynamodb, I have a table with hash and range key. I need to find all rows that matches my hash key. I don't want to specify the range. Similar query on that table works fine on AWS Console. I followed this help.

DynamoDB db = new DynamoDB(new AmazonDynamoDBClient(new ProfileCredentialsProvider()));
KeyAttribute key = new KeyAttribute("ID", new AttributeValue().withS("123"));
QuerySpec querySpec = new QuerySpec().withHashKey(key);
Table table = db.getTable("USER_TABLE");
ItemCollection<QueryOutcome> items = null;
try
{
            items = table.query(querySpec);
}
catch (Exception e)
{
            log.severe(String.format("table.query exception " + e.getMessage()));
}

The table.query call is throwing an Exception: "value type: class com.amazonaws.services.dynamodbv2.model.AttributeValue"

I don't see any reason for the exception and I am stuck. I posted the same question on AWS forum but no answer in there yet - any help is much appreciated.

1 Answer 1

1

The problem is with this line:

KeyAttribute key = new KeyAttribute("ID", new AttributeValue().withS("123"));

KeyAttribute doesn't require AttributeValue but rather an Object that represents the value itself so in your case you should create the KeyAttribute like this:

KeyAttribute key = new KeyAttribute("ID", "123");

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Chen - yes, that was the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.