3
votes

So I'm running a scan of a DynamoDB table with ~500 records using the AWS CLI through Powershell, because the AWS Powershell Tools don't support DDB query/scan operations. I can run the command with no filters and get all my items:

& aws dynamodb scan --table-name "$table_name" --projection-expression "$item_key"

This returns all 500+ values of $item_key.

Problem comes when I try to filter the scan:

& aws dynamodb scan --table-name "$table_name" --projection-expression "$item_key" --filter-expression "item_key_2 = `"$item_value`""

This returns a count of 0 and no items, even though there are several values in the table that match $item_value.

What am I missing/doing wrong here?

1
What is item_key_2? Is it a variable, or name of a field? aws doco is not very helpful. It may be easier store your results in a Psobject and filter in PowerShell.Jan Chrbolka
I wound up just doing a full table scan and filtering in Powershell. I found the native DynamoDB filtering as described by David too clunky to work with. Plus, it doesn't save much time since a filtered scan retrieves all rows before filtering anyway.DataBeast

1 Answers

2
votes

Let's assume $item_value here expands to foobar. What that filter expression is looking for is items whose item_key_2 and foobar attributes have the same value:

{
  "item_key": "...",
  "item_key_2": "It's a match!",
  "foobar": "It's a match!"
}

To compare item_key_2 against a literal value, you need to do:

aws dynamodb scan \
    --table-name "$table_name" \
    --filter-expression "item_key_2 = :value" \
    --expression-attribute-values "{`":value`":{`"S`":`"$item_value`"}}"

:(