0

I am just trying out to see if it's valid to use AWS cli commands using subprocess module. Running the below command gives the successful output

vpc = subprocess.run("aws ec2 describe-vpcs | jq -r '.Vpcs[].VpcId'", stdout=subprocess.PIPE, shell=True)

While running the with select statement in jq shown as below gives an error.

subnets = subprocess.run("aws ec2 describe-subnets | jq -r '.Subnets[] | select(.Tags[].Value == "az1") .SubnetId'", stdout=subprocess.PIPE, shell=True)

error as

File "awsinit.py", line 42
    subnets = subprocess.run("aws ec2 describe-subnets | jq -r '.Subnets[] | select(.Tags[].Value == "az1") .SubnetId'", stdout=subprocess.PIPE, shell=True)
                                                                                                      ^
SyntaxError: invalid syntax

Any guide on fixing this or any other suggestion on this?

1 Answer 1

1

Fixing the quotation marks will help you solve the problem

subnets = subprocess.run('''aws ec2 describe-subnets | jq -r '.Subnets[] | select(.Tags[].Value == "az1") .SubnetId' ''', stdout=subprocess.PIPE, shell=True)
Sign up to request clarification or add additional context in comments.

1 Comment

do you know how I can include variables inside the command?

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.