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 21 days ago84 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 21 days ago
profile picture
EXPERT
reviewed 18 days ago
profile picture
EXPERT
reviewed 21 days 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 21 days 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