1

Currently my dynamodb has a key is batch_id and then a list 'doc_info_list'. I would like to add to the list with below code.

But it is showing an exception

com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: ExpressionAttributeValues contains invalid value: One or more parameter values were invalid: An AttributeValue may not contain an empty string for key :val1 (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: ValidationException; Request ID: 03LRKK3J3SBVFNGMKV36NVSQBJVV4KQNSO5AEMVJF66Q9ASUAAJG)

Code:

AmazonDynamoDB amazonDynamoDBClient = AmazonDynamoDBClientBuilder.defaultClient();
        DynamoDB dynamoDB = new DynamoDB(amazonDynamoDBClient);
        Table table = dynamoDB.getTable("XXXX");

        String currentDateTime = MiscHelper.getDateTimeAsISO8601();

        Map<String, Object> map = objectMapper.convertValue(doc, Map.class);

        ValueMap valueMap = new ValueMap().withList(":val1", Arrays.asList(map));
        valueMap.withList(":empty_list", new ArrayList<>());
        valueMap.withString(":val2", currentDateTime);
        UpdateItemSpec updateItemSpec = new UpdateItemSpec().withPrimaryKey("batch_id", batchId)
                .withUpdateExpression("set doc_info_list = list_append(if_not_exists(doc_info_list, :empty_list), :val1), created_date_time = :val2, updated_date_time = :val2")
                .withValueMap(valueMap)
                .withReturnValues(ReturnValue.UPDATED_NEW);

What am I doing wrong here?

2
  • What's a doc? Is this a DynamoDb entity object? Commented Mar 30, 2019 at 9:35
  • Doc is a normal pojo object. Commented Mar 30, 2019 at 9:37

1 Answer 1

1

So, you're trying to save doc into dynamodb through a Map representation. The only problem I might guess is that some of your doc fields are an empty String and then you're trying to save it as Dynamo's AttributeValue and this is not allowed: https://forums.aws.amazon.com/thread.jspa?threadID=90137

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

5 Comments

You are totally right. I have a field which contains a blank data. My bad I did not find it out. Thank again.
By the way, is my implementation is a good approach. Could we use DynamoDBMapper with Entity (using Annotation) for this use case?
I don't see why not. With a mapper you could at least skip the map transformation.
do you have an example I can refer which using list_append & DynamoDBMapper
I mean you could leave most of your code as is, just skip the objectMapper.convertValue(doc, Map.class). As to if SDK with mapper can take care of the more complex queries like the one you have - I don't think so. But you can open another question, maybe someone will know for sure. :)

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.