纠正AWS CLI语法找到找到一个VPC安全组在非默认VPC语法、安全、AWS、CLI

2023-09-12 23:36:34 作者:青春、是一道明媚的伤

这是从What在描述-VPCS的正确语法筛选按标签?。

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

Using the answer provided and referencing 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的请求

I have constructed the cli request

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

不过,我得到一个错误

however I get an error

安全组MyVpcSecGroup在默认情况下不存在VPC   'VPC-bxxxxxx

The security group 'MyVpcSecGroup' does not exist in default VPC 'vpc-bxxxxxx'

那么,如何格式化用--filters如VPC-ID的列表来搜索安全组在非默认VPC语法?

So how do I format the syntax to search for a security group in a non default VPC using a list of --filters such as vpc-id?

THX艺术

推荐答案

该文件说:

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

因此​​,它似乎是 - 组名不能在非默认VPC使用

So, it would seem that --group-names cannot be used on a non-default VPC.

但是,也有替代方法:

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

要基于特定的 VPC和名称过滤器:

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

要筛选基于一个特定的 VPC以及任何标签

To filter based on a specific VPC and any Tag:

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

要筛选基于一个特定的 VPC和一个特定的标签

To filter based on a specific VPC and a specific Tag:

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

请注意:标签名称和值是区分大小写

Note: Tag names and values are case-sensitive.