Reputation: 134
I have dynamodb table present in the aws account, I want to filter it based on the certain conditioning and get the result as an array
below is the aws cli query with jq
aws dynamodb scan --table-name sample-table | jq .Items | jq 'map(select(.VpcId.S != "None")) ' | jq .[].VpcId.S
here is the output which I am getting:
"vpc-yyyyyyyyyyyyyyyyy"
"vpc-zzzzzzzzzzzzzzzzz"
"vpc-XXXXXXXXXxxxxxxxx"
I want the output as
[
"vpc-yyyyyyyyyyyyyyyyy",
"vpc-zzzzzzzzzzzzzzzzz",
"vpc-XXXXXXXXXxxxxxxxx"
]
so that I can pass it to the terraform.
below is the output of the actual command
aws dynamodb scan --table-name sample-table
{
"Items": [
{
"VpcId": {
"S": "vpc-yyyyyyyyyyyyyyyyy"
}
},
{
"VpcId": {
"S": "None"
}
},
{
"VpcId": {
"S": "vpc-xxxxxxxxxxxxxxxxx"
}
},
}
]
}
Upvotes: 1
Views: 641
Reputation: 18921
Replace .[].VpcId.S
with map(.VpcId.S)
. The .[]
syntax takes the elements out of the array.
You can combine your different jq
filters together in this way:
.Items | map(select(.VpcId.S != "None") | .VpcId.S)
Upvotes: 4