2

I am trying to query the output of an AWS cli command using an environment variable as the query string. This works fine for me using the AWS Cli in Linux but in Powershell I am having trouble getting the Cli to use the variable in Powershell.

For example - thsi works for me in Linux:

SECGRP="RDP from Home"
aws ec2 describe-security-groups --query \
'SecurityGroups[?GroupName==`'"$SECGRP"'`].GroupId' --output text

If i run this in Powershell:

$SECGRP="RDP from Home"
aws ec2 describe-security-groups --query \
'SecurityGroups[?GroupName==`'"$SECGRP"'`].GroupId' --output text

Error Details:

Bad value for --query SecurityGroups[?GroupName==`: Bad jmespath 
expression: Unclosed ` delimiter:
SecurityGroups[?GroupName==`
                       ^

I have tried a few combinations of quotes inisde the query expression but either get errors or no output.

I have also run the following to demonstrate i can get the correct output using Powershell (but not using a variable):

aws ec2 describe-security-groups --query \
'SecurityGroups[?GroupName==`RDP from Home`].GroupId' --output text

1 Answer 1

3

Try this:

$SECGRP="RDP from Home"
aws ec2 describe-security-groups --query "SecurityGroups[?GroupName=='$SECGRP'].GroupId" --output text
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your response.

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.