AWS 文档 SDK 示例
将 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
-
- 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 Reference (V4)》中的 UpdateSecurityGroupRuleDescriptionsIngress。
-
- 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 Reference (V5)》中的 UpdateSecurityGroupRuleDescriptionsIngress。
-