更正aws cli语法以在非默认VPC中查找VPC安全组

art*_*lay 3 amazon-ec2 amazon-web-services amazon-vpc aws-cli

这是一个后续问题,在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.
Run Code Online (Sandbox Code Playgroud)

我构建了cli请求

aws --profile myProfile --region eu-west-1 ec2 describe-security-groups --group-name MyVpcSecGroup --filters Name=tag:vpc-id,Values=vpc-9xxxxxxx
Run Code Online (Sandbox Code Playgroud)

但是我收到了一个错误

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

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

thx艺术

Joh*_*ein 6

文件说:

   --group-names (list)
      [EC2-Classic, default VPC] One or more security group names.
Run Code Online (Sandbox Code Playgroud)

因此,它似乎--group-names不能用于非默认的VPC.

但是,还有其他方法:

aws ec2 describe-security-groups --group-ids sg-xxxxxxxx
aws ec2 describe-security-groups --filters Name=group-name,Values=MyVpcSecGroup
Run Code Online (Sandbox Code Playgroud)

要根据特定的VPC和名称进行过滤:

aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-11223344 Name=group-name,Values=MyVpcSecGroup
Run Code Online (Sandbox Code Playgroud)

要根据特定的VPC和任何标记进行过滤:

aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-11223344 Name=tag-value,Values=Production
Run Code Online (Sandbox Code Playgroud)

要根据特定的VPC和特定标记进行过滤:

aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-11223344 Name=tag:Environment,Values=Production
Run Code Online (Sandbox Code Playgroud)

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