4

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

使用提供的答案并参考http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-security-groups.html

--filters (list)
One or more filters.
......
vpc-id - The ID of the VPC specified when the security group was created.

我已经构建了 cli 请求

aws --profile myProfile --region eu-west-1 ec2 describe-security-groups --group-name MyVpcSecGroup --filters Name=tag:vpc-id,Values=vpc-9xxxxxxx

但是我收到一个错误

默认 VPC 'vpc-bxxxxxx' 中不存在安全组 'MyVpcSecGroup'

那么如何格式化语法以使用 --filters 列表(例如 vpc-id)在非默认 VPC 中搜索安全组?

谢谢艺术

4

2 回答 2

7

文档说:

   --group-names (list)
      [EC2-Classic, default VPC] One or more security group names.

因此,似乎--group-names不能在非默认 VPC 上使用。

但是,还有其他方法:

aws ec2 describe-security-groups --group-ids sg-xxxxxxxx
aws ec2 describe-security-groups --filters Name=group-name,Values=MyVpcSecGroup

根据特定VPC 和 Name进行过滤:

aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-11223344 Name=group-name,Values=MyVpcSecGroup

要基于特定VPC 和任何标签进行过滤:

aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-11223344 Name=tag-value,Values=Production

要基于特定VPC 和特定 Tag进行过滤:

aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-11223344 Name=tag:Environment,Values=Production

注意:标记名称和值区分大小写

于 2014-11-25T10:46:56.390 回答
2

以下是我们在寻找特定组时的做法:

aws --profile myProfile ec2 describe-security-groups --region=AWS_REGION --filters "Name=vpc-id,Values=VPC_ID" --filters "Name=group-name,Values=NAMEOFSECGROUP"
于 2014-11-25T23:25:39.007 回答