Home > Mobile >  Update DynamoDB item with optional operation
Update DynamoDB item with optional operation

Time:08-04

Is the following operation implementable in DynamoDB:
On providing the key,

  • SET status as "active".
  • If the attribute additional_info starts_with "xyz"
    • Then REMOVE additional_info
    • Else do nothing to additional_info

Basically, an update where we override value of status regardless of additional_info. And optionally unset additional_info as an attribute if a condition is satisfied?

CodePudding user response:

It cannot be done in one call. It also can't be done in a single transaction wrapping the two calls into one, because a transaction can't repeatedly reference the same item.

If you can just make two calls, that's the way to go. If you need it to be somewhat transactional, you'll need to control things in your app. The details depend on your requirements.

  • Related