首页 文章

在describe-vpcs中按标签过滤的正确语法是什么?

提问于
浏览
5

我想了解一个aws ec2 cli电话 . 我想在自定义标签上描述所有VPC然后文件管理器(vpcname = myvpc,但是在尝试多种组合后,我不断得到关于格式和使用--filters的冲突错误 . 使用作为参考[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

然而这又回来了

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

这么努力

aws --profile myProfile --region eu-west-1 ec2 describe-vpcs --filters Name = vpcname,Values = myvpc

然后它回来了

A client error (InvalidParameterValue) occurred when calling the DescribeVpcs operation: The filter 'vpcname' is invalid

所以尝试其他一些组合

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

关于如何格式化此请求的任何建议?

3 回答

  • 0

    你已经非常接近解决它 - 唯一的问题是你没有指定valid filter for describe-vpcs . 这是与您的用例相关的过滤器:

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

    因此,当它要求 Name=string1,Values=string1... 时,它预计:

    • Name = tag:TagName

    • Values = TagValue

    试试这个,在我的本地使用不同的自定义标签:

    aws ec2 describe-vpcs --filters Name=tag:vpcname,Values=myvpc
    
  • 0

    在TAG变量中定义标记,在VALUE变量中定义值:

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

    如果您尝试使用Ansible AWS * _facts调用执行相同的操作,则会遇到同样的问题 . 在Ansible中,正确的语法是:

    ec2_vpc_net_facts: filters: "tag:vpcname": "myvpc"

    我在这里只提到这一点,因为在我尝试使Ansible正确的时候,我的大部分谷歌搜索出现了这个问题,而且我在Ansible中使用了上面的AWS cli示例,因为我无法正确使用过滤器 .

相关问题