Search code examples
javascriptamazon-web-servicesdynamodb-mapper

How to create a size condition using AWS dynamodb-mapper-js


I am trying to use the AWS Dynamodb Mapper library with Typescript to update an item in a table depending on the size of an array element (lets call it IDs) of the table.

An issue in the Github repo has been raised for this:

According to the dynamoDB documentation, there is a size operator that we can in a Condition Expression:

I haven't seen any trace of it in the package, is it supported ?

The issue has not been addressed (the DDB documentation cited is here).

I would like the condition to be something like size(IDs) > 12, but FunctionExpression doesn't seem to support this.

How can I use this mapper library to implement a size condition?


Solution

  • It looks like this is not possible using mapper, but it is possible to use the marshallConditionExpression function in mapper to create a serialized update condition, then manually append the size condition. This can then be used with the ddb client directly to update the item. So mapper doesn't support it, but supports hacking a solution together.