本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
搭配使用 UpdateSecurityGroupRuleDescriptionsIngress 與 CLI
下列程式碼範例示範如何使用 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-idsg-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 使用者指南》中的安全群組規則。 範例 2:使用字首清單來源更新傳入安全群組規則的描述 下列 update-security-group-rule-descriptions-ingress範例會更新指定連接埠和字首清單之安全群組規則的描述。描述 'SSH access from ABC office' 會取代規則的任何現有描述。aws ec2 update-security-group-rule-descriptions-ingress \ --group-idsg-02f0d35a850ba727f\ --ip-permissions IpProtocol=tcp,FromPort=22,ToPort=22,PrefixListIds='[{PrefixListId=pl-12345678,Description="SSH access from corpnet"}]'輸出: { "Return": true }如需詳細資訊,請參閱《Amazon EC2 使用者指南》中的安全群組規則。 - 
                    如需 API 詳細資訊,請參閱《 AWS CLI 命令參考》中的 UpdateSecurityGroupRuleDescriptionsIngress 。 
 
- 
                    
 
- PowerShell
- 
            - 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。 
 
- 
                    
- 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。 
 
- 
                    
 
如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱 使用 SDK 建立 Amazon EC2 資源 AWS。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。