Is it possible to use the --query option of the AWS CLI (described here) to filter a 1 dimensional array? All the examples I can find on the AWS site work great for maps -- but I couldn't figure out the syntax for a simple array.
Consider the dynamodb list-tables command which has a string array in the output:
aws dynamodb list-tables
Sample Output:
{
"TableNames": [
"Questions",
"Answers",
"Votes"
]
}
Let's say I want to figure out if TableNames contains "Answers". Syntax I've tried that's invalid or doesn't work.
aws dynamodb list-tables --query 'TableNames[?==`Answers`]'
aws dynamodb list-tables --query 'TableNames[?.==`Answers`]'
aws dynamodb list-tables --query '[?TableNames[*]==`Answers`]'
To refer to the current element in an array, you can use the @
character:
$ aws dynamodb list-tables --query "TableNames[? @ == 'Answers' ]"
[
"Answers"
]
If you just need a true/false answer of "does this table name exist in the list of tables" you can also use:
$ aws dynamodb list-tables --query "contains(TableNames, 'Answers')"
true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With