Skip to content

Trouble passing array to AWS CLI filter

0

Running the command:

$sgs = @("sg1", "sg2", "sg3")
aws ec2 describe-network-interfaces --filters Name=group-id,Values=$sgs --output json | ConvertFrom-Json

https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-network-interfaces.html

But the CLI doesn't filter by the security group ids. Any help?

asked 2 years ago290 views
2 Answers
1
Accepted Answer

Hello.

I assume you are probably using PowerShell since you are using "ConvertFrom-Json".
So please try as follows.

$sgs = @("sg1", "sg2", "sg3")
aws ec2 describe-network-interfaces --filters Name=group-id,Values=$($sgs -join ',') --output json | ConvertFrom-Json
EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
EXPERT
reviewed 2 years ago
0

Try this

sgs=("sg1" "sg2" "sg3")
aws ec2 describe-network-interfaces --filters "Name=group-id,Values=${sgs[*]}" --output json | jq .
EXPERT
answered 2 years ago
  • This is invalid powershell, see how you were trying to interpolate the array in a string.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.