将 UpdateSecurityGroupRuleDescriptionsIngress 与 CLI 配合使用 - Amazon Elastic Compute Cloud

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-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 用户指南》中的安全组规则

示例 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 用户指南》中的安全组规则

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
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

有关 AWS SDK 开发人员指南和代码示例的完整列表,请参阅 使用 AWS SDK 创建 Amazon EC2 资源。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。