Reputation: 33
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?
Upvotes: 0
Views: 980
Reputation: 11
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)
Upvotes: 1