I am trying to understand a aws ec2 cli call. I am looking to describe all VPC then filer on a custom tag (vpcname=myvpc, however after trying multiple combinations I keep getting conflicting errors about the format and use of --filters. using as a reference [http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-vpcs.html][1]
aws --profile myProfile --region eu-west-1 ec2 describe-vpcs --filters vpcname,myvpc
however this returns
Error parsing parameter '--filters': should be: Key value pairs, where values are separated by commas, and multiple pairs are separated by spaces.
--filters Name=string1,Values=string1,string2 Name=string1,Values=string1,string2
so trying
aws --profile myProfile --region eu-west-1 ec2 describe-vpcs --filters Name=vpcname,Values=myvpc
and it returns
A client error (InvalidParameterValue) occurred when calling the DescribeVpcs operation: The filter 'vpcname' is invalid
so trying a few other combinations
aws --profile myProfile --region eu-west-1 ec2 describe-vpcs --filters tag :Name=vpcname,Values=myvpc
Error parsing parameter '--filters': should be: Key value pairs, where values are separated by commas, and multiple pairs are separated by spaces.
--filters Name=string1,Values=string1,string2 Name=string1,Values=string1,string2
Any advice on how I format this request?
Define tag in TAG variable and value in VALUE variable:
You got pretty close to solving it -- the only problem is that you are not specifying a valid filter for describe-vpcs. Here's the filter that would be relevant to your use case:
So when it is asking for
Name=string1,Values=string1...
, it expects:Try this instead, works for me locally with a different custom tag:
If you are trying to do the same thing using the Ansible AWS *_facts calls you have the same kind of issue. In Ansible the correct syntax is:
ec2_vpc_net_facts: filters: "tag:vpcname": "myvpc"
I only mention this here because this SO question came up in most of my google searches when trying to get the Ansible right and I had been using the AWS cli example above in Ansible because I couldn't get the filter right.