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

故事扮演 提交于 2019-12-03 07:45:25

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

Define tag in TAG variable and value in VALUE variable:

TAG=vpcname
VALUE=myvpc
aws ec2 describe-vpcs |\
jq -r ".Vpcs[] | select (.Tags[] | select(.Key==\"$TAG\") |\
select(.Value==\"$VALUE\"))"

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!