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?

John
asked 5 months ago140 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
profile picture
EXPERT
answered 5 months ago
profile picture
EXPERT
reviewed 5 months ago
profile picture
EXPERT
reviewed 5 months ago
0

Try this

sgs=("sg1" "sg2" "sg3")
aws ec2 describe-network-interfaces --filters "Name=group-id,Values=${sgs[*]}" --output json | jq .
profile picture
EXPERT
answered 5 months 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.

Guidelines for Answering Questions