1

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"
    }
  },
  }
]
}

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.