

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Amazon EC2：允許以程式設計方式和在主控台中管理具備特定標籤鍵值對的 EC2 安全群組
<a name="reference_policies_examples_ec2_securitygroups-vpc"></a>

此範例顯示如何建立身分型政策，授予使用者對具有相同標籤的安全群組採取特定動作的許可。此政策會授予許可以在 Amazon EC2 主控台中檢視安全群組，並針對具有 `Department=Test` 標籤的現有安全群組新增和移除傳入與傳出規則，以及列出和修改規則說明。此政策定義了程式設計和主控台存取的許可。若要使用此政策，請將範例政策中的*斜體預留位置文字*取代為您自己的資訊。然後，遵循[建立政策](access_policies_create.md)或[編輯政策](access_policies_manage-edit.md)中的指示進行操作。

------
#### [ JSON ]

****  

```
{
   "Version":"2012-10-17",		 	 	 
   "Statement": [{
      "Effect": "Allow",
      "Action": [
         "ec2:DescribeSecurityGroups",
         "ec2:DescribeSecurityGroupRules",
         "ec2:DescribeTags"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
         "ec2:AuthorizeSecurityGroupIngress", 
         "ec2:RevokeSecurityGroupIngress", 
         "ec2:AuthorizeSecurityGroupEgress", 
         "ec2:RevokeSecurityGroupEgress", 
         "ec2:ModifySecurityGroupRules",
         "ec2:UpdateSecurityGroupRuleDescriptionsIngress", 
         "ec2:UpdateSecurityGroupRuleDescriptionsEgress"
      ],
      "Resource": [
         "arn:aws:ec2:us-east-1:111122223333:security-group/*"
      ],
      "Condition": {
         "StringEquals": {
            "aws:ResourceTag/Department": "Test"
         }
      }
     },     
     {
      "Effect": "Allow",
      "Action": [
         "ec2:ModifySecurityGroupRules"
      ],
      "Resource": [
         "arn:aws:ec2:us-east-1:111122223333:security-group-rule/*"
      ]
     }
   ]
}
```

------