2014-11-25 72 views
2

這是What is the correct syntax for filtering by tag in describe-vpcs?的後續問題。更正aws cli語法以在非默認VPC中查找VPC安全組

使用提供的答案和參考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 

但是我得到一個錯誤

安全組 'MyVpcSecGroup' 不存在默認VPC 'vpc-bxxxxxx'

那麼如何格式化語法以在非默認VPC中使用--filters(如vpc-id)列表搜索安全組?

THX藝術

回答

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和名稱

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和特定的標籤

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

注:標記名稱和值區分大小寫

+0

感謝@約翰,我的問題是不明確的,所以我增加了一些信息,以最後一句。我希望通過基於標記進行過濾來獲取MyVpcSecGroup信息,例如vpc-id。這應該返回ifo特定VPC的特定組ID。 Thx Art – 2014-11-25 12:42:56

+0

已更新,其中包含通過Tag進行過濾的示例。 – 2014-11-25 23:44:48

+0

完美@約翰,添加組名稱作爲過濾器是我失蹤,藝術 – 2014-11-26 03:03:31

2

下面是我們如何做到這一點尋找一個特定的組時:

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

感謝您的輸入,給予引號+1,因爲在某些情況下名稱失敗,藝術 – 2014-11-26 03:02:01