首页 文章

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

提问于
浏览
2

这是What is the correct syntax for filtering by tag in 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中搜索安全组?

thx艺术

2 回答

  • 2

    以下是我们在寻找特定群体时如何做到这一点:

    aws --profile myProfile ec2 describe-security-groups --region=AWS_REGION --filters "Name=vpc-id,Values=VPC_ID" --filters "Name=group-name,Values=NAMEOFSECGROUP"
    
  • 5

    文件说:

    --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 and Name 过滤:

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

    要根据特定的 VPC and any Tag 过滤:

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

    要根据特定的 VPC and a specific Tag 过滤:

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

    注意:标记名称和值为 case-sensitive .

相关问题