

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

# 搭配使用 `UpdateSecurityGroupRuleDescriptionsIngress` 與 CLI
<a name="example_ec2_UpdateSecurityGroupRuleDescriptionsIngress_section"></a>

下列程式碼範例示範如何使用 `UpdateSecurityGroupRuleDescriptionsIngress`。

------
#### [ CLI ]

**AWS CLI**  
**範例 1：使用 CIDR 來源，更新傳入安全群組規則的描述**  
下列 `update-security-group-rule-descriptions-ingress` 範例會更新指定之連接埠和 IPv4 位址範圍的安全群組規則描述。描述 '`SSH access from ABC office`' 會取代規則的任何現有描述。  

```
aws ec2 update-security-group-rule-descriptions-ingress \
    --group-id sg-02f0d35a850ba727f \
    --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,IpRanges='[{CidrIp=203.0.113.0/16,Description="SSH access from corpnet"}]'
```
輸出：  

```
{
    "Return": true
}
```
如需詳細資訊，請參閱《*Amazon EC2 使用者指南*》中的[安全群組規則](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security-groups.html#security-group-rules)。  
**範例 2：使用字首清單來源，更新傳入安全群組規則的描述**  
下列 `update-security-group-rule-descriptions-ingress` 範例會更新指定之連接埠和字首清單的安全群組規則描述。描述 '`SSH access from ABC office`' 會取代規則的任何現有描述。  

```
aws ec2 update-security-group-rule-descriptions-ingress \
    --group-id sg-02f0d35a850ba727f \
    --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,PrefixListIds='[{PrefixListId=pl-12345678,Description="SSH access from corpnet"}]'
```
輸出：  

```
{
    "Return": true
}
```
如需詳細資訊，請參閱《*Amazon EC2 使用者指南*》中的[安全群組規則](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security-groups.html#security-group-rules)。  
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateSecurityGroupRuleDescriptionsIngress](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ec2/update-security-group-rule-descriptions-ingress.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：更新現有輸入 (傳入) 安全群組規則的描述。**  

```
$existingInboundRule = Get-EC2SecurityGroupRule -SecurityGroupRuleId "sgr-1234567890"
$ruleWithUpdatedDescription = [Amazon.EC2.Model.SecurityGroupRuleDescription]@{
  "SecurityGroupRuleId" = $existingInboundRule.SecurityGroupRuleId
  "Description" = "Updated rule description"
}

Update-EC2SecurityGroupRuleIngressDescription -GroupId $existingInboundRule.GroupId -SecurityGroupRuleDescription $ruleWithUpdatedDescription
```
**範例 2：移除現有輸入 (傳入) 安全群組規則的描述 (透過省略請求中的參數)。**  

```
$existingInboundRule = Get-EC2SecurityGroupRule -SecurityGroupRuleId "sgr-1234567890"
$ruleWithoutDescription = [Amazon.EC2.Model.SecurityGroupRuleDescription]@{
  "SecurityGroupRuleId" = $existingInboundRule.SecurityGroupRuleId
}

Update-EC2SecurityGroupRuleIngressDescription -GroupId $existingInboundRule.GroupId -SecurityGroupRuleDescription $ruleWithoutDescription
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [UpdateSecurityGroupRuleDescriptionsIngress](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：更新現有輸入 (傳入) 安全群組規則的描述。**  

```
$existingInboundRule = Get-EC2SecurityGroupRule -SecurityGroupRuleId "sgr-1234567890"
$ruleWithUpdatedDescription = [Amazon.EC2.Model.SecurityGroupRuleDescription]@{
  "SecurityGroupRuleId" = $existingInboundRule.SecurityGroupRuleId
  "Description" = "Updated rule description"
}

Update-EC2SecurityGroupRuleIngressDescription -GroupId $existingInboundRule.GroupId -SecurityGroupRuleDescription $ruleWithUpdatedDescription
```
**範例 2：移除現有輸入 (傳入) 安全群組規則的描述 (透過省略請求中的參數)。**  

```
$existingInboundRule = Get-EC2SecurityGroupRule -SecurityGroupRuleId "sgr-1234567890"
$ruleWithoutDescription = [Amazon.EC2.Model.SecurityGroupRuleDescription]@{
  "SecurityGroupRuleId" = $existingInboundRule.SecurityGroupRuleId
}

Update-EC2SecurityGroupRuleIngressDescription -GroupId $existingInboundRule.GroupId -SecurityGroupRuleDescription $ruleWithoutDescription
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateSecurityGroupRuleDescriptionsIngress](https://docs.aws.amazon.com/powershell/v5/reference)。

------

如需 AWS SDK 開發人員指南和程式碼範例的完整清單，請參閱 [使用 SDK 建立 Amazon EC2 資源 AWS](sdk-general-information-section.md)。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。