Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the correct syntax for filtering by tag in describe-vpcs?

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?

like image 332
art vanderlay Avatar asked Nov 21 '14 09:11

art vanderlay


People also ask

Which PowerShell cmdlet is used to tag an existing VPC?

EC2: New-EC2Tag Cmdlet | AWS Tools for PowerShell.

How do I find my VPC ID?

To find a VPC ID, you can use either the AMS console or API/CLI. AMS Console: In the navigation pane, select VPCs and the relevant VPC. The VPC details page for the selected VPC opens with information including the VPC ID.

How do I list all resources in a VPC?

You can use AWS CLI to list all ENIs associated with the VPC and prettify the output using the --query parameter to get a resource list with the desired fields (AZ, instance-id, etc.).

What is VPC ID in AWS?

A virtual private cloud (VPC) is a virtual network dedicated to your AWS account. It is logically isolated from other virtual networks in the AWS Cloud. You can specify an IP address range for the VPC, add subnets, add gateways, and associate security groups. A subnet is a range of IP addresses in your VPC.


1 Answers

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:

tag:key=*value* - The key/value combination of a tag assigned to the resource.

So when it is asking for Name=string1,Values=string1..., it expects:

  • Name=tag:TagName
  • Values=TagValue

Try this instead, works for me locally with a different custom tag:

aws ec2 describe-vpcs --filters Name=tag:vpcname,Values=myvpc
like image 147
Anthony Neace Avatar answered Sep 22 '22 20:09

Anthony Neace