amazon-web-servicesamazon-dynamodbpartiql

Run AWS batch-execute-statement on the entire table in DynamoDB


I have a table in DynamoDB and I need to update all the items in it. Each item has a key and multiple columns with boolean values. It looks a bit like this:

Key BooleanOne BooleanTwo
key-one true true
key-two true false
key-three true false

I have many such items (too many to copy all the keys manually to make separate statements in a batch-execution-statement), but I can't find a way to iterate over all the items that should comply with the following condition in the WHERE clause: BooleanTwo = false.

How can I execute a batch-execute-statement that updates all the items which have BooleanTwo = false to BooleanTwo = true without having to manually enter all the keys in the table?

Normally I'd do something like this if the number of items was low:

[    
    {
        "Statement": "UPDATE MyTable SET BooleanTwo=true where Key=key-two"
    },
    {
        "Statement": "UPDATE MyTable SET BooleanTwo=true where Key=key-three"
    }
]

I'd like to do something like this instead:

"Statement": "UPDATE MyTable SET BooleanTwo=true where BooleanTwo=false"

How can I achieve this?


Solution

  • There is no way in DynamoDB to do a mass update by providing only a short declarative command specifying the criteria of the items to update.

    Given this schema you have, you'll need to do a scan with a filter and issue batch write calls. It doesn't have to be manual exactly (no human typing of the keys) but it will be a big loop. You can do a parallel scan to make it faster.