使用亚马逊的EC2示例 AWS CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用亚马逊的EC2示例 AWS CLI

以下代码示例向您展示如何在 Amazon 中使用来执行操作和实现常见场景EC2。 AWS Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例演示如何使用 accept-address-transfer

AWS CLI

接受向您的账户转移的弹性 IP 地址

以下accept-address-transfer示例接受将指定的弹性 IP 地址转移到您的账户。

aws ec2 accept-address-transfer \ --address 100.21.184.216

输出:

{ "AddressTransfer": { "PublicIp": "100.21.184.216", "AllocationId": "eipalloc-09ad461b0d03f6aaf", "TransferAccountId": "123456789012", "TransferOfferExpirationTimestamp": "2023-02-22T20:51:10.000Z", "TransferOfferAcceptedTimestamp": "2023-02-22T22:52:54.000Z", "AddressTransferStatus": "accepted" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的传输弹性 IP 地址

以下代码示例演示如何使用 accept-reserved-instances-exchange-quote

AWS CLI

执行可转换预留实例交换

此示例执行指定的可转换预留实例的交换。

命令:

aws ec2 accept-reserved-instances-exchange-quote --reserved-instance-ids 7b8750c3-397e-4da4-bbcb-a45ebexample --target-configurations OfferingId=b747b472-423c-48f3-8cee-679bcexample

输出:

{ "ExchangeId": "riex-e68ed3c1-8bc8-4c17-af77-811afexample" }

以下代码示例演示如何使用 accept-transit-gateway-peering-attachment

AWS CLI

接受公交网关对等连接

以下accept-transit-gateway-peering-attachment示例接受指定的传输网关对等连接。该--region参数指定接受者中转网关所在的区域。

aws ec2 accept-transit-gateway-peering-attachment \ --transit-gateway-attachment-id tgw-attach-4455667788aabbccd \ --region us-east-2

输出:

{ "TransitGatewayPeeringAttachment": { "TransitGatewayAttachmentId": "tgw-attach-4455667788aabbccd", "RequesterTgwInfo": { "TransitGatewayId": "tgw-123abc05e04123abc", "OwnerId": "123456789012", "Region": "us-west-2" }, "AccepterTgwInfo": { "TransitGatewayId": "tgw-11223344aabbcc112", "OwnerId": "123456789012", "Region": "us-east-2" }, "State": "pending", "CreationTime": "2019-12-09T11:38:31.000Z" } }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 对等连接附件

以下代码示例演示如何使用 accept-transit-gateway-vpc-attachment

AWS CLI

接受将连接至传输网关的请求。VPC

以下accept-transit-gateway-vpc-attachment示例接受请求 forte 指定的附件。

aws ec2 accept-transit-gateway-vpc-attachment \ --transit-gateway-attachment-id tgw-attach-0a34fe6b4fEXAMPLE

输出:

{ "TransitGatewayVpcAttachment": { "TransitGatewayAttachmentId": "tgw-attach-0a34fe6b4fEXAMPLE", "TransitGatewayId": "tgw-0262a0e521EXAMPLE", "VpcId": "vpc-07e8ffd50fEXAMPLE", "VpcOwnerId": "123456789012", "State": "pending", "SubnetIds": [ "subnet-0752213d59EXAMPLE" ], "CreationTime": "2019-07-10T17:33:46.000Z", "Options": { "DnsSupport": "enable", "Ipv6Support": "disable" } } }

有关更多信息,请参阅《公交网关指南》VPC中的 Transit Gateway 附件

以下代码示例演示如何使用 accept-vpc-endpoint-connections

AWS CLI

接受接口端点连接请求

此示例接受指定终端节点服务的指定端点连接请求。

命令:

aws ec2 accept-vpc-endpoint-connections --service-id vpce-svc-03d5ebb7d9579a2b3 --vpc-endpoint-ids vpce-0c1308d7312217abc

输出:

{ "Unsuccessful": [] }

以下代码示例演示如何使用 accept-vpc-peering-connection

AWS CLI

接受对VPC等连接

此示例接受指定的对VPC等连接请求。

命令:

aws ec2 accept-vpc-peering-connection --vpc-peering-connection-id pcx-1a2b3c4d

输出:

{ "VpcPeeringConnection": { "Status": { "Message": "Provisioning", "Code": "provisioning" }, "Tags": [], "AccepterVpcInfo": { "OwnerId": "444455556666", "VpcId": "vpc-44455566", "CidrBlock": "10.0.1.0/28" }, "VpcPeeringConnectionId": "pcx-1a2b3c4d", "RequesterVpcInfo": { "OwnerId": "444455556666", "VpcId": "vpc-111abc45", "CidrBlock": "10.0.0.0/28" } } }

以下代码示例演示如何使用 advertise-byoip-cidr

AWS CLI

宣传地址范围

以下advertise-byoip-cidr示例公布了指定的公共IPv4地址范围。

aws ec2 advertise-byoip-cidr \ --cidr 203.0.113.25/24

输出:

{ "ByoipCidr": { "Cidr": "203.0.113.25/24", "StatusMessage": "ipv4pool-ec2-1234567890abcdef0", "State": "provisioned" } }

以下代码示例演示如何使用 allocate-address

AWS CLI

示例 1:从 Amazon 的地址池中分配弹性 IP 地址

以下 allocate-address 示例分配弹性 IP 地址。亚马逊从亚马逊的地址池EC2中选择地址。

aws ec2 allocate-address

输出:

{ "PublicIp": "70.224.234.241", "AllocationId": "eipalloc-01435ba59eEXAMPLE", "PublicIpv4Pool": "amazon", "NetworkBorderGroup": "us-west-2", "Domain": "vpc" }

有关更多信息,请参阅 Amazon EC2 用户指南中的弹性 IP 地址

示例 2:分配弹性 IP 地址并将其与网络边界组关联

以下 allocate-address 示例分配弹性 IP 地址并将其与指定的网络边界组关联。

aws ec2 allocate-address \ --network-border-group us-west-2-lax-1

输出:

{ "PublicIp": "70.224.234.241", "AllocationId": "eipalloc-e03dd489ceEXAMPLE", "PublicIpv4Pool": "amazon", "NetworkBorderGroup": "us-west-2-lax-1", "Domain": "vpc" }

有关更多信息,请参阅 Amazon EC2 用户指南中的弹性 IP 地址

示例 3:从自己拥有的地址池中分配弹性 IP 地址

以下 allocate-address 示例从您引入 Amazon Web Services 账户的地址池中,分配弹性 IP 地址。Amazon 从地址池EC2中选择地址。

aws ec2 allocate-address \ --public-ipv4-pool ipv4pool-ec2-1234567890abcdef0

输出:

{ "AllocationId": "eipalloc-02463d08ceEXAMPLE", "NetworkBorderGroup": "us-west-2", "CustomerOwnedIp": "18.218.95.81", "CustomerOwnedIpv4Pool": "ipv4pool-ec2-1234567890abcdef0", "Domain": "vpc" "NetworkBorderGroup": "us-west-2", }

有关更多信息,请参阅 Amazon EC2 用户指南中的弹性 IP 地址

以下代码示例演示如何使用 allocate-hosts

AWS CLI

示例 1:分配专用主机

以下allocate-hosts示例在eu-west-1a可用区中分配了一台专用主机,您可以在该主机上启动m5.large实例。默认情况下,专用主机仅接受目标实例启动,不支持主机恢复。

aws ec2 allocate-hosts \ --instance-type m5.large \ --availability-zone eu-west-1a \ --quantity 1

输出:

{ "HostIds": [ "h-07879acf49EXAMPLE" ] }

示例 2:分配启用自动放置和主机恢复的专用主机

以下allocate-hosts示例在eu-west-1a可用区中分配一台启用了自动放置和主机恢复的专用主机。

aws ec2 allocate-hosts \ --instance-type m5.large \ --availability-zone eu-west-1a \ --auto-placement on \ --host-recovery on \ --quantity 1

输出:

{ "HostIds": [ "h-07879acf49EXAMPLE" ] }

示例 3:分配带有标签的专用主机

以下allocate-hosts示例分配了一台专用主机,并应用了密钥名为purpose、值为的production标签。

aws ec2 allocate-hosts \ --instance-type m5.large \ --availability-zone eu-west-1a \ --quantity 1 \ --tag-specifications 'ResourceType=dedicated-host,Tags={Key=purpose,Value=production}'

输出:

{ "HostIds": [ "h-07879acf49EXAMPLE" ] }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的分配专用主机

以下代码示例演示如何使用 allocate-ipam-pool-cidr

AWS CLI

CIDR从IPAM池中分配

以下allocate-ipam-pool-cidr示例CIDR从IPAM池中分配。

(Linux):

aws ec2 allocate-ipam-pool-cidr \ --ipam-pool-id ipam-pool-0533048da7d823723 \ --netmask-length 24

(视窗):

aws ec2 allocate-ipam-pool-cidr ^ --ipam-pool-id ipam-pool-0533048da7d823723 ^ --netmask-length 24

输出:

{ "IpamPoolAllocation": { "Cidr": "10.0.0.0/24", "IpamPoolAllocationId": "ipam-pool-alloc-018ecc28043b54ba38e2cd99943cebfbd", "ResourceType": "custom", "ResourceOwner": "123456789012" } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的手动向池分配以保留 IP 地址空间。CIDR

以下代码示例演示如何使用 apply-security-groups-to-client-vpn-target-network

AWS CLI

将安全组应用于客户端VPN终端节点的目标网络

以下apply-security-groups-to-client-vpn-target-network示例将安全组sg-01f6e627a89f4db32应用于指定目标网络和客户端VPN端点之间的关联。

aws ec2 apply-security-groups-to-client-vpn-target-network \ --security-group-ids sg-01f6e627a89f4db32 \ --vpc-id vpc-0e2110c2f324332e0 \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde

输出:

{ "SecurityGroupIds": [ "sg-01f6e627a89f4db32" ] }

有关更多信息,请参阅《AWS 客户机VPN管理员指南》中的 “目标网络”。

以下代码示例演示如何使用 assign-ipv6-addresses

AWS CLI

为网络接口分配特定IPv6地址

此示例将指定的IPv6地址分配给指定的网络接口。

命令:

aws ec2 assign-ipv6-addresses --network-interface-id eni-38664473 --ipv6-addresses 2001:db8:1234:1a00:3304:8879:34cf:4071 2001:db8:1234:1a00:9691:9503:25ad:1761

输出:

{ "AssignedIpv6Addresses": [ "2001:db8:1234:1a00:3304:8879:34cf:4071", "2001:db8:1234:1a00:9691:9503:25ad:1761" ], "NetworkInterfaceId": "eni-38664473" }

将 Amazon 选择IPv6的地址分配给网络接口

此示例为指定的网络接口分配两个IPv6地址。Amazon 会自动从子网IPv6CIDR区块范围内的可用IPv6地址中分配这些IPv6地址。

命令:

aws ec2 assign-ipv6-addresses --network-interface-id eni-38664473 --ipv6-address-count 2

输出:

{ "AssignedIpv6Addresses": [ "2001:db8:1234:1a00:3304:8879:34cf:4071", "2001:db8:1234:1a00:9691:9503:25ad:1761" ], "NetworkInterfaceId": "eni-38664473" }
  • 有关API详细信息,请参阅《AWS CLI 命令参考》中的 AssignIpv6Ad dresses。

以下代码示例演示如何使用 assign-private-ip-addresses

AWS CLI

为特定的辅助私有 IP 地址分配网络接口

此示例将指定的辅助私有 IP 地址分配给指定的网络接口。如果命令成功,则不返回任何输出。

命令:

aws ec2 assign-private-ip-addresses --network-interface-id eni-e5aa89a3 --private-ip-addresses 10.0.0.82

将 Amazon EC2 选择的辅助私有 IP 地址分配给网络接口

此示例为指定的网络接口分配两个辅助私有 IP 地址。Amazon EC2 会自动从与网络接口关联的子网CIDR区块范围内的可用 IP 地址中分配这些 IP 地址。如果命令成功,则不返回任何输出。

命令:

aws ec2 assign-private-ip-addresses --network-interface-id eni-e5aa89a3 --secondary-private-ip-address-count 2

以下代码示例演示如何使用 assign-private-nat-gateway-address

AWS CLI

为私有NAT网关分配私有 IP 地址

以下assign-private-nat-gateway-address示例为指定的私有NAT网关分配两个私有 IP 地址。

aws ec2 assign-private-nat-gateway-address \ --nat-gateway-id nat-1234567890abcdef0 \ --private-ip-address-count 2

输出:

{ "NatGatewayId": "nat-1234567890abcdef0", "NatGatewayAddresses": [ { "NetworkInterfaceId": "eni-0065a61b324d1897a", "IsPrimary": false, "Status": "assigning" }, { "NetworkInterfaceId": "eni-0065a61b324d1897a", "IsPrimary": false, "Status": "assigning" } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的NAT网关

以下代码示例演示如何使用 associate-address

AWS CLI

在 EC2-Classic 中关联弹性 IP 地址

此示例将弹性 IP 地址与 EC2-Classic 中的实例相关联。如果命令成功,则不返回任何输出。

命令:

aws ec2 associate-address --instance-id i-07ffe74c7330ebf53 --public-ip 198.51.100.0

要将弹性 IP 地址关联到 EC2-VPC

此示例将弹性 IP 地址与中的实例相关联VPC。

命令:

aws ec2 associate-address --instance-id i-0b263919b6498b123 --allocation-id eipalloc-64d5890a

输出:

{ "AssociationId": "eipassoc-2bebb745" }

本示例将弹性 IP 地址与网络接口相关联。

命令:

aws ec2 associate-address --allocation-id eipalloc-64d5890a --network-interface-id eni-1a2b3c4d

本示例将弹性 IP 与和网络接口关联的私有 IP 地址相关联。

命令:

aws ec2 associate-address --allocation-id eipalloc-64d5890a --network-interface-id eni-1a2b3c4d --private-ip-address 10.0.0.85

以下代码示例演示如何使用 associate-client-vpn-target-network

AWS CLI

将目标网络与客户端VPN终端节点关联

以下associate-client-vpn-target-network示例将子网与指定的客户端VPN终端节点相关联。

aws ec2 associate-client-vpn-target-network \ --subnet-id subnet-0123456789abcabca \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde

输出:

{ "AssociationId": "cvpn-assoc-12312312312312312", "Status": { "Code": "associating" } }

有关更多信息,请参阅《AWS 客户机VPN管理员指南》中的 “目标网络”。

以下代码示例演示如何使用 associate-dhcp-options

AWS CLI

将DHCP选项集与您的选项集相关联 VPC

此示例将指定的DHCP选项集与指定的选项集相关联VPC。如果命令成功,则不返回任何输出。

命令:

aws ec2 associate-dhcp-options --dhcp-options-id dopt-d9070ebb --vpc-id vpc-a01106c2

将默认DHCP选项集与您的设置相关联 VPC

此示例将默认选项集与指定DHCP选项集相关联VPC。如果命令成功,则不返回任何输出。

命令:

aws ec2 associate-dhcp-options --dhcp-options-id default --vpc-id vpc-a01106c2

以下代码示例演示如何使用 associate-iam-instance-profile

AWS CLI

将IAM实例配置文件与实例关联

此示例将名为IAM实例的实例配置文件admin-role与实例相关联i-123456789abcde123

命令:

aws ec2 associate-iam-instance-profile --instance-id i-123456789abcde123 --iam-instance-profile Name=admin-role

输出:

{ "IamInstanceProfileAssociation": { "InstanceId": "i-123456789abcde123", "State": "associating", "AssociationId": "iip-assoc-0e7736511a163c209", "IamInstanceProfile": { "Id": "AIPAJBLK7RKJKWDXVHIEC", "Arn": "arn:aws:iam::123456789012:instance-profile/admin-role" } } }

以下代码示例演示如何使用 associate-instance-event-window

AWS CLI

示例 1:将一个或多个实例与事件窗口关联

以下associate-instance-event-window示例将一个或多个实例与事件窗口相关联。

aws ec2 associate-instance-event-window \ --region us-east-1 \ --instance-event-window-id iew-0abcdef1234567890 \ --association-target "InstanceIds=i-1234567890abcdef0,i-0598c7d356eba48d7"

输出:

{ "InstanceEventWindow": { "InstanceEventWindowId": "iew-0abcdef1234567890", "Name": "myEventWindowName", "CronExpression": "* 21-23 * * 2,3", "AssociationTarget": { "InstanceIds": [ "i-1234567890abcdef0", "i-0598c7d356eba48d7" ], "Tags": [], "DedicatedHostIds": [] }, "State": "creating" } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

示例 2:将实例标签与事件窗口关联

以下associate-instance-event-window示例将实例标签与事件窗口相关联。输入instance-event-window-id参数以指定事件窗口。要关联实例标签,请指定association-target参数,为参数值指定一个或多个标签。

aws ec2 associate-instance-event-window \ --region us-east-1 \ --instance-event-window-id iew-0abcdef1234567890 \ --association-target "InstanceTags=[{Key=k2,Value=v2},{Key=k1,Value=v1}]"

输出:

{ "InstanceEventWindow": { "InstanceEventWindowId": "iew-0abcdef1234567890", "Name": "myEventWindowName", "CronExpression": "* 21-23 * * 2,3", "AssociationTarget": { "InstanceIds": [], "Tags": [ { "Key": "k2", "Value": "v2" }, { "Key": "k1", "Value": "v1" } ], "DedicatedHostIds": [] }, "State": "creating" } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

示例 3:将专用主机与事件窗口关联

以下associate-instance-event-window示例将专用主机与事件窗口相关联。输入instance-event-window-id参数以指定事件窗口。要关联专用主机,请指定--association-target参数,对于参数值,请指定一个或多个专用主机IDs。

aws ec2 associate-instance-event-window \ --region us-east-1 \ --instance-event-window-id iew-0abcdef1234567890 \ --association-target "DedicatedHostIds=h-029fa35a02b99801d"

输出:

{ "InstanceEventWindow": { "InstanceEventWindowId": "iew-0abcdef1234567890", "Name": "myEventWindowName", "CronExpression": "* 21-23 * * 2,3", "AssociationTarget": { "InstanceIds": [], "Tags": [], "DedicatedHostIds": [ "h-029fa35a02b99801d" ] }, "State": "creating" } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

以下代码示例演示如何使用 associate-ipam-resource-discovery

AWS CLI

将资源发现与 IPAM

在此示例中,您是IPAM委托管理员,并且已创建资源发现并由另一个 AWS 账户与您共享,以便您可以使用IPAM来管理和监控其他账户CIDRs拥有的资源。

备注

要完成此请求,你需要使用可以获得的资源发现 ID describe-ipam-resource-discoveries和可以通过 IPAM desc ribe-ipams 获得的 ID。你要关联的资源发现必须先使用与你的账户共享 AWS RAM。--region你输入的资源发现必须与你关联的所在区域相匹配。IPAM

以下associate-ipam-resource-discovery示例将资源发现与关联起来IPAM。

aws ec2 associate-ipam-resource-discovery \ --ipam-id ipam-005f921c17ebd5107 \ --ipam-resource-discovery-id ipam-res-disco-03e0406de76a044ee \ --tag-specifications 'ResourceType=ipam-resource-discovery,Tags=[{Key=cost-center,Value=cc123}]' \ --region us-east-1

输出:

{ { "IpamResourceDiscoveryAssociation": { "OwnerId": "320805250157", "IpamResourceDiscoveryAssociationId": "ipam-res-disco-assoc-04382a6346357cf82", "IpamResourceDiscoveryAssociationArn": "arn:aws:ec2::320805250157:ipam-resource-discovery-association/ipam-res-disco-assoc-04382a6346357cf82", "IpamResourceDiscoveryId": "ipam-res-disco-0365d2977fc1672fe", "IpamId": "ipam-005f921c17ebd5107", "IpamArn": "arn:aws:ec2::320805250157:ipam/ipam-005f921c17ebd5107", "IpamRegion": "us-east-1", "IsDefault": false, "ResourceDiscoveryStatus": "active", "State": "associate-in-progress", "Tags": [] } } }

关联资源发现后,您可以监控和/或管理其他账户创建的资源的 IP 地址。有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的IPAM与组织外部账户集成

以下代码示例演示如何使用 associate-nat-gateway-address

AWS CLI

将弹性 IP 地址与公共NAT网关关联

以下associate-nat-gateway-address示例将指定的弹性 IP 地址与指定的公共NAT网关相关联。 AWS 自动分配辅助私有IPv4地址。

aws ec2 associate-nat-gateway-address \ --nat-gateway-id nat-1234567890abcdef0 \ --allocation-ids eipalloc-0be6ecac95EXAMPLE

输出:

{ "NatGatewayId": "nat-1234567890abcdef0", "NatGatewayAddresses": [ { "AllocationId": "eipalloc-0be6ecac95EXAMPLE", "NetworkInterfaceId": "eni-09cc4b2558794f7f9", "IsPrimary": false, "Status": "associating" } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的NAT网关

以下代码示例演示如何使用 associate-route-table

AWS CLI

将路由表与子网关联

此示例将指定的路由表与指定的子网关联。

命令:

aws ec2 associate-route-table --route-table-id rtb-22574640 --subnet-id subnet-9d4a7b6c

输出:

{ "AssociationId": "rtbassoc-781d0d1a" }

以下代码示例演示如何使用 associate-subnet-cidr-block

AWS CLI

将IPv6CIDR区块与子网关联

此示例将IPv6CIDR区块与指定的子网关联。

命令:

aws ec2 associate-subnet-cidr-block --subnet-id subnet-5f46ec3b --ipv6-cidr-block 2001:db8:1234:1a00::/64

输出:

{ "SubnetId": "subnet-5f46ec3b", "Ipv6CidrBlockAssociation": { "Ipv6CidrBlock": "2001:db8:1234:1a00::/64", "AssociationId": "subnet-cidr-assoc-3aa54053", "Ipv6CidrBlockState": { "State": "associating" } } }

以下代码示例演示如何使用 associate-transit-gateway-multicast-domain

AWS CLI

将传输网关与多播域关联

以下associate-transit-gateway-multicast-domain示例将指定的子网和连接与指定的多播域相关联。

aws ec2 associate-transit-gateway-multicast-domain \ --transit-gateway-multicast-domain-id tgw-mcast-domain-0c4905cef79d6e597 \ --transit-gateway-attachment-id tgw-attach-028c1dd0f8f5cbe8e \ --subnet-ids subnet-000de86e3b49c932a \ --transit-gateway-multicast-domain-id tgw-mcast-domain-0c4905cef7EXAMPLE

输出:

{ "Associations": { "TransitGatewayMulticastDomainId": "tgw-mcast-domain-0c4905cef79d6e597", "TransitGatewayAttachmentId": "tgw-attach-028c1dd0f8f5cbe8e", "ResourceId": "vpc-01128d2c240c09bd5", "ResourceType": "vpc", "Subnets": [ { "SubnetId": "subnet-000de86e3b49c932a", "State": "associating" } ] } }

有关更多信息,请参阅《传输网关指南》中的管理多播域

以下代码示例演示如何使用 associate-transit-gateway-route-table

AWS CLI

将公交网关路由表与公交网关附件关联

以下示例将指定的公交网关路由表与指定的VPC附件相关联。

aws ec2 associate-transit-gateway-route-table \ --transit-gateway-route-table-id tgw-rtb-002573ed1eEXAMPLE \ --transit-gateway-attachment-id tgw-attach-0b5968d3b6EXAMPLE

输出:

{ "Association": { "TransitGatewayRouteTableId": "tgw-rtb-002573ed1eEXAMPLE", "TransitGatewayAttachmentId": "tgw-attach-0b5968d3b6EXAMPLE", "ResourceId": "vpc-0065acced4EXAMPLE", "ResourceType": "vpc", "State": "associating" } }

有关更多信息,请参阅 T ransit Gateway 指南中的关联 Tr AWS an sit Gateway 路由表

以下代码示例演示如何使用 associate-vpc-cidr-block

AWS CLI

示例 1:将亚马逊提供的IPv6CIDR区块与区块相关联 VPC

以下associate-vpc-cidr-block示例将一个IPv6CIDR块与指定的相关联VPC。 :

aws ec2 associate-vpc-cidr-block \ --amazon-provided-ipv6-cidr-block \ --ipv6-cidr-block-network-border-group us-west-2-lax-1 \ --vpc-id vpc-8EXAMPLE

输出:

{ "Ipv6CidrBlockAssociation": { "AssociationId": "vpc-cidr-assoc-0838ce7d9dEXAMPLE", "Ipv6CidrBlockState": { "State": "associating" }, "NetworkBorderGroup": "us-west-2-lax-1" }, "VpcId": "vpc-8EXAMPLE" }

示例 2:将其他方IPv4CIDR块与关联起来 VPC

以下associate-vpc-cidr-block示例将该IPv4CIDR块10.2.0.0/16与指定的相关联VPC。

aws ec2 associate-vpc-cidr-block \ --vpc-id vpc-1EXAMPLE \ --cidr-block 10.2.0.0/16

输出:

{ "CidrBlockAssociation": { "AssociationId": "vpc-cidr-assoc-2EXAMPLE", "CidrBlock": "10.2.0.0/16", "CidrBlockState": { "State": "associating" } }, "VpcId": "vpc-1EXAMPLE" }

以下代码示例演示如何使用 attach-classic-link-vpc

AWS CLI

将 EC2-Classic 实例链接(附加)到 VPC

此示例通过安全组 sg-12312312 将实例 i-1234567890abcdef0 链接到 vpc-88888888。VPC VPC

命令:

aws ec2 attach-classic-link-vpc --instance-id i-1234567890abcdef0 --vpc-id vpc-88888888 --groups sg-12312312

输出:

{ "Return": true }

以下代码示例演示如何使用 attach-internet-gateway

AWS CLI

将互联网网关连接到您的 VPC

以下attach-internet-gateway示例将指定的互联网网关附加到特定的VPC。

aws ec2 attach-internet-gateway \ --internet-gateway-id igw-0d0fb496b3EXAMPLE \ --vpc-id vpc-0a60eb65b4EXAMPLE

此命令不生成任何输出。

有关更多信息,请参阅 Amazon VPC 用户指南中的互联网网关

以下代码示例演示如何使用 attach-network-interface

AWS CLI

示例 1:将网络接口连接到实例

以下attach-network-interface示例将指定的网络接口连接到指定的实例。

aws ec2 attach-network-interface \ --network-interface-id eni-0dc56a8d4640ad10a \ --instance-id i-1234567890abcdef0 \ --device-index 1

输出:

{ "AttachmentId": "eni-attach-01a8fc87363f07cf9" }

有关更多信息,请参阅 Amazon EC2 用户指南中的弹性网络接口

示例 2:将网络接口连接到带有多张网卡的实例

以下attach-network-interface示例将指定的网络接口连接到指定的实例和网卡。

aws ec2 attach-network-interface \ --network-interface-id eni-07483b1897541ad83 \ --instance-id i-01234567890abcdef \ --network-card-index 1 \ --device-index 1

输出:

{ "AttachmentId": "eni-attach-0fbd7ee87a88cd06c" }

有关更多信息,请参阅 Amazon EC2 用户指南中的弹性网络接口

以下代码示例演示如何使用 attach-verified-access-trust-provider

AWS CLI

将信任提供者附加到实例

以下attach-verified-access-trust-provider示例将指定的已验证访问信任提供者附加到指定的已验证访问实例。

aws ec2 attach-verified-access-trust-provider \ --verified-access-instance-id vai-0ce000c0b7643abea \ --verified-access-trust-provider-id vatp-0bb32de759a3e19e7

输出:

{ "VerifiedAccessTrustProvider": { "VerifiedAccessTrustProviderId": "vatp-0bb32de759a3e19e7", "Description": "", "TrustProviderType": "user", "UserTrustProviderType": "iam-identity-center", "PolicyReferenceName": "idc", "CreationTime": "2023-08-25T19:00:38", "LastUpdatedTime": "2023-08-25T19:00:38" }, "VerifiedAccessInstance": { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "Description": "", "VerifiedAccessTrustProviders": [ { "VerifiedAccessTrustProviderId": "vatp-0bb32de759a3e19e7", "TrustProviderType": "user", "UserTrustProviderType": "iam-identity-center" } ], "CreationTime": "2023-08-25T18:27:56", "LastUpdatedTime": "2023-08-25T18:27:56" } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问实例

以下代码示例演示如何使用 attach-volume

AWS CLI

将卷连接到实例

此示例命令将卷 (vol-1234567890abcdef0) 附加到实例 (i-01474ef662b89480) 上/dev/sdf

命令:

aws ec2 attach-volume --volume-id vol-1234567890abcdef0 --instance-id i-01474ef662b89480 --device /dev/sdf

输出:

{ "AttachTime": "YYYY-MM-DDTHH:MM:SS.000Z", "InstanceId": "i-01474ef662b89480", "VolumeId": "vol-1234567890abcdef0", "State": "attaching", "Device": "/dev/sdf" }

以下代码示例演示如何使用 attach-vpn-gateway

AWS CLI

将虚拟专用网关连接到您的 VPC

以下attach-vpn-gateway示例将指定的虚拟专用网关附加到指定的VPC。

aws ec2 attach-vpn-gateway \ --vpn-gateway-id vgw-9a4cacf3 \ --vpc-id vpc-a01106c2

输出:

{ "VpcAttachment": { "State": "attaching", "VpcId": "vpc-a01106c2" } }

以下代码示例演示如何使用 authorize-client-vpn-ingress

AWS CLI

为客户端VPN终端节点添加授权规则

以下authorize-client-vpn-ingress示例添加了一个允许所有客户端访问互联网的入口授权规则 (0.0.0.0/0)。

aws ec2 authorize-client-vpn-ingress \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde \ --target-network-cidr 0.0.0.0/0 \ --authorize-all-groups

输出:

{ "Status": { "Code": "authorizing" } }

有关更多信息,请参阅《AWS 客户机VPN管理员指南》中的授权规则

以下代码示例演示如何使用 authorize-security-group-egress

AWS CLI

添加允许出站流量到达特定地址范围的规则

此示例命令添加了一条规则,该规则允许访问TCP端口 80 上的指定地址范围。

命令(Linux):

aws ec2 authorize-security-group-egress --group-id sg-1a2b3c4d --ip-permissions IpProtocol=tcp,FromPort=80,ToPort=80,IpRanges='[{CidrIp=10.0.0.0/16}]'

命令(Windows):

aws ec2 authorize-security-group-egress --group-id sg-1a2b3c4d --ip-permissions IpProtocol=tcp,FromPort=80,ToPort=80,IpRanges=[{CidrIp=10.0.0.0/16}]

添加允许出站流量进入特定安全组的规则

此示例命令添加了一条规则,该规则允许访问TCP端口 80 上的指定安全组。

命令(Linux):

aws ec2 authorize-security-group-egress --group-id sg-1a2b3c4d --ip-permissions IpProtocol=tcp,FromPort=80,ToPort=80,UserIdGroupPairs='[{GroupId=sg-4b51a32f}]'

命令(Windows):

aws ec2 authorize-security-group-egress --group-id sg-1a2b3c4d --ip-permissions IpProtocol=tcp,FromPort=80,ToPort=80,UserIdGroupPairs=[{GroupId=sg-4b51a32f}]

以下代码示例演示如何使用 authorize-security-group-ingress

AWS CLI

示例 1:添加允许入站SSH流量的规则

以下authorize-security-group-ingress示例添加了一条规则,允许TCP端口 22 (SSH) 上的入站流量。

aws ec2 authorize-security-group-ingress \ --group-id sg-1234567890abcdef0 \ --protocol tcp \ --port 22 \ --cidr 203.0.113.0/24

输出:

{ "Return": true, "SecurityGroupRules": [ { "SecurityGroupRuleId": "sgr-01afa97ef3e1bedfc", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "123456789012", "IsEgress": false, "IpProtocol": "tcp", "FromPort": 22, "ToPort": 22, "CidrIpv4": "203.0.113.0/24" } ] }

示例 2:添加允许来自其他安全组的入站HTTP流量的规则

以下authorize-security-group-ingress示例添加了一条规则,允许源安全组通过TCP端口 80 进行入站访问sg-1a2b3c4d。源组必须位于同一个VPC或同一个对等组中VPC(需要对VPC等连接)。允许的传入流量基于与源安全组相关联实例的私有 IP 地址(而不是公有 IP 或弹性 IP 地址)。

aws ec2 authorize-security-group-ingress \ --group-id sg-1234567890abcdef0 \ --protocol tcp \ --port 80 \ --source-group sg-1a2b3c4d

输出:

{ "Return": true, "SecurityGroupRules": [ { "SecurityGroupRuleId": "sgr-01f4be99110f638a7", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "123456789012", "IsEgress": false, "IpProtocol": "tcp", "FromPort": 80, "ToPort": 80, "ReferencedGroupInfo": { "GroupId": "sg-1a2b3c4d", "UserId": "123456789012" } } ] }

示例 3:在同一个调用中添加多个规则

以下authorize-security-group-ingress示例使用ip-permissions参数添加两个入站规则,一个用于在TCP端口 3389 (RDP) 上启用入站访问,另一个启用 ping/。ICMP

aws ec2 authorize-security-group-ingress--group-id sg-1234567890abcdef0--ip-permissions =tcp,=3389,= FromPort 3389,= “[{=172.31.0.0/16} IpProtocol]” =icmp,=-1,=-1,= “[{ToPort=172.31.0.0/16}]” IpRanges CidrIp IpProtocol FromPort ToPort IpRanges CidrIp

输出:

{ "Return": true, "SecurityGroupRules": [ { "SecurityGroupRuleId": "sgr-00e06e5d3690f29f3", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "123456789012", "IsEgress": false, "IpProtocol": "tcp", "FromPort": 3389, "ToPort": 3389, "CidrIpv4": "172.31.0.0/16" }, { "SecurityGroupRuleId": "sgr-0a133dd4493944b87", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "123456789012", "IsEgress": false, "IpProtocol": "tcp", "FromPort": -1, "ToPort": -1, "CidrIpv4": "172.31.0.0/16" } ] }

示例 4:添加ICMP流量规则

以下authorize-security-group-ingress示例使用ip-permissions参数添加一条允许来自任何地方的ICMP消息Destination Unreachable: Fragmentation Needed and Don't Fragment was Set(类型 3,代码 4)的入站规则。

aws ec2 authorize-security-group-ingress--group-id sg-1234567890abcdef0--ip-permissions =icmp,=3,=4,= “[{=0.0.0.0/0}]] IpProtocol” FromPort ToPort IpRanges CidrIp

输出:

{ "Return": true, "SecurityGroupRules": [ { "SecurityGroupRuleId": "sgr-0de3811019069b787", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "123456789012", "IsEgress": false, "IpProtocol": "icmp", "FromPort": 3, "ToPort": 4, "CidrIpv4": "0.0.0.0/0" } ] }

示例 5:添加IPv6流量规则

以下authorize-security-group-ingress示例使用ip-permissions参数添加允许从该IPv6范围进行SSH访问(端口 22)的入站规则2001:db8:1234:1a00::/64

aws ec2 authorize-security-group-ingress--group-id sg-1234567890abcdef0--ip-permissions =tcp,=22,=22,Ipv6Ranges= “[{6 IpProtocol =2001: db 8:1234:1 a00:: /64}]” FromPort ToPort CidrIpv

输出:

{ "Return": true, "SecurityGroupRules": [ { "SecurityGroupRuleId": "sgr-0455bc68b60805563", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "123456789012", "IsEgress": false, "IpProtocol": "tcp", "FromPort": 22, "ToPort": 22, "CidrIpv6": "2001:db8:1234:1a00::/64" } ] }

示例 6:添加ICMPv6流量规则

以下authorize-security-group-ingress示例使用ip-permissions参数添加允许来自任何地方的ICMPv6流量的入站规则。

aws ec2 authorize-security-group-ingress--group-id sg-1234567890abcdef0--ip-permissions =icmpv6,Ipv6Ranges= “[{6=:: /0}]” IpProtocol CidrIpv

输出:

{ "Return": true, "SecurityGroupRules": [ { "SecurityGroupRuleId": "sgr-04b612d9363ab6327", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "123456789012", "IsEgress": false, "IpProtocol": "icmpv6", "FromPort": -1, "ToPort": -1, "CidrIpv6": "::/0" } ] }

示例 7:添加带有描述的规则

以下authorize-security-group-ingress示例使用ip-permissions参数添加允许来自指定IPv4地址范围的RDP流量的入站规则。该规则包含描述,可帮助以后识别。

aws ec2 authorize-security-group-ingress--group-id sg-1234567890abcdef0--ip-permissions =tcp,=3389,=3389,= “[{=203.0.113.0/24,FromPort描述 IpProtocol ='从纽约办公室访问'}]” ToPort IpRanges CidrIp RDP

输出:

{ "Return": true, "SecurityGroupRules": [ { "SecurityGroupRuleId": "sgr-0397bbcc01e974db3", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "123456789012", "IsEgress": false, "IpProtocol": "tcp", "FromPort": 3389, "ToPort": 3389, "CidrIpv4": "203.0.113.0/24", "Description": "RDP access from NY office" } ] }

示例 8:添加使用前缀列表的入站规则

以下authorize-security-group-ingress示例使用ip-permissions参数添加一条入站规则,该规则允许指定前缀列表中CIDR范围内的所有流量。

aws ec2 authorize-security-group-ingress--group-id sg-04a351bfe432d4e71--ip-permissions =all,= “[{=pl-002dc3ec097de1514}]]” IpProtocol PrefixListIds PrefixListId

输出:

{ "Return": true, "SecurityGroupRules": [ { "SecurityGroupRuleId": "sgr-09c74b32f677c6c7c", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "123456789012", "IsEgress": false, "IpProtocol": "-1", "FromPort": -1, "ToPort": -1, "PrefixListId": "pl-0721453c7ac4ec009" } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的安全组

以下代码示例演示如何使用 bundle-instance

AWS CLI

捆绑实例

此示例i-1234567890abcdef0将实例绑定到名bundletasks为的存储桶。在为访问密钥指定值之前IDs,请查看并遵循管理 AWS 访问密钥的最佳实践中的指导。

命令:

aws ec2 bundle-instance --instance-id i-1234567890abcdef0 --bucket bundletasks --prefix winami --owner-akid AK12AJEXAMPLE --owner-sak example123example

输出:

{ "BundleTask": { "UpdateTime": "2015-09-15T13:30:35.000Z", "InstanceId": "i-1234567890abcdef0", "Storage": { "S3": { "Prefix": "winami", "Bucket": "bundletasks" } }, "State": "pending", "StartTime": "2015-09-15T13:30:35.000Z", "BundleId": "bun-294e041f" } }

以下代码示例演示如何使用 cancel-bundle-task

AWS CLI

取消捆绑任务

此示例取消捆绑任务bun-2a4e041c

命令:

aws ec2 cancel-bundle-task --bundle-id bun-2a4e041c

输出:

{ "BundleTask": { "UpdateTime": "2015-09-15T13:27:40.000Z", "InstanceId": "i-1234567890abcdef0", "Storage": { "S3": { "Prefix": "winami", "Bucket": "bundletasks" } }, "State": "cancelling", "StartTime": "2015-09-15T13:24:35.000Z", "BundleId": "bun-2a4e041c" } }

以下代码示例演示如何使用 cancel-capacity-reservation-fleets

AWS CLI

取消容量预留舰队

以下cancel-capacity-reservation-fleets示例取消了指定的容量预留队列及其预留的容量。当您取消队列时,其状态将更改为cancelled,并且无法再创建新的容量预留。此外,队列中所有单独的容量预留都将被取消,以前以预留容量运行的实例继续以共享容量正常运行。

aws ec2 cancel-capacity-reservation-fleets \ --capacity-reservation-fleet-ids crf-abcdef01234567890

输出:

{ "SuccessfulFleetCancellations": [ { "CurrentFleetState": "cancelling", "PreviousFleetState": "active", "CapacityReservationFleetId": "crf-abcdef01234567890" } ], "FailedFleetCancellations": [] }

有关容量预留队列的更多信息,请参阅 A mazon EC2 用户指南中的容量预留队列。

以下代码示例演示如何使用 cancel-capacity-reservation

AWS CLI

取消容量预留

以下cancel-capacity-reservation示例取消了指定的容量预留。

aws ec2 cancel-capacity-reservation \ --capacity-reservation-id cr-1234abcd56EXAMPLE

输出:

{ "Return": true }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的取消容量预留

以下代码示例演示如何使用 cancel-conversion-task

AWS CLI

取消实例或卷的有效转换

此示例取消了与任务 ID import-i-fh 95npoc 关联的上传。如果命令成功,则不返回任何输出。

命令:

aws ec2 cancel-conversion-task --conversion-task-id import-i-fh95npoc

以下代码示例演示如何使用 cancel-export-task

AWS CLI

取消正在执行的导出任务

此示例取消了任务 ID 为 export-i-fgelt 0i7 的活动导出任务。如果命令成功,则不返回任何输出。

命令:

aws ec2 cancel-export-task --export-task-id export-i-fgelt0i7

以下代码示例演示如何使用 cancel-image-launch-permission

AWS CLI

取消与您的亚马逊 Web Services 账户AMI共享

以下cancel-image-launch-permission示例将您的账户从指定的启动权限AMI中移除。

aws ec2 cancel-image-launch-permission \ --image-id ami-0123456789example \ --region us-east-1

输出:

{ "Return": true }

有关更多信息,请参阅《亚马逊EC2用户指南》中的 “取消与您的亚马逊 Web Services 账户AMI共享”。

以下代码示例演示如何使用 cancel-import-task

AWS CLI

取消导入任务

以下cancel-import-task示例取消了指定的导入映像任务。

aws ec2 cancel-import-task \ --import-task-id import-ami-1234567890abcdef0

输出:

{ "ImportTaskId": "import-ami-1234567890abcdef0", "PreviousState": "active", "State": "deleting" }

以下代码示例演示如何使用 cancel-reserved-instances-listing

AWS CLI

取消预留实例上架

以下cancel-reserved-instances-listing示例取消了指定的预留实例列表。

aws ec2 cancel-reserved-instances-listing \ --reserved-instances-listing-id 5ec28771-05ff-4b9b-aa31-9e57dexample

以下代码示例演示如何使用 cancel-spot-fleet-requests

AWS CLI

示例 1:取消竞价型队列请求并终止关联的实例

以下cancel-spot-fleet-requests示例取消竞价型队列请求并终止相关的按需实例和竞价型实例。

aws ec2 cancel-spot-fleet-requests \ --spot-fleet-request-ids sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE \ --terminate-instances

输出:

{ "SuccessfulFleetRequests": [ { "SpotFleetRequestId": "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE", "CurrentSpotFleetRequestState": "cancelled_terminating", "PreviousSpotFleetRequestState": "active" } ], "UnsuccessfulFleetRequests": [] }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的取消竞价型队列请求

示例 2:在不终止关联实例的情况下取消竞价型队列请求

以下cancel-spot-fleet-requests示例在不终止关联的按需实例和竞价型实例的情况下取消竞价型队列请求。

aws ec2 cancel-spot-fleet-requests \ --spot-fleet-request-ids sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE \ --no-terminate-instances

输出:

{ "SuccessfulFleetRequests": [ { "SpotFleetRequestId": "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE", "CurrentSpotFleetRequestState": "cancelled_running", "PreviousSpotFleetRequestState": "active" } ], "UnsuccessfulFleetRequests": [] }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的取消竞价型队列请求

以下代码示例演示如何使用 cancel-spot-instance-requests

AWS CLI

取消竞价型实例请求

此示例命令取消竞价型实例请求。

命令:

aws ec2 cancel-spot-instance-requests --spot-instance-request-ids sir-08b93456

输出:

{ "CancelledSpotInstanceRequests": [ { "State": "cancelled", "SpotInstanceRequestId": "sir-08b93456" } ] }

以下代码示例演示如何使用 confirm-product-instance

AWS CLI

确认产品实例

此示例确定指定的产品代码是否与指定的实例相关联。

命令:

aws ec2 confirm-product-instance --product-code 774F4FF8 --instance-id i-1234567890abcdef0

输出:

{ "OwnerId": "123456789012" }

以下代码示例演示如何使用 copy-fpga-image

AWS CLI

复制 Amazon FPGA 图片

此示例将指定内容AFI从us-east-1区域复制到当前区域 (eu-west-1)。

命令:

aws ec2 copy-fpga-image --name copy-afi --source-fpga-image-id afi-0d123e123bfc85abc --source-region us-east-1 --region eu-west-1

输出:

{ "FpgaImageId": "afi-06b12350a123fbabc" }

以下代码示例演示如何使用 copy-image

AWS CLI

示例 1:将复制AMI到另一个区域

以下copy-image示例命令将指定的内容AMI从区域复制到该us-west-2区域,us-east-1并添加了简短的描述。

aws ec2 copy-image \ --region us-east-1 \ --name ami-name \ --source-region us-west-2 \ --source-image-id ami-066877671789bd71b \ --description "This is my copied image."

输出:

{ "ImageId": "ami-0123456789abcdefg" }

有关更多信息,请参阅 Amazon EC2 用户指南AMI中的复制

示例 2:将复制AMI到另一个区域并加密备份快照

以下copy-image命令将指定的内容AMI从区域复制到当前us-west-2区域,并使用指定的密KMS钥对备份快照进行加密。

aws ec2 copy-image \ --source-region us-west-2 \ --name ami-name \ --source-image-id ami-066877671789bd71b \ --encrypted \ --kms-key-id alias/my-kms-key

输出:

{ "ImageId": "ami-0123456789abcdefg" }

有关更多信息,请参阅 Amazon EC2 用户指南AMI中的复制

示例 3:在复制用户定义的AMI标签时包括用户定义的标签 AMI

复制时,以下copy-image命令使用--copy-image-tags参数复制用户定义的AMI标签AMI。

aws ec2 copy-image \ --region us-east-1 \ --name ami-name \ --source-region us-west-2 \ --source-image-id ami-066877671789bd71b \ --description "This is my copied image." --copy-image-tags

输出:

{ "ImageId": "ami-0123456789abcdefg" }

有关更多信息,请参阅 Amazon EC2 用户指南AMI中的复制

以下代码示例演示如何使用 copy-snapshot

AWS CLI

示例 1:将快照复制到另一个区域

以下copy-snapshot示例命令将指定的快照从区域复制到该us-west-2区域,us-east-1并添加了简短的描述。

aws ec2 copy-snapshot \ --region us-east-1 \ --source-region us-west-2 \ --source-snapshot-id snap-066877671789bd71b \ --description "This is my copied snapshot."

输出:

{ "SnapshotId": "snap-066877671789bd71b" }

有关更多信息,请参阅亚马逊EC2用户指南中的复制亚马逊EBS快照

示例 2:复制未加密的快照并加密新快照

以下copy-snapshot命令将指定的未加密快照从该us-west-2区域复制到当前区域,并使用指定的KMS密钥对新快照进行加密。

aws ec2 copy-snapshot \ --source-region us-west-2 \ --source-snapshot-id snap-066877671789bd71b \ --encrypted \ --kms-key-id alias/my-kms-key

输出:

{ "SnapshotId": "snap-066877671789bd71b" }

有关更多信息,请参阅亚马逊EC2用户指南中的复制亚马逊EBS快照

以下代码示例演示如何使用 create-capacity-reservation-fleet

AWS CLI

创建容量预留队列

以下create-capacity-reservation-fleet示例为请求中指定的实例类型创建容量预留队列,最多不超过指定的总目标容量。容量预留机群为其预留容量的实例数取决于总目标容量和您在请求中指定的实例类型权重。指定要使用的实例类型以及每个指定实例类型的优先级。

aws ec2 create-capacity-reservation-fleet \ --total-target-capacity 24 \ --allocation-strategy prioritized \ --instance-match-criteria open \ --tenancy default \ --end-date 2022-12-31T23:59:59.000Z \ --instance-type-specifications file://instanceTypeSpecification.json

instanceTypeSpecification.json 的内容:

[ { "InstanceType": "m5.xlarge", "InstancePlatform": "Linux/UNIX", "Weight": 3.0, "AvailabilityZone":"us-east-1a", "EbsOptimized": true, "Priority" : 1 } ]

输出:

{ "Status": "submitted", "TotalFulfilledCapacity": 0.0, "CapacityReservationFleetId": "crf-abcdef01234567890", "TotalTargetCapacity": 24 }

有关容量预留队列的更多信息,请参阅 A mazon EC2 用户指南中的容量预留队列。

有关实例类型重量和目标总容量的更多信息,请参阅 Amazon EC2 用户指南中的实例类型重量和目标总容量

有关为指定实例类型指定优先级的更多信息,请参阅 Amazon EC2 用户指南中的分配策略实例类型优先级

以下代码示例演示如何使用 create-capacity-reservation

AWS CLI

示例 1:创建容量预留

以下create-capacity-reservation示例在eu-west-1a可用区创建容量预留,您可以在其中启动三个运行 Linux/Unix 操作系统的t2.medium实例。默认情况下,容量预留是在开放实例匹配条件下创建的,不支持临时存储,在您手动取消之前,容量预留将保持活动状态。

aws ec2 create-capacity-reservation \ --availability-zone eu-west-1a \ --instance-type t2.medium \ --instance-platform Linux/UNIX \ --instance-count 3

输出:

{ "CapacityReservation": { "CapacityReservationId": "cr-1234abcd56EXAMPLE ", "EndDateType": "unlimited", "AvailabilityZone": "eu-west-1a", "InstanceMatchCriteria": "open", "EphemeralStorage": false, "CreateDate": "2019-08-16T09:27:35.000Z", "AvailableInstanceCount": 3, "InstancePlatform": "Linux/UNIX", "TotalInstanceCount": 3, "State": "active", "Tenancy": "default", "EbsOptimized": false, "InstanceType": "t2.medium" } }

示例 2:创建在指定日期/时间自动结束的容量预留

以下create-capacity-reservation示例在eu-west-1a可用区创建容量预留,您可以在其中启动三个运行 Linux/Unix 操作系统的m5.large实例。此容量预留将于 2019 年 8 月 31 日 23:59:59 自动结束。

aws ec2 create-capacity-reservation \ --availability-zone eu-west-1a \ --instance-type m5.large \ --instance-platform Linux/UNIX \ --instance-count 3 \ --end-date-type limited \ --end-date 2019-08-31T23:59:59Z

输出:

{ "CapacityReservation": { "CapacityReservationId": "cr-1234abcd56EXAMPLE ", "EndDateType": "limited", "AvailabilityZone": "eu-west-1a", "EndDate": "2019-08-31T23:59:59.000Z", "InstanceMatchCriteria": "open", "EphemeralStorage": false, "CreateDate": "2019-08-16T10:15:53.000Z", "AvailableInstanceCount": 3, "InstancePlatform": "Linux/UNIX", "TotalInstanceCount": 3, "State": "active", "Tenancy": "default", "EbsOptimized": false, "InstanceType": "m5.large" } }

示例 3:创建仅接受目标实例启动的容量预留

以下create-capacity-reservation示例创建了仅接受目标实例启动的容量预留。

aws ec2 create-capacity-reservation \ --availability-zone eu-west-1a \ --instance-type m5.large \ --instance-platform Linux/UNIX \ --instance-count 3 \ --instance-match-criteria targeted

输出:

{ "CapacityReservation": { "CapacityReservationId": "cr-1234abcd56EXAMPLE ", "EndDateType": "unlimited", "AvailabilityZone": "eu-west-1a", "InstanceMatchCriteria": "targeted", "EphemeralStorage": false, "CreateDate": "2019-08-16T10:21:57.000Z", "AvailableInstanceCount": 3, "InstancePlatform": "Linux/UNIX", "TotalInstanceCount": 3, "State": "active", "Tenancy": "default", "EbsOptimized": false, "InstanceType": "m5.large" } }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的创建容量预留

以下代码示例演示如何使用 create-carrier-gateway

AWS CLI

创建运营商网关

以下create-carrier-gateway示例为指定的创建运营商网关VPC。

aws ec2 create-carrier-gateway \ --vpc-id vpc-0c529aEXAMPLE1111

输出:

{ "CarrierGateway": { "CarrierGatewayId": "cagw-0465cdEXAMPLE1111", "VpcId": "vpc-0c529aEXAMPLE1111", "State": "pending", "OwnerId": "123456789012" } }

有关更多信息,请参阅《Waveleng AWS th 用户指南》中的运营商网关

以下代码示例演示如何使用 create-client-vpn-endpoint

AWS CLI

创建客户端VPN终端节点

以下create-client-vpn-endpoint示例创建了一个使用相互身份验证的客户端VPN端点,并指定了客户端CIDR块的值。

aws ec2 create-client-vpn-endpoint \ --client-cidr-block "172.31.0.0/16" \ --server-certificate-arn arn:aws:acm:ap-south-1:123456789012:certificate/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE \ --authentication-options Type=certificate-authentication,MutualAuthentication={ClientRootCertificateChainArn=arn:aws:acm:ap-south-1:123456789012:certificate/a1b2c3d4-5678-90ab-cdef-22222EXAMPLE} \ --connection-log-options Enabled=false

输出:

{ "ClientVpnEndpointId": "cvpn-endpoint-123456789123abcde", "Status": { "Code": "pending-associate" }, "DnsName": "cvpn-endpoint-123456789123abcde.prod.clientvpn.ap-south-1.amazonaws.com" }

有关更多信息,请参阅《客户机VPN管理员指南》中的AWS 客户端VPN端点

以下代码示例演示如何使用 create-client-vpn-route

AWS CLI

为客户端VPN终端节点创建路由

以下create-client-vpn-route示例为客户端VPN终端节点的指定子网添加了一条通往 Internet (0.0.0.0/0) 的路由。

aws ec2 create-client-vpn-route \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde \ --destination-cidr-block 0.0.0.0/0 \ --target-vpc-subnet-id subnet-0123456789abcabca

输出:

{ "Status": { "Code": "creating" } }

有关更多信息,请参阅《AWS 客户机VPN管理员指南》中的路由

以下代码示例演示如何使用 create-coip-cidr

AWS CLI

创建一系列客户拥有的 IP (CoIP) 地址

以下create-coip-cidr示例在指定的 CoIP 池中创建指定范围的 CoIP 地址。

aws ec2 create-coip-cidr \ --cidr 15.0.0.0/24 \ --coip-pool-id ipv4pool-coip-1234567890abcdefg

输出:

{ "CoipCidr": { "Cidr": "15.0.0.0/24", "CoipPoolId": "ipv4pool-coip-1234567890abcdefg", "LocalGatewayRouteTableId": "lgw-rtb-abcdefg1234567890" } }

有关更多信息,请参阅《AWS Outposts 用户指南》中的客户拥有的 IP 地址

以下代码示例演示如何使用 create-coip-pool

AWS CLI

创建客户拥有的 IP (CoIP) 地址池

以下create-coip-pool示例为指定的本地网关路由表中的 CoIP 地址创建 CoIP 池。

aws ec2 create-coip-pool \ --local-gateway-route-table-id lgw-rtb-abcdefg1234567890

输出:

{ "CoipPool": { "PoolId": "ipv4pool-coip-1234567890abcdefg", "LocalGatewayRouteTableId": "lgw-rtb-abcdefg1234567890", "PoolArn": "arn:aws:ec2:us-west-2:123456789012:coip-pool/ipv4pool-coip-1234567890abcdefg" } }

有关更多信息,请参阅《AWS Outposts 用户指南》中的客户拥有的 IP 地址

以下代码示例演示如何使用 create-customer-gateway

AWS CLI

创建客户网关

此示例使用指定的 IP 地址为其外部接口创建客户网关。

命令:

aws ec2 create-customer-gateway --type ipsec.1 --public-ip 12.1.2.3 --bgp-asn 65534

输出:

{ "CustomerGateway": { "CustomerGatewayId": "cgw-0e11f167", "IpAddress": "12.1.2.3", "State": "available", "Type": "ipsec.1", "BgpAsn": "65534" } }

以下代码示例演示如何使用 create-default-subnet

AWS CLI

创建默认子网

此示例在可用区中创建默认子网us-east-2a

命令:

aws ec2 create-default-subnet --availability-zone us-east-2a { "Subnet": { "AvailabilityZone": "us-east-2a", "Tags": [], "AvailableIpAddressCount": 4091, "DefaultForAz": true, "Ipv6CidrBlockAssociationSet": [], "VpcId": "vpc-1a2b3c4d", "State": "available", "MapPublicIpOnLaunch": true, "SubnetId": "subnet-1122aabb", "CidrBlock": "172.31.32.0/20", "AssignIpv6AddressOnCreation": false } }

以下代码示例演示如何使用 create-default-vpc

AWS CLI

创建默认值 VPC

此示例创建了一个默认值VPC。

命令:

aws ec2 create-default-vpc

输出:

{ "Vpc": { "VpcId": "vpc-8eaae5ea", "InstanceTenancy": "default", "Tags": [], "Ipv6CidrBlockAssociationSet": [], "State": "pending", "DhcpOptionsId": "dopt-af0c32c6", "CidrBlock": "172.31.0.0/16", "IsDefault": true } }

以下代码示例演示如何使用 create-dhcp-options

AWS CLI

创建一组DHCP选项

以下create-dhcp-options示例创建了一组DHCP选项,用于指定域名、域名服务器和网络BIOS节点类型。

aws ec2 create-dhcp-options \ --dhcp-configuration \ "Key=domain-name-servers,Values=10.2.5.1,10.2.5.2" \ "Key=domain-name,Values=example.com" \ "Key=netbios-node-type,Values=2"

输出:

{ "DhcpOptions": { "DhcpConfigurations": [ { "Key": "domain-name", "Values": [ { "Value": "example.com" } ] }, { "Key": "domain-name-servers", "Values": [ { "Value": "10.2.5.1" }, { "Value": "10.2.5.2" } ] }, { "Key": "netbios-node-type", "Values": [ { "Value": "2" } ] } ], "DhcpOptionsId": "dopt-06d52773eff4c55f3" } }

以下代码示例演示如何使用 create-egress-only-internet-gateway

AWS CLI

创建仅限出口的互联网网关

此示例为指定的创建仅限出站的 Internet 网关。VPC

命令:

aws ec2 create-egress-only-internet-gateway --vpc-id vpc-0c62a468

输出:

{ "EgressOnlyInternetGateway": { "EgressOnlyInternetGatewayId": "eigw-015e0e244e24dfe8a", "Attachments": [ { "State": "attached", "VpcId": "vpc-0c62a468" } ] } }

以下代码示例演示如何使用 create-fleet

AWS CLI

示例 1:创建启动竞价型实例作为默认购买模式的EC2队列

以下create-fleet示例使用启动EC2队列所需的最低参数创建队列:启动模板、目标容量和默认购买模式。启动模板由其启动模板 ID 和版本号标识。队列的目标容量为 2 个实例,默认购买模式为spot,这会导致队列启动 2 个竞价型实例。

创建EC2队列时,使用JSON文件指定要启动的实例的相关信息。

aws ec2 create-fleet \ --cli-input-json file://file_name.json

file_name.json 的内容:

{ "LaunchTemplateConfigs": [ { "LaunchTemplateSpecification": { "LaunchTemplateId": "lt-0e8c754449b27161c", "Version": "1" } } ], "TargetCapacitySpecification": { "TotalTargetCapacity": 2, "DefaultTargetCapacityType": "spot" } }

输出:

{ "FleetId": "fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE" }

示例 2:创建启动按需实例作为默认购买模式的EC2队列

以下create-fleet示例使用启动EC2队列所需的最低参数创建队列:启动模板、目标容量和默认购买模式。启动模板由其启动模板 ID 和版本号标识。队列的目标容量为 2 个实例,默认购买模式为on-demand,这会导致队列启动 2 个按需实例。

创建EC2队列时,使用JSON文件指定要启动的实例的相关信息。

aws ec2 create-fleet \ --cli-input-json file://file_name.json

file_name.json 的内容:

{ "LaunchTemplateConfigs": [ { "LaunchTemplateSpecification": { "LaunchTemplateId": "lt-0e8c754449b27161c", "Version": "1" } } ], "TargetCapacitySpecification": { "TotalTargetCapacity": 2, "DefaultTargetCapacityType": "on-demand" } }

输出:

{ "FleetId": "fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE" }

示例 3:创建以按需实例作为主容量启动的EC2队列

以下create-fleet示例创建了一个EC2队列,该队列指定队列的总目标容量为 2 个实例,目标容量为 1 个按需实例。默认的购买模式是spot。队列按指定启动 1 个按需实例,但需要再启动一个实例才能达到目标总容量。差额的购买模型计算为 TotalTargetCapacity-OnDemandTargetCapacity =DefaultTargetCapacityType,这会导致队列启动 1 个竞价型实例。

创建EC2队列时,使用JSON文件指定要启动的实例的相关信息。

aws ec2 create-fleet \ --cli-input-json file://file_name.json

file_name.json 的内容:

{ "LaunchTemplateConfigs": [ { "LaunchTemplateSpecification": { "LaunchTemplateId": "lt-0e8c754449b27161c", "Version": "1" } } ], "TargetCapacitySpecification": { "TotalTargetCapacity": 2, "OnDemandTargetCapacity":1, "DefaultTargetCapacityType": "spot" } }

输出:

{ "FleetId": "fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE" }

示例 4:创建使用最低EC2价格分配策略启动竞价型实例的队列

如果未指定 Spot 实例的分配策略,则使用默认分配策略 lowest-price。以下create-fleet示例使用lowest-price分配策略创建EC2舰队。覆盖启动模板的三个启动规范有不同的实例类型,但有相同的权重容量和子网。目标总容量为 2 个实例,默认购买模式为spot。EC2队列使用启动规范的实例类型启动 2 个 Spot 实例,价格最低。

创建EC2队列时,使用JSON文件指定要启动的实例的相关信息。

aws ec2 create-fleet \ --cli-input-json file://file_name.jsonContents of file_name.json:: { "LaunchTemplateConfigs": [ { "LaunchTemplateSpecification": { "LaunchTemplateId": "lt-0e8c754449b27161c", "Version": "1" }, "Overrides": [ { "InstanceType": "c4.large", "WeightedCapacity": 1, "SubnetId": "subnet-a4f6c5d3" }, { "InstanceType": "c3.large", "WeightedCapacity": 1, "SubnetId": "subnet-a4f6c5d3" }, { "InstanceType": "c5.large", "WeightedCapacity": 1, "SubnetId": "subnet-a4f6c5d3" } ] } ], "TargetCapacitySpecification": { "TotalTargetCapacity": 2, "DefaultTargetCapacityType": "spot" } }

输出:

{ "FleetId": "fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE" }

以下代码示例演示如何使用 create-flow-logs

AWS CLI

示例 1:创建流日志

以下create-flow-logs示例创建了一个流日志,用于捕获指定网络接口的所有被拒绝流量。使用指定IAM角色的权限将流日志传送到 Lo CloudWatch gs 中的日志组。

aws ec2 create-flow-logs \ --resource-type NetworkInterface \ --resource-ids eni-11223344556677889 \ --traffic-type REJECT \ --log-group-name my-flow-logs \ --deliver-logs-permission-arn arn:aws:iam::123456789101:role/publishFlowLogs

输出:

{ "ClientToken": "so0eNA2uSHUNlHI0S2cJ305GuIX1CezaRdGtexample", "FlowLogIds": [ "fl-12345678901234567" ], "Unsuccessful": [] }

有关更多信息,请参阅 Amazon VPC 用户指南中的VPC流日志

示例 2:使用自定义格式创建流日志

以下create-flow-logs示例创建了一个流日志,用于捕获指定的所有流量VPC并将流日志传输到 Amazon S3 存储桶。--log-format 参数指定流日志记录的自定义格式。要在 Windows 上运行此命令,请将单引号 (') 更改为双引号 (“)。

aws ec2 create-flow-logs \ --resource-type VPC \ --resource-ids vpc-00112233344556677 \ --traffic-type ALL \ --log-destination-type s3 \ --log-destination arn:aws:s3:::flow-log-bucket/my-custom-flow-logs/ \ --log-format '${version} ${vpc-id} ${subnet-id} ${instance-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${tcp-flags} ${type} ${pkt-srcaddr} ${pkt-dstaddr}'

有关更多信息,请参阅 Amazon VPC 用户指南中的VPC流日志

示例 3:创建最大聚合间隔为一分钟的流日志

以下create-flow-logs示例创建了一个流日志,用于捕获指定的所有流量VPC并将流日志传输到 Amazon S3 存储桶。该--max-aggregation-interval参数将最大聚合间隔指定为 60 秒(1 分钟)。

aws ec2 create-flow-logs \ --resource-type VPC \ --resource-ids vpc-00112233344556677 \ --traffic-type ALL \ --log-destination-type s3 \ --log-destination arn:aws:s3:::flow-log-bucket/my-custom-flow-logs/ \ --max-aggregation-interval 60

有关更多信息,请参阅 Amazon VPC 用户指南中的VPC流日志

以下代码示例演示如何使用 create-fpga-image

AWS CLI

创建 Amazon FPGA 图片

此示例AFI从指定存储桶中的指定压缩包中创建一个。

命令:

aws ec2 create-fpga-image --name my-afi --description test-afi --input-storage-location Bucket=my-fpga-bucket,Key=dcp/17_12_22-103226.Developer_CL.tar --logs-storage-location Bucket=my-fpga-bucket,Key=logs

输出:

{ "FpgaImageId": "afi-0d123e123bfc85abc", "FpgaImageGlobalId": "agfi-123cb27b5e84a0abc" }

以下代码示例演示如何使用 create-image

AWS CLI

示例 1:AMI从 Amazon EBS 支持的实例创建

以下create-image示例AMI从指定实例创建一个。

aws ec2 create-image \ --instance-id i-1234567890abcdef0 \ --name "My server" \ --description "An AMI for my server"

输出:

{ "ImageId": "ami-abcdef01234567890" }

有关为您指定块储存设备映射的更多信息AMI,请参阅 Amazon EC2 用户指南AMI中的为指定块储存设备映射

示例 2:在不重启的情况下AMI从由 Amazon EBS 支持的实例创建一个

以下create-image示例创建了一个AMI并设置了--no-reboot 参数,这样在创建映像之前就不会重新启动实例。

aws ec2 create-image \ --instance-id i-1234567890abcdef0 \ --name "My server" \ --no-reboot

输出:

{ "ImageId": "ami-abcdef01234567890" }

有关为您指定块储存设备映射的更多信息AMI,请参阅 Amazon EC2 用户指南AMI中的为指定块储存设备映射

示例 3:在创建时标记AMI和快照

以下create-image示例创建一个AMI,并使用相同的标签标记AMI和快照 cost-center=cc123

aws ec2 create-image \ --instance-id i-1234567890abcdef0 \ --name "My server" \ --tag-specifications "ResourceType=image,Tags=[{Key=cost-center,Value=cc123}]" "ResourceType=snapshot,Tags=[{Key=cost-center,Value=cc123}]"

输出:

{ "ImageId": "ami-abcdef01234567890" }

有关在创建资源时为资源添加标签的更多信息,请参阅 Amazon EC2 用户指南中的在资源创建时添加标签

以下代码示例演示如何使用 create-instance-connect-endpoint

AWS CLI

创建 Instance C EC2 onnect 端点

以下create-instance-connect-endpoint示例在指定子网中创建一个 In EC2 stance Connect 终端节点。

aws ec2 create-instance-connect-endpoint \ --region us-east-1 \ --subnet-id subnet-0123456789example

输出:

{ "VpcId": "vpc-0123abcd", "InstanceConnectEndpointArn": "arn:aws:ec2:us-east-1:111111111111:instance-connect-endpoint/eice-0123456789example", "AvailabilityZone": "us-east-1a", "NetworkInterfaceIds": [ "eni-0123abcd" ], "PreserveClientIp": true, "Tags": [], "FipsDnsName": "eice-0123456789example.0123abcd.fips.ec2-instance-connect-endpoint.us-east-1.amazonaws.com", "StateMessage": "", "State": "create-complete", "DnsName": "eice-0123456789example.0123abcd.ec2-instance-connect-endpoint.us-east-1.amazonaws.com", "SubnetId": "subnet-0123abcd", "OwnerId": "111111111111", "SecurityGroupIds": [ "sg-0123abcd" ], "InstanceConnectEndpointId": "eice-0123456789example", "CreatedAt": "2023-04-07T15:43:53.000Z" }

有关更多信息,请参阅 Amazon EC2 用户指南中的创EC2建 Instance Connect 终端节点

以下代码示例演示如何使用 create-instance-event-window

AWS CLI

示例 1:创建具有时间范围的事件窗口

以下create-instance-event-window示例创建了一个具有时间范围的事件窗口。您不能同时指定 cron-expression 参数。

aws ec2 create-instance-event-window \ --region us-east-1 \ --time-range StartWeekDay=monday,StartHour=2,EndWeekDay=wednesday,EndHour=8 \ --tag-specifications "ResourceType=instance-event-window,Tags=[{Key=K1,Value=V1}]" \ --name myEventWindowName

输出:

{ "InstanceEventWindow": { "InstanceEventWindowId": "iew-0abcdef1234567890", "TimeRanges": [ { "StartWeekDay": "monday", "StartHour": 2, "EndWeekDay": "wednesday", "EndHour": 8 } ], "Name": "myEventWindowName", "State": "creating", "Tags": [ { "Key": "K1", "Value": "V1" } ] } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

示例 2:使用 cron 表达式创建事件窗口

以下create-instance-event-window示例创建了一个带有 cron 表达式的事件窗口。您不能同时指定 time-range 参数。

aws ec2 create-instance-event-window \ --region us-east-1 \ --cron-expression "* 21-23 * * 2,3" \ --tag-specifications "ResourceType=instance-event-window,Tags=[{Key=K1,Value=V1}]" \ --name myEventWindowName

输出:

{ "InstanceEventWindow": { "InstanceEventWindowId": "iew-0abcdef1234567890", "Name": "myEventWindowName", "CronExpression": "* 21-23 * * 2,3", "State": "creating", "Tags": [ { "Key": "K1", "Value": "V1" } ] } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

以下代码示例演示如何使用 create-instance-export-task

AWS CLI

导出实例

此示例命令创建一个任务,用于将实例 i-1234567890abcdef0 导出到 Amazon S3 存储桶 myexportbucket。

命令:

aws ec2 create-instance-export-task --description "RHEL5 instance" --instance-id i-1234567890abcdef0 --target-environment vmware --export-to-s3-task DiskImageFormat=vmdk,ContainerFormat=ova,S3Bucket=myexportbucket,S3Prefix=RHEL5

输出:

{ "ExportTask": { "State": "active", "InstanceExportDetails": { "InstanceId": "i-1234567890abcdef0", "TargetEnvironment": "vmware" }, "ExportToS3Task": { "S3Bucket": "myexportbucket", "S3Key": "RHEL5export-i-fh8sjjsq.ova", "DiskImageFormat": "vmdk", "ContainerFormat": "ova" }, "Description": "RHEL5 instance", "ExportTaskId": "export-i-fh8sjjsq" } }

以下代码示例演示如何使用 create-internet-gateway

AWS CLI

创建互联网网关

以下create-internet-gateway示例使用标签创建互联网网关Name=my-igw

aws ec2 create-internet-gateway \ --tag-specifications ResourceType=internet-gateway,Tags=[{Key=Name,Value=my-igw}]

输出:

{ "InternetGateway": { "Attachments": [], "InternetGatewayId": "igw-0d0fb496b3994d755", "OwnerId": "123456789012", "Tags": [ { "Key": "Name", "Value": "my-igw" } ] } }

有关更多信息,请参阅 Amazon VPC 用户指南中的互联网网关

以下代码示例演示如何使用 create-ipam-pool

AWS CLI

创建IPAM池

以下create-ipam-pool示例创建了一个IPAM池。

(Linux):

aws ec2 create-ipam-pool \ --ipam-scope-id ipam-scope-02fc38cd4c48e7d38 \ --address-family ipv4 \ --auto-import \ --allocation-min-netmask-length 16 \ --allocation-max-netmask-length 26 \ --allocation-default-netmask-length 24 \ --allocation-resource-tags "Key=Environment,Value=Preprod" \ --tag-specifications 'ResourceType=ipam-pool,Tags=[{Key=Name,Value="Preprod pool"}]'

(视窗):

aws ec2 create-ipam-pool ^ --ipam-scope-id ipam-scope-02fc38cd4c48e7d38 ^ --address-family ipv4 ^ --auto-import ^ --allocation-min-netmask-length 16 ^ --allocation-max-netmask-length 26 ^ --allocation-default-netmask-length 24 ^ --allocation-resource-tags "Key=Environment,Value=Preprod" ^ --tag-specifications ResourceType=ipam-pool,Tags=[{Key=Name,Value="Preprod pool"}]

输出:

{ "IpamPool": { "OwnerId": "123456789012", "IpamPoolId": "ipam-pool-0533048da7d823723", "IpamPoolArn": "arn:aws:ec2::123456789012:ipam-pool/ipam-pool-0533048da7d823723", "IpamScopeArn": "arn:aws:ec2::123456789012:ipam-scope/ipam-scope-02fc38cd4c48e7d38", "IpamScopeType": "private", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-08440e7a3acde3908", "IpamRegion": "us-east-1", "Locale": "None", "PoolDepth": 1, "State": "create-in-progress", "AutoImport": true, "AddressFamily": "ipv4", "AllocationMinNetmaskLength": 16, "AllocationMaxNetmaskLength": 26, "AllocationDefaultNetmaskLength": 24, "AllocationResourceTags": [ { "Key": "Environment", "Value": "Preprod" } ], "Tags": [ { "Key": "Name", "Value": "Preprod pool" } ] } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的 IP 地址配置计划

以下代码示例演示如何使用 create-ipam-resource-discovery

AWS CLI

创建资源发现

在此示例中,您是一名委托IPAM管理员,想要创建资源发现并与其他 AWS 组织的IPAM管理员共享,以便其他组织中的管理员可以管理和监控您组织中资源的 IP 地址。

重要提示

此示例包括--region--operating-regions选项,因为虽然它们是可选的,但必须以特定的方式配置它们才能成功地将资源发现与IPAM。* --operating-regions 必须与您想要IPAM发现的资源所在的区域相匹配。如果有些区域您不IPAM想管理 IP 地址(例如出于合规性原因),请不要将其包括在内。* --region 必须与IPAM您要关联的所在区域匹配。您必须在创建资源发现的区域中创建资源发现。IPAM例如,如果您IPAM要关联的是在 us-east-1 中创建的,请在请求中--region us-east-1包含这些选项。如果您未指定,则两个--region--operating-regions和选项都默认为您运行命令的区域。

在此示例中,IPAM我们正在集成的操作区域包括us-west-1us-west-2、和ap-south-1。当我们创建资源发现时,我们IPAM希望发现us-west-1和中的资源 IP 地址,us-west-2但不是ap-south-1。因此,我们只包含--operating-regions RegionName='us-west-1' RegionName='us-west-2'在请求中。

以下create-ipam-resource-discovery示例创建了IPAM资源发现。

aws ec2 create-ipam-resource-discovery \ --description 'Example-resource-discovery' \ --tag-specifications 'ResourceType=ipam-resource-discovery,Tags=[{Key=cost-center,Value=cc123}]' \ --operating-regions RegionName='us-west-1' RegionName='us-west-2' \ --region us-east-1

输出:

{ "IpamResourceDiscovery":{ "OwnerId": "149977607591", "IpamResourceDiscoveryId": "ipam-res-disco-0257046d8aa78b8bc", "IpamResourceDiscoveryArn": "arn:aws:ec2::149977607591:ipam-resource-discovery/ipam-res-disco-0257046d8aa78b8bc", "IpamResourceDiscoveryRegion": "us-east-1", "Description": "'Example-resource-discovery'", "OperatingRegions":[ {"RegionName": "us-west-1"}, {"RegionName": "us-west-2"}, {"RegionName": "us-east-1"} ], "IsDefault": false, "State": "create-in-progress", "Tags": [ { "Key": "cost-center", "Value": "cc123" } ] }

创建资源发现后,您可能需要与其他IPAM委托管理员共享,您可以这样做create-resource-share。有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的IPAM与组织外部账户集成

以下代码示例演示如何使用 create-ipam-scope

AWS CLI

创建IPAM作用域

以下create-ipam-scope示例创建了一个IPAM作用域。

(Linux):

aws ec2 create-ipam-scope \ --ipam-id ipam-08440e7a3acde3908 \ --description "Example description" \ --tag-specifications 'ResourceType=ipam-scope,Tags=[{Key=Name,Value="Example name value"}]'

(视窗):

aws ec2 create-ipam-scope ^ --ipam-id ipam-08440e7a3acde3908 ^ --description "Example description" ^ --tag-specifications ResourceType=ipam-scope,Tags=[{Key=Name,Value="Example name value"}]

输出:

{ "IpamScope": { "OwnerId": "123456789012", "IpamScopeId": "ipam-scope-01c1ebab2b63bd7e4", "IpamScopeArn": "arn:aws:ec2::123456789012:ipam-scope/ipam-scope-01c1ebab2b63bd7e4", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-08440e7a3acde3908", "IpamRegion": "us-east-1", "IpamScopeType": "private", "IsDefault": false, "Description": "Example description", "PoolCount": 0, "State": "create-in-progress", "Tags": [ { "Key": "Name", "Value": "Example name value" } ] } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的创建其他范围

以下代码示例演示如何使用 create-ipam

AWS CLI

要创建 IPAM

以下create-ipam示例创建了一个IPAM。

(Linux):

aws ec2 create-ipam \ --description "Example description" \ --operating-regions "RegionName=us-east-2" "RegionName=us-west-1" \ --tag-specifications 'ResourceType=ipam,Tags=[{Key=Name,Value=ExampleIPAM}]'

(视窗):

aws ec2 create-ipam ^ --description "Example description" ^ --operating-regions "RegionName=us-east-2" "RegionName=us-west-1" ^ --tag-specifications ResourceType=ipam,Tags=[{Key=Name,Value=ExampleIPAM}]

输出:

{ "Ipam": { "OwnerId": "123456789012", "IpamId": "ipam-036486dfa6af58ee0", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-036486dfa6af58ee0", "IpamRegion": "us-east-1", "PublicDefaultScopeId": "ipam-scope-071b8042b0195c183", "PrivateDefaultScopeId": "ipam-scope-0807405dece705a30", "ScopeCount": 2, "OperatingRegions": [ { "RegionName": "us-east-2" }, { "RegionName": "us-west-1" }, { "RegionName": "us-east-1" } ], "State": "create-in-progress", "Tags": [ { "Key": "Name", "Value": "ExampleIPAM" } ] } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南IPAM中的创建

以下代码示例演示如何使用 create-key-pair

AWS CLI

创建密钥对

本示例将创建一个名为 MyKeyPair 的密钥对。

命令:

aws ec2 create-key-pair --key-name MyKeyPair

输出是私钥和密钥指纹的ASCII版本。需要将密钥保存到文件中。

有关更多信息,请参阅《AWS 命令行界面用户指南》中的“使用密钥对”。

以下代码示例演示如何使用 create-launch-template-version

AWS CLI

创建启动模板版本

此示例基于启动模板的版本 1 创建新的启动模板版本并指定了不同的 AMI ID。

命令:

aws ec2 create-launch-template-version --launch-template-id lt-0abcd290751193123 --version-description WebVersion2 --source-version 1 --launch-template-data '{"ImageId":"ami-c998b6b2"}'

输出:

{ "LaunchTemplateVersion": { "VersionDescription": "WebVersion2", "LaunchTemplateId": "lt-0abcd290751193123", "LaunchTemplateName": "WebServers", "VersionNumber": 2, "CreatedBy": "arn:aws:iam::123456789012:root", "LaunchTemplateData": { "ImageId": "ami-c998b6b2", "InstanceType": "t2.micro", "NetworkInterfaces": [ { "Ipv6Addresses": [ { "Ipv6Address": "2001:db8:1234:1a00::123" } ], "DeviceIndex": 0, "SubnetId": "subnet-7b16de0c", "AssociatePublicIpAddress": true } ] }, "DefaultVersion": false, "CreateTime": "2017-12-01T13:35:46.000Z" } }

以下代码示例演示如何使用 create-launch-template

AWS CLI

示例 1:创建启动模板

以下create-launch-template示例创建了一个启动模板,该模板指定了启动实例的子网,为该实例分配了公有 IP IPv6 地址和地址,并为该实例创建了标签。

aws ec2 create-launch-template \ --launch-template-name TemplateForWebServer \ --version-description WebVersion1 \ --launch-template-data '{"NetworkInterfaces":[{"AssociatePublicIpAddress":true,"DeviceIndex":0,"Ipv6AddressCount":1,"SubnetId":"subnet-7b16de0c"}],"ImageId":"ami-8c1be5f6","InstanceType":"t2.small","TagSpecifications":[{"ResourceType":"instance","Tags":[{"Key":"purpose","Value":"webserver"}]}]}'

输出:

{ "LaunchTemplate": { "LatestVersionNumber": 1, "LaunchTemplateId": "lt-01238c059e3466abc", "LaunchTemplateName": "TemplateForWebServer", "DefaultVersionNumber": 1, "CreatedBy": "arn:aws:iam::123456789012:user/Bob", "CreateTime": "2019-01-27T09:13:24.000Z" } }

有关更多信息,请参阅《Amazon Elastic Compute Cloud 用户指南》中的“从启动模板启动实例”。有关引用JSON格式参数的信息,请参阅《AWS 命令行界面用户指南》中的引用字符串。

示例 2:为 Amazon A EC2 uto Scaling 创建启动模板

以下create-launch-template示例创建了一个包含多个标签和块储存设备映射的启动模板,用于在实例启动时指定额外的EBS卷。为指定一个Groups与 Auto Scaling 组要启动实例的安全组相对应的值。VPC将VPC和子网指定为 Auto Scaling 组的属性。

aws ec2 create-launch-template \ --launch-template-name TemplateForAutoScaling \ --version-description AutoScalingVersion1 \ --launch-template-data '{"NetworkInterfaces":[{"DeviceIndex":0,"AssociatePublicIpAddress":true,"Groups":["sg-7c227019,sg-903004f8"],"DeleteOnTermination":true}],"ImageId":"ami-b42209de","InstanceType":"m4.large","TagSpecifications":[{"ResourceType":"instance","Tags":[{"Key":"environment","Value":"production"},{"Key":"purpose","Value":"webserver"}]},{"ResourceType":"volume","Tags":[{"Key":"environment","Value":"production"},{"Key":"cost-center","Value":"cc123"}]}],"BlockDeviceMappings":[{"DeviceName":"/dev/sda1","Ebs":{"VolumeSize":100}}]}' --region us-east-1

输出:

{ "LaunchTemplate": { "LatestVersionNumber": 1, "LaunchTemplateId": "lt-0123c79c33a54e0abc", "LaunchTemplateName": "TemplateForAutoScaling", "DefaultVersionNumber": 1, "CreatedBy": "arn:aws:iam::123456789012:user/Bob", "CreateTime": "2019-04-30T18:16:06.000Z" } }

有关更多信息,请参阅 Amazon Auto Scaling 用户指南中的为 Aut EC2 o S caling 组创建启动模板。有关引用JSON格式参数的信息,请参阅《AWS 命令行界面用户指南》中的引用字符串。

示例 3:创建指定EBS卷加密的启动模板

以下create-launch-template示例创建了一个启动模板,其中包含根据未加密快照创建的加密EBS卷。同时还会在创建过程中标记卷。如果默认情况下禁用了加密,则必须指定以下示例中所示的 "Encrypted" 选项。如果您使用该"KmsKeyId"选项来指定客户托管CMK,则即使默认启用了加密,也必须指定该"Encrypted"选项。

aws ec2 create-launch-template \ --launch-template-name TemplateForEncryption \ --launch-template-data file://config.json

config.json 的内容:

{ "BlockDeviceMappings":[ { "DeviceName":"/dev/sda1", "Ebs":{ "VolumeType":"gp2", "DeleteOnTermination":true, "SnapshotId":"snap-066877671789bd71b", "Encrypted":true, "KmsKeyId":"arn:aws:kms:us-east-1:012345678910:key/abcd1234-a123-456a-a12b-a123b4cd56ef" } } ], "ImageId":"ami-00068cd7555f543d5", "InstanceType":"c5.large", "TagSpecifications":[ { "ResourceType":"volume", "Tags":[ { "Key":"encrypted", "Value":"yes" } ] } ] }

输出:

{ "LaunchTemplate": { "LatestVersionNumber": 1, "LaunchTemplateId": "lt-0d5bd51bcf8530abc", "LaunchTemplateName": "TemplateForEncryption", "DefaultVersionNumber": 1, "CreatedBy": "arn:aws:iam::123456789012:user/Bob", "CreateTime": "2020-01-07T19:08:36.000Z" } }

有关更多信息,请参阅《亚马逊弹性计算云用户指南》中的从快照恢复亚马逊EBS卷和默认加密。

以下代码示例演示如何使用 create-local-gateway-route-table-virtual-interface-group-association

AWS CLI

将本地网关路由表与虚拟接口 (VIFs) 组关联

以下create-local-gateway-route-table-virtual-interface-group-association示例在指定的本地网关路由表和VIF组之间创建关联。

aws ec2 create-local-gateway-route-table-virtual-interface-group-association \ --local-gateway-route-table-id lgw-rtb-exampleidabcd1234 \ --local-gateway-virtual-interface-group-id lgw-vif-grp-exampleid0123abcd

输出:

{ "LocalGatewayRouteTableVirtualInterfaceGroupAssociation": { "LocalGatewayRouteTableVirtualInterfaceGroupAssociationId": "lgw-vif-grp-assoc-exampleid12345678", "LocalGatewayVirtualInterfaceGroupId": "lgw-vif-grp-exampleid0123abcd", "LocalGatewayId": "lgw-exampleid11223344", "LocalGatewayRouteTableId": "lgw-rtb-exampleidabcd1234", "LocalGatewayRouteTableArn": "arn:aws:ec2:us-west-2:111122223333:local-gateway-route-table/lgw-rtb-exampleidabcd1234", "OwnerId": "111122223333", "State": "pending", "Tags": [] } }

有关更多信息,请参阅 AWS Outposts 用户指南中的VIF群组关联

以下代码示例演示如何使用 create-local-gateway-route-table-vpc-association

AWS CLI

将 a VPC 与路由表关联

以下create-local-gateway-route-table-vpc-association示例将指定的VPC与指定的本地网关路由表相关联。

aws ec2 create-local-gateway-route-table-vpc-association \ --local-gateway-route-table-id lgw-rtb-059615ef7dEXAMPLE \ --vpc-id vpc-07ef66ac71EXAMPLE

输出:

{ "LocalGatewayRouteTableVpcAssociation": { "LocalGatewayRouteTableVpcAssociationId": "lgw-vpc-assoc-0ee765bcc8EXAMPLE", "LocalGatewayRouteTableId": "lgw-rtb-059615ef7dEXAMPLE", "LocalGatewayId": "lgw-09b493aa7cEXAMPLE", "VpcId": "vpc-07ef66ac71EXAMPLE", "State": "associated" } }

以下代码示例演示如何使用 create-local-gateway-route-table

AWS CLI

创建本地网关路由表

以下create-local-gateway-route-table示例使用直接VPC路由模式创建本地网关路由表。

aws ec2 create-local-gateway-route-table \ --local-gateway-id lgw-1a2b3c4d5e6f7g8h9 \ --mode direct-vpc-routing

输出:

{ "LocalGatewayRouteTable": { "LocalGatewayRouteTableId": "lgw-rtb-abcdefg1234567890", "LocalGatewayRouteTableArn": "arn:aws:ec2:us-west-2:111122223333:local-gateway-route-table/lgw-rtb-abcdefg1234567890", "LocalGatewayId": "lgw-1a2b3c4d5e6f7g8h9", "OutpostArn": "arn:aws:outposts:us-west-2:111122223333:outpost/op-021345abcdef67890", "OwnerId": "111122223333", "State": "pending", "Tags": [], "Mode": "direct-vpc-routing" } }

有关更多信息,请参阅《AWS Outposts 用户指南》中的本地网关路由表

以下代码示例演示如何使用 create-local-gateway-route

AWS CLI

为本地网关路由表创建静态路由

以下create-local-gateway-route示例在指定的本地网关路由表中创建指定的路由。

aws ec2 create-local-gateway-route \ --destination-cidr-block 0.0.0.0/0 \ --local-gateway-route-table-id lgw-rtb-059615ef7dEXAMPLE

输出:

{ "Route": { "DestinationCidrBlock": "0.0.0.0/0", "LocalGatewayVirtualInterfaceGroupId": "lgw-vif-grp-07145b276bEXAMPLE", "Type": "static", "State": "deleted", "LocalGatewayRouteTableId": "lgw-rtb-059615ef7dEXAMPLE" } }

以下代码示例演示如何使用 create-managed-prefix-list

AWS CLI

创建前缀列表

以下create-managed-prefix-list示例创建一个最多包含 10 个条目的IPv4前缀列表,并在前缀列表中创建 2 个条目。

aws ec2 create-managed-prefix-list \ --address-family IPv4 \ --max-entries 10 \ --entries Cidr=10.0.0.0/16,Description=vpc-a Cidr=10.2.0.0/16,Description=vpc-b \ --prefix-list-name vpc-cidrs

输出:

{ "PrefixList": { "PrefixListId": "pl-0123456abcabcabc1", "AddressFamily": "IPv4", "State": "create-in-progress", "PrefixListArn": "arn:aws:ec2:us-west-2:123456789012:prefix-list/pl-0123456abcabcabc1", "PrefixListName": "vpc-cidrs", "MaxEntries": 10, "Version": 1, "Tags": [], "OwnerId": "123456789012" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的托管前缀列表

以下代码示例演示如何使用 create-nat-gateway

AWS CLI

示例 1:创建公共NAT网关

以下create-nat-gateway示例在指定子NAT网中创建公有网关,并将弹性 IP 地址与指定的分配 ID 关联起来。创建公共NAT网关时,必须关联弹性 IP 地址。

aws ec2 create-nat-gateway \ --subnet-id subnet-0250c25a1fEXAMPLE \ --allocation-id eipalloc-09ad461b0dEXAMPLE

输出:

{ "NatGateway": { "CreateTime": "2021-12-01T22:22:38.000Z", "NatGatewayAddresses": [ { "AllocationId": "eipalloc-09ad461b0dEXAMPLE" } ], "NatGatewayId": "nat-0c61bf8a12EXAMPLE", "State": "pending", "SubnetId": "subnet-0250c25a1fEXAMPLE", "VpcId": "vpc-0a60eb65b4EXAMPLE", "ConnectivityType": "public" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的NAT网关

示例 2:创建私有NAT网关

以下create-nat-gateway示例在指定子NAT网中创建私有网关。私有NAT网关没有关联的弹性 IP 地址。

aws ec2 create-nat-gateway \ --subnet-id subnet-0250c25a1fEXAMPLE \ --connectivity-type private

输出:

{ "NatGateway": { "CreateTime": "2021-12-01T22:26:00.000Z", "NatGatewayAddresses": [ {} ], "NatGatewayId": "nat-011b568379EXAMPLE", "State": "pending", "SubnetId": "subnet-0250c25a1fEXAMPLE", "VpcId": "vpc-0a60eb65b4EXAMPLE", "ConnectivityType": "private" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的NAT网关

以下代码示例演示如何使用 create-network-acl-entry

AWS CLI

创建网络ACL条目

此示例为指定的网络创建了一个条目ACL。该规则允许从UDP端口 53 () 上的任何IPv4地址 (0.0.0.0/0) 进入任何关联子网的入口流量。DNS如果命令成功,则不返回任何输出。

命令:

aws ec2 create-network-acl-entry --network-acl-id acl-5fb85d36 --ingress --rule-number 100 --protocol udp --port-range From=53,To=53 --cidr-block 0.0.0.0/0 --rule-action allow

此示例为指定网络创建了一条规则ACL,该规则允许来自端口 80 () 上的任何IPv6地址 (:: /0) 的入TCP口流量。HTTP

命令:

aws ec2 create-network-acl-entry --network-acl-id acl-5fb85d36 --ingress --rule-number 120 --protocol tcp --port-range From=80,To=80 --ipv6-cidr-block ::/0 --rule-action allow

以下代码示例演示如何使用 create-network-acl

AWS CLI

创建网络 ACL

此示例ACL为指定的创建网络VPC。

命令:

aws ec2 create-network-acl --vpc-id vpc-a01106c2

输出:

{ "NetworkAcl": { "Associations": [], "NetworkAclId": "acl-5fb85d36", "VpcId": "vpc-a01106c2", "Tags": [], "Entries": [ { "CidrBlock": "0.0.0.0/0", "RuleNumber": 32767, "Protocol": "-1", "Egress": true, "RuleAction": "deny" }, { "CidrBlock": "0.0.0.0/0", "RuleNumber": 32767, "Protocol": "-1", "Egress": false, "RuleAction": "deny" } ], "IsDefault": false } }

以下代码示例演示如何使用 create-network-insights-access-scope

AWS CLI

创建网络访问范围

以下create-network-insights-access-scope示例创建了网络访问范围。

aws ec2 create-network-insights-access-scope \ --cli-input-json file://access-scope-file.json

access-scope-file.json 的内容:

{ "MatchPaths": [ { "Source": { "ResourceStatement": { "Resources": [ "vpc-abcd12e3" ] } } } ], "ExcludePaths": [ { "Source": { "ResourceStatement": { "ResourceTypes": [ "AWS::EC2::InternetGateway" ] } } } ] }

输出:

{ "NetworkInsightsAccessScope": { "NetworkInsightsAccessScopeId": "nis-123456789abc01234", "NetworkInsightsAccessScopeArn": "arn:aws:ec2:us-east-1:123456789012:network-insights-access-scope/nis-123456789abc01234", "CreatedDate": "2022-01-25T19:20:28.796000+00:00", "UpdatedDate": "2022-01-25T19:20:28.797000+00:00" }, "NetworkInsightsAccessScopeContent": { "NetworkInsightsAccessScopeId": "nis-123456789abc01234", "MatchPaths": [ { "Source": { "ResourceStatement": { "Resources": [ "vpc-abcd12e3" ] } } } ], "ExcludePaths": [ { "Source": { "ResourceStatement": { "ResourceTypes": [ "AWS::EC2::InternetGateway" ] } } } ] } }

有关更多信息,请参阅《网络访问分析器指南》 AWS CLI中的 “网络访问分析器入”。

以下代码示例演示如何使用 create-network-insights-path

AWS CLI

创建路径

以下create-network-insights-path示例创建了一条路径。源是指定的互联网网关,目的地是指定的EC2实例。要确定是否可以使用指定的协议和端口到达目的地,请使用start-network-insights-analysis命令分析路径。

aws ec2 create-network-insights-path \ --source igw-0797cccdc9d73b0e5 \ --destination i-0495d385ad28331c7 \ --destination-port 22 \ --protocol TCP

输出:

{ "NetworkInsightsPaths": { "NetworkInsightsPathId": "nip-0b26f224f1d131fa8", "NetworkInsightsPathArn": "arn:aws:ec2:us-east-1:123456789012:network-insights-path/nip-0b26f224f1d131fa8", "CreatedDate": "2021-01-20T22:43:46.933Z", "Source": "igw-0797cccdc9d73b0e5", "Destination": "i-0495d385ad28331c7", "Protocol": "tcp" } }

有关更多信息,请参阅 Reach ability Analy AWS CLI zer 指南中的入门使用指南。

以下代码示例演示如何使用 create-network-interface-permission

AWS CLI

创建网络接口权限

此示例向账户授予将网络接口附加123456789012eni-1a2b3c4d到实例的权限。

命令:

aws ec2 create-network-interface-permission --network-interface-id eni-1a2b3c4d --aws-account-id 123456789012 --permission INSTANCE-ATTACH

输出:

{ "InterfacePermission": { "PermissionState": { "State": "GRANTED" }, "NetworkInterfacePermissionId": "eni-perm-06fd19020ede149ea", "NetworkInterfaceId": "eni-1a2b3c4d", "Permission": "INSTANCE-ATTACH", "AwsAccountId": "123456789012" } }

以下代码示例演示如何使用 create-network-interface

AWS CLI

示例 1:为网络接口指定IPv4地址

以下create-network-interface示例使用指定的主IPv4地址为指定子网创建网络接口。

aws ec2 create-network-interface \ --subnet-id subnet-00a24d0d67acf6333 \ --description "my network interface" \ --groups sg-09dfba7ed20cda78b \ --private-ip-address 10.0.8.17

输出:

{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "Description": "my network interface", "Groups": [ { "GroupName": "my-security-group", "GroupId": "sg-09dfba7ed20cda78b" } ], "InterfaceType": "interface", "Ipv6Addresses": [], "MacAddress": "06:6a:0f:9a:49:37", "NetworkInterfaceId": "eni-0492b355f0cf3b3f8", "OwnerId": "123456789012", "PrivateDnsName": "ip-10-0-8-18.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.17", "PrivateIpAddresses": [ { "Primary": true, "PrivateDnsName": "ip-10-0-8-17.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.17" } ], "RequesterId": "AIDA4Z3Y7GSXTMEXAMPLE", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-00a24d0d67acf6333", "TagSet": [], "VpcId": "vpc-02723a0feeeb9d57b" } }

示例 2:使用IPv4地址和地址创建网络接口 IPv6

以下create-network-interface示例使用由 Amazon 选择IPv4的地址和地址为指定子网创建网络接口EC2。IPv6

aws ec2 create-network-interface \ --subnet-id subnet-00a24d0d67acf6333 \ --description "my dual stack network interface" \ --ipv6-address-count 1 \ --groups sg-09dfba7ed20cda78b

输出:

{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "Description": "my dual stack network interface", "Groups": [ { "GroupName": "my-security-group", "GroupId": "sg-09dfba7ed20cda78b" } ], "InterfaceType": "interface", "Ipv6Addresses": [ { "Ipv6Address": "2600:1f13:cfe:3650:a1dc:237c:393a:4ba7", "IsPrimaryIpv6": false } ], "MacAddress": "06:b8:68:d2:b2:2d", "NetworkInterfaceId": "eni-05da417453f9a84bf", "OwnerId": "123456789012", "PrivateDnsName": "ip-10-0-8-18.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.18", "PrivateIpAddresses": [ { "Primary": true, "PrivateDnsName": "ip-10-0-8-18.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.18" } ], "RequesterId": "AIDA4Z3Y7GSXTMEXAMPLE", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-00a24d0d67acf6333", "TagSet": [], "VpcId": "vpc-02723a0feeeb9d57b", "Ipv6Address": "2600:1f13:cfe:3650:a1dc:237c:393a:4ba7" } }

示例 3:使用连接跟踪配置选项创建网络接口

以下create-network-interface示例创建了一个网络接口并配置了空闲连接跟踪超时。

aws ec2 create-network-interface \ --subnet-id subnet-00a24d0d67acf6333 \ --groups sg-02e57dbcfe0331c1b \ --connection-tracking-specification TcpEstablishedTimeout=86400,UdpTimeout=60

输出:

{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "ConnectionTrackingConfiguration": { "TcpEstablishedTimeout": 86400, "UdpTimeout": 60 }, "Description": "", "Groups": [ { "GroupName": "my-security-group", "GroupId": "sg-02e57dbcfe0331c1b" } ], "InterfaceType": "interface", "Ipv6Addresses": [], "MacAddress": "06:4c:53:de:6d:91", "NetworkInterfaceId": "eni-0c133586e08903d0b", "OwnerId": "123456789012", "PrivateDnsName": "ip-10-0-8-94.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.94", "PrivateIpAddresses": [ { "Primary": true, "PrivateDnsName": "ip-10-0-8-94.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.94" } ], "RequesterId": "AIDA4Z3Y7GSXTMEXAMPLE", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-00a24d0d67acf6333", "TagSet": [], "VpcId": "vpc-02723a0feeeb9d57b" } }

示例 4:创建弹性结构适配器

以下create-network-interface示例创建了一个EFA。

aws ec2 create-network-interface \ --interface-type efa \ --subnet-id subnet-00a24d0d67acf6333 \ --description "my efa" \ --groups sg-02e57dbcfe0331c1b

输出:

{ "NetworkInterface": { "AvailabilityZone": "us-west-2a", "Description": "my efa", "Groups": [ { "GroupName": "my-efa-sg", "GroupId": "sg-02e57dbcfe0331c1b" } ], "InterfaceType": "efa", "Ipv6Addresses": [], "MacAddress": "06:d7:a4:f7:4d:57", "NetworkInterfaceId": "eni-034acc2885e862b65", "OwnerId": "123456789012", "PrivateDnsName": "ip-10-0-8-180.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.180", "PrivateIpAddresses": [ { "Primary": true, "PrivateDnsName": "ip-10-0-8-180.us-west-2.compute.internal", "PrivateIpAddress": "10.0.8.180" } ], "RequesterId": "AIDA4Z3Y7GSXTMEXAMPLE", "RequesterManaged": false, "SourceDestCheck": true, "Status": "pending", "SubnetId": "subnet-00a24d0d67acf6333", "TagSet": [], "VpcId": "vpc-02723a0feeeb9d57b" } }

有关更多信息,请参阅 Amazon EC2 用户指南中的弹性网络接口

以下代码示例演示如何使用 create-placement-group

AWS CLI

创建置放群组

此示例命令使用指定名称创建置放群组。

命令:

aws ec2 create-placement-group --group-name my-cluster --strategy cluster

创建分区置放群组

此示例命令创建一个名HDFS-Group-A为五个分区的分区置放组。

命令:

aws ec2 create-placement-group --group-name HDFS-Group-A --strategy partition --partition-count 5

以下代码示例演示如何使用 create-replace-root-volume-task

AWS CLI

示例 1:将根卷恢复到其初始启动状态

以下create-replace-root-volume-task示例将实例 i-0123456789abcdefa 的根卷恢复到其初始启动状态。

aws ec2 create-replace-root-volume-task \ --instance-id i-0123456789abcdefa

输出:

{ "ReplaceRootVolumeTask": { "InstanceId": "i-0123456789abcdefa", "ReplaceRootVolumeTaskId": "replacevol-0111122223333abcd", "TaskState": "pending", "StartTime": "2022-03-14T15:06:38Z", "Tags": [] } }

有关更多信息,请参阅 Amazon 弹性计算云用户指南中的替换根卷

示例 2:将根卷恢复到特定快照

以下create-replace-root-volume-task示例将实例 i-0123456789abcdefa 的根卷恢复到快照 snap-0abcdef1234567890。

aws ec2 create-replace-root-volume-task \ --instance-id i-0123456789abcdefa \ --snapshot-id snap-0abcdef1234567890

输出:

{ "ReplaceRootVolumeTask": { "InstanceId": "i-0123456789abcdefa", "ReplaceRootVolumeTaskId": "replacevol-0555566667777abcd", "TaskState": "pending", "StartTime": "2022-03-14T15:16:28Z", "Tags": [] } }

有关更多信息,请参阅 Amazon 弹性计算云用户指南中的替换根卷

以下代码示例演示如何使用 create-reserved-instances-listing

AWS CLI

在预留实例 Marketplace 上架预留实例

以下create-reserved-instances-listing示例在预留实例 Marketplace 中创建了指定预留实例的清单。

aws ec2 create-reserved-instances-listing \ --reserved-instances-id 5ec28771-05ff-4b9b-aa31-9e57dexample \ --instance-count 3 \ --price-schedules CurrencyCode=USD,Price=25.50 \ --client-token 550e8400-e29b-41d4-a716-446655440000

以下代码示例演示如何使用 create-restore-image-task

AWS CLI

AMI从 S3 存储桶中恢复

以下create-restore-image-task示例AMI从 S3 存储桶中恢复。使用describe-store-image-tasks输出S3ObjectKey `` and ``Bucket中的值,指定对象密钥AMI和复制到的 S3 存储桶的名称,然后指定AMI已恢复的存储桶的名称AMI。该账户的名称AMIs在该地区必须是唯一的。恢复者AMI将获得一个新的AMI身份证。

aws ec2 create-restore-image-task \ --object-key ami-1234567890abcdef0.bin \ --bucket my-ami-bucket \ --name "New AMI Name"

输出:

{ "ImageId": "ami-0eab20fe36f83e1a8" }

有关使用 S3 存储和恢复的更多信息,请参阅亚马逊AMI用户指南中的使用 S3 <https://docs.aws.amazon.com/AWS EC2/latest/UserGuide/ami-store-restore.html> 存储和还原。AMI EC2

以下代码示例演示如何使用 create-route-table

AWS CLI

创建路由表

此示例为指定的创建路由表VPC。

命令:

aws ec2 create-route-table --vpc-id vpc-a01106c2

输出:

{ "RouteTable": { "Associations": [], "RouteTableId": "rtb-22574640", "VpcId": "vpc-a01106c2", "PropagatingVgws": [], "Tags": [], "Routes": [ { "GatewayId": "local", "DestinationCidrBlock": "10.0.0.0/16", "State": "active" } ] } }

以下代码示例演示如何使用 create-route

AWS CLI

创建路线

此示例为指定的路由表创建路由。该路由匹配所有IPv4流量 (0.0.0.0/0),并将其路由到指定的 Internet 网关。如果命令成功,则不返回任何输出。

命令:

aws ec2 create-route --route-table-id rtb-22574640 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-c0a643a9

此示例命令在路由表 rtb-g8ff4ea2 中创建路由。该路由匹配IPv4CIDR区块 10.0.0.0/16 的流量并将其路由到对等连接 VPC pcx-111aaa22。通过此路由,可以将流量定向到对等连接VPC中的VPC对等体。如果命令成功,则不返回任何输出。

命令:

aws ec2 create-route --route-table-id rtb-g8ff4ea2 --destination-cidr-block 10.0.0.0/16 --vpc-peering-connection-id pcx-1a2b3c4d

此示例在指定的路由表中创建一条匹配所有IPv6流量 (::/0) 的路由,并将其路由到指定的仅限出口 Internet 网关。

命令:

aws ec2 create-route --route-table-id rtb-dce620b8 --destination-ipv6-cidr-block ::/0 --egress-only-internet-gateway-id eigw-01eadbd45ecd7943f

以下代码示例演示如何使用 create-security-group

AWS CLI

为 EC2-Classic 创建安全组

本示例将创建一个名为 MySecurityGroup 的安全组。

命令:

aws ec2 create-security-group --group-name MySecurityGroup --description "My security group"

输出:

{ "GroupId": "sg-903004f8" }

要为 EC2-创建安全组 VPC

此示例为指定的创建了一个名MySecurityGroup为的安全组VPC。

命令:

aws ec2 create-security-group --group-name MySecurityGroup --description "My security group" --vpc-id vpc-1a2b3c4d

输出:

{ "GroupId": "sg-903004f8" }

有关更多信息,请参阅《AWS 命令行界面用户指南》中的“使用安全组”。

以下代码示例演示如何使用 create-snapshot

AWS CLI

创建快照

此示例命令创建卷的快照,卷 ID 为,vol-1234567890abcdef0并附上用于识别快照的简短描述。

命令:

aws ec2 create-snapshot --volume-id vol-1234567890abcdef0 --description "This is my root volume snapshot"

输出:

{ "Description": "This is my root volume snapshot", "Tags": [], "Encrypted": false, "VolumeId": "vol-1234567890abcdef0", "State": "pending", "VolumeSize": 8, "StartTime": "2018-02-28T21:06:01.000Z", "Progress": "", "OwnerId": "012345678910", "SnapshotId": "snap-066877671789bd71b" }

创建带有标签的快照

此示例命令创建快照并应用两个标签:purpose=prod 和 costcenter=123。

命令:

aws ec2 create-snapshot --volume-id vol-1234567890abcdef0 --description 'Prod backup' --tag-specifications 'ResourceType=snapshot,Tags=[{Key=purpose,Value=prod},{Key=costcenter,Value=123}]'

输出:

{ "Description": "Prod backup", "Tags": [ { "Value": "prod", "Key": "purpose" }, { "Value": "123", "Key": "costcenter" } ], "Encrypted": false, "VolumeId": "vol-1234567890abcdef0", "State": "pending", "VolumeSize": 8, "StartTime": "2018-02-28T21:06:06.000Z", "Progress": "", "OwnerId": "012345678910", "SnapshotId": "snap-09ed24a70bc19bbe4" }

以下代码示例演示如何使用 create-snapshots

AWS CLI

示例 1:创建多卷快照

以下create-snapshots示例创建连接到指定实例的所有卷的快照。

aws ec2 create-snapshots \ --instance-specification InstanceId=i-1234567890abcdef0 \ --description "This is snapshot of a volume from my-instance"

输出:

{ "Snapshots": [ { "Description": "This is a snapshot of a volume from my-instance", "Tags": [], "Encrypted": false, "VolumeId": "vol-0a01d2d5a34697479", "State": "pending", "VolumeSize": 16, "StartTime": "2019-08-05T16:58:19.000Z", "Progress": "", "OwnerId": "123456789012", "SnapshotId": "snap-07f30e3909aa0045e" }, { "Description": "This is a snapshot of a volume from my-instance", "Tags": [], "Encrypted": false, "VolumeId": "vol-02d0d4947008cb1a2", "State": "pending", "VolumeSize": 20, "StartTime": "2019-08-05T16:58:19.000Z", "Progress": "", "OwnerId": "123456789012", "SnapshotId": "snap-0ec20b602264aad48" }, ... ] }

示例 2:使用源卷中的标签创建多卷快照

以下create-snapshots示例创建连接到指定实例的所有卷的快照,并将标签从每个卷复制到其对应的快照中。

aws ec2 create-snapshots \ --instance-specification InstanceId=i-1234567890abcdef0 \ --copy-tags-from-source volume \ --description "This is snapshot of a volume from my-instance"

输出:

{ "Snapshots": [ { "Description": "This is a snapshot of a volume from my-instance", "Tags": [ { "Key": "Name", "Value": "my-volume" } ], "Encrypted": false, "VolumeId": "vol-02d0d4947008cb1a2", "State": "pending", "VolumeSize": 20, "StartTime": "2019-08-05T16:53:04.000Z", "Progress": "", "OwnerId": "123456789012", "SnapshotId": "snap-053bfaeb821a458dd" } ... ] }

示例 3:创建不包括根卷的多卷快照

以下create-snapshots示例创建了除根卷之外连接到指定实例的所有卷的快照。

aws ec2 create-snapshots \ --instance-specification InstanceId=i-1234567890abcdef0,ExcludeBootVolume=true

有关输出示例,请参阅示例 1。

示例 4:创建多卷快照并添加标签

以下create-snapshots示例创建附加到指定实例的所有卷的快照,并为每个快照添加两个标签。

aws ec2 create-snapshots \ --instance-specification InstanceId=i-1234567890abcdef0 \ --tag-specifications 'ResourceType=snapshot,Tags=[{Key=Name,Value=backup},{Key=costcenter,Value=123}]'

有关输出示例,请参阅示例 1。

以下代码示例演示如何使用 create-spot-datafeed-subscription

AWS CLI

创建竞价型实例数据源

以下create-spot-datafeed-subscription示例创建了竞价型实例数据馈送。

aws ec2 create-spot-datafeed-subscription \ --bucket my-bucket \ --prefix spot-data-feed

输出:

{ "SpotDatafeedSubscription": { "Bucket": "my-bucket", "OwnerId": "123456789012", "Prefix": "spot-data-feed", "State": "Active" } }

数据源存储在您指定的 Amazon S3 存储桶中。此数据馈送的文件名采用以下格式。

my-bucket.s3.amazonaws.com/spot-data-feed/123456789012.YYYY-MM-DD-HH.n.abcd1234.gz

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的竞价型实例数据源

以下代码示例演示如何使用 create-store-image-task

AWS CLI

将存储AMI在 S3 存储桶中

以下create-store-image-task示例将存储AMI在 S3 存储桶中。指定的 ID AMI 和用于存储的 S3 存储桶的名称AMI。

aws ec2 create-store-image-task \ --image-id ami-1234567890abcdef0 \ --bucket my-ami-bucket

输出:

{ "ObjectKey": "ami-1234567890abcdef0.bin" }

有关更多信息,请参阅 Amazon EC2 用户指南中的AMI使用 S3 存储和恢复

以下代码示例演示如何使用 create-subnet-cidr-reservation

AWS CLI

创建子网CIDR预留

以下create-subnet-cidr-reservation示例为指定的子网和CIDR范围创建子网CIDR预留。

aws ec2 create-subnet-cidr-reservation \ --subnet-id subnet-03c51e2eEXAMPLE \ --reservation-type prefix \ --cidr 10.1.0.20/26

输出:

{ "SubnetCidrReservation": { "SubnetCidrReservationId": "scr-044f977c4eEXAMPLE", "SubnetId": "subnet-03c51e2e6cEXAMPLE", "Cidr": "10.1.0.16/28", "ReservationType": "prefix", "OwnerId": "123456789012" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的子网CIDR预留

以下代码示例演示如何使用 create-subnet

AWS CLI

示例 1:创建仅包含IPv4CIDR区块的子网

以下create-subnet示例使用指定的IPv4CIDR区块在指定的子网中创建VPC子网。

aws ec2 create-subnet \ --vpc-id vpc-081ec835f3EXAMPLE \ --cidr-block 10.0.0.0/24 \ --tag-specifications ResourceType=subnet,Tags=[{Key=Name,Value=my-ipv4-only-subnet}]

输出:

{ "Subnet": { "AvailabilityZone": "us-west-2a", "AvailabilityZoneId": "usw2-az2", "AvailableIpAddressCount": 251, "CidrBlock": "10.0.0.0/24", "DefaultForAz": false, "MapPublicIpOnLaunch": false, "State": "available", "SubnetId": "subnet-0e99b93155EXAMPLE", "VpcId": "vpc-081ec835f3EXAMPLE", "OwnerId": "123456789012", "AssignIpv6AddressOnCreation": false, "Ipv6CidrBlockAssociationSet": [], "Tags": [ { "Key": "Name", "Value": "my-ipv4-only-subnet" } ], "SubnetArn": "arn:aws:ec2:us-west-2:123456789012:subnet/subnet-0e99b93155EXAMPLE" } }

示例 2:创建同时包含IPv4和IPv6CIDR块的子网

以下create-subnet示例使用指定的IPv4和IPv6CIDR块在指定的VPC子网中创建子网。

aws ec2 create-subnet \ --vpc-id vpc-081ec835f3EXAMPLE \ --cidr-block 10.0.0.0/24 \ --ipv6-cidr-block 2600:1f16:cfe:3660::/64 \ --tag-specifications ResourceType=subnet,Tags=[{Key=Name,Value=my-ipv4-ipv6-subnet}]

输出:

{ "Subnet": { "AvailabilityZone": "us-west-2a", "AvailabilityZoneId": "usw2-az2", "AvailableIpAddressCount": 251, "CidrBlock": "10.0.0.0/24", "DefaultForAz": false, "MapPublicIpOnLaunch": false, "State": "available", "SubnetId": "subnet-0736441d38EXAMPLE", "VpcId": "vpc-081ec835f3EXAMPLE", "OwnerId": "123456789012", "AssignIpv6AddressOnCreation": false, "Ipv6CidrBlockAssociationSet": [ { "AssociationId": "subnet-cidr-assoc-06c5f904499fcc623", "Ipv6CidrBlock": "2600:1f13:cfe:3660::/64", "Ipv6CidrBlockState": { "State": "associating" } } ], "Tags": [ { "Key": "Name", "Value": "my-ipv4-ipv6-subnet" } ], "SubnetArn": "arn:aws:ec2:us-west-2:123456789012:subnet/subnet-0736441d38EXAMPLE" } }

示例 3:创建仅包含IPv6CIDR区块的子网

以下create-subnet示例使用指定的IPv6CIDR区块在指定的子网中创建VPC子网。

aws ec2 create-subnet \ --vpc-id vpc-081ec835f3EXAMPLE \ --ipv6-native \ --ipv6-cidr-block 2600:1f16:115:200::/64 \ --tag-specifications ResourceType=subnet,Tags=[{Key=Name,Value=my-ipv6-only-subnet}]

输出:

{ "Subnet": { "AvailabilityZone": "us-west-2a", "AvailabilityZoneId": "usw2-az2", "AvailableIpAddressCount": 0, "DefaultForAz": false, "MapPublicIpOnLaunch": false, "State": "available", "SubnetId": "subnet-03f720e7deEXAMPLE", "VpcId": "vpc-081ec835f3EXAMPLE", "OwnerId": "123456789012", "AssignIpv6AddressOnCreation": true, "Ipv6CidrBlockAssociationSet": [ { "AssociationId": "subnet-cidr-assoc-01ef639edde556709", "Ipv6CidrBlock": "2600:1f13:cfe:3660::/64", "Ipv6CidrBlockState": { "State": "associating" } } ], "Tags": [ { "Key": "Name", "Value": "my-ipv6-only-subnet" } ], "SubnetArn": "arn:aws:ec2:us-west-2:123456789012:subnet/subnet-03f720e7deEXAMPLE" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的VPCs和子网

以下代码示例演示如何使用 create-tags

AWS CLI

示例 1:为资源添加标签

以下create-tags示例将标签Stack=production添加到指定的图像,或者覆盖标签密钥AMI所在位置的现有标签。Stack

aws ec2 create-tags \ --resources ami-1234567890abcdef0 \ --tags Key=Stack,Value=production

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的主题标题

示例 2:为多个资源添加标签

以下create-tags示例为AMI和实例添加(或覆盖)两个标签。其中一个标签有一个键(webserver),但没有值(值设置为空字符串)。另一个标签有一个键(stack)和一个值(Production)。

aws ec2 create-tags \ --resources ami-1a2b3c4d i-1234567890abcdef0 \ --tags Key=webserver,Value= Key=stack,Value=Production

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的主题标题

示例 3:添加包含特殊字符的标签

以下 create-tags 示例为实例添加标签 [Group]=test。方括号([ 和 ])是特殊字符,必须对其进行转义。以下示例还使用适用于每个环境的行延续字符。

如果使用的是 Windows,请用双引号(")将具有特殊字符的元素引起来,然后在每个双引号字符前面添加反斜杠(\),如下所示:

aws ec2 create-tags ^ --resources i-1234567890abcdef0 ^ --tags Key=\"[Group]\",Value=test

如果您使用的是 Windows PowerShell,请在元素中使用双引号 (“) 将带有特殊字符的值括起来,在每个双引号字符前面加一个反斜杠 (\),然后用单引号 (') 将整个键和值结构括起来,如下所示:

aws ec2 create-tags ` --resources i-1234567890abcdef0 ` --tags 'Key=\"[Group]\",Value=test'

如果使用的是 Linux 或 OS X,请使用双引号(")将具有特殊字符的元素引起来,然后使用单引号(')将整个键和值结构引起来,如下所示:

aws ec2 create-tags \ --resources i-1234567890abcdef0 \ --tags 'Key="[Group]",Value=test'

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的主题标题

以下代码示例演示如何使用 create-traffic-mirror-filter-rule

AWS CLI

为传入TCP流量创建过滤规则

以下create-traffic-mirror-filter-rule示例创建了一条规则,您可以使用该规则来镜像所有传入TCP流量。在运行此命令之前,create-traffic-mirror-filter请使用创建流量镜像过滤器。

aws ec2 create-traffic-mirror-filter-rule \ --description "TCP Rule" \ --destination-cidr-block 0.0.0.0/0 \ --protocol 6 \ --rule-action accept \ --rule-number 1 \ --source-cidr-block 0.0.0.0/0 \ --traffic-direction ingress \ --traffic-mirror-filter-id tmf-04812ff784b25ae67

输出:

{ "TrafficMirrorFilterRule": { "DestinationCidrBlock": "0.0.0.0/0", "TrafficMirrorFilterId": "tmf-04812ff784b25ae67", "TrafficMirrorFilterRuleId": "tmfr-02d20d996673f3732", "SourceCidrBlock": "0.0.0.0/0", "TrafficDirection": "ingress", "Description": "TCP Rule", "RuleNumber": 1, "RuleAction": "accept", "Protocol": 6 }, "ClientToken": "4752b573-40a6-4eac-a8a4-a72058761219" }

有关更多信息,请参阅《流量镜像指南》中的创建AWS 流量镜像过滤器

以下代码示例演示如何使用 create-traffic-mirror-filter

AWS CLI

创建流量镜像过滤器

以下create-traffic-mirror-filter示例创建了流量镜像过滤器。创建筛选器后,使用create-traffic-mirror-filter-rule向过滤器添加规则。

aws ec2 create-traffic-mirror-filter \ --description "TCP Filter"

输出:

{ "ClientToken": "28908518-100b-4987-8233-8c744EXAMPLE", "TrafficMirrorFilter": { "TrafficMirrorFilterId": "tmf-04812ff784EXAMPLE", "Description": "TCP Filter", "EgressFilterRules": [], "IngressFilterRules": [], "Tags": [], "NetworkServices": [] } }

有关更多信息,请参阅《流量镜像指南》中的创建AWS 流量镜像过滤器

以下代码示例演示如何使用 create-traffic-mirror-session

AWS CLI

创建流量镜像会话

以下create-traffic-mirror-session命令为数据包的 25 字节的指定源和目标创建流量镜像会话。

aws ec2 create-traffic-mirror-session \ --description "example session" \ --traffic-mirror-target-id tmt-07f75d8feeEXAMPLE \ --network-interface-id eni-070203f901EXAMPLE \ --session-number 1 \ --packet-length 25 \ --traffic-mirror-filter-id tmf-04812ff784EXAMPLE

输出:

{ "TrafficMirrorSession": { "TrafficMirrorSessionId": "tms-08a33b1214EXAMPLE", "TrafficMirrorTargetId": "tmt-07f75d8feeEXAMPLE", "TrafficMirrorFilterId": "tmf-04812ff784EXAMPLE", "NetworkInterfaceId": "eni-070203f901EXAMPLE", "OwnerId": "111122223333", "PacketLength": 25, "SessionNumber": 1, "VirtualNetworkId": 7159709, "Description": "example session", "Tags": [] }, "ClientToken": "5236cffc-ee13-4a32-bb5b-388d9da09d96" }

有关更多信息,请参阅《流量镜像指南》中的创建AWS 流量镜像会话

以下代码示例演示如何使用 create-traffic-mirror-target

AWS CLI

创建 Network Load Balancer 流量镜像目标

以下create-traffic-mirror-target示例创建了 Network Load Balancer 流量镜像目标。

aws ec2 create-traffic-mirror-target \ --description "Example Network Load Balancer Target" \ --network-load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:111122223333:loadbalancer/net/NLB/7cdec873EXAMPLE

输出:

{ "TrafficMirrorTarget": { "Type": "network-load-balancer", "Tags": [], "Description": "Example Network Load Balancer Target", "OwnerId": "111122223333", "NetworkLoadBalancerArn": "arn:aws:elasticloadbalancing:us-east-1:724145273726:loadbalancer/net/NLB/7cdec873EXAMPLE", "TrafficMirrorTargetId": "tmt-0dabe9b0a6EXAMPLE" }, "ClientToken": "d5c090f5-8a0f-49c7-8281-72c796a21f72" }

创建网络流量镜像目标

以下create-traffic-mirror-target示例创建了一个网络接口流量镜像目标。

aws ec2 create-traffic-mirror-target — 描述 “网络接口目标” — eni-network-interface-id eni-01f6f631e EXAMPLE

输出:

{ "ClientToken": "5289a345-0358-4e62-93d5-47ef3061d65e", "TrafficMirrorTarget": { "Description": "Network interface target", "NetworkInterfaceId": "eni-01f6f631eEXAMPLE", "TrafficMirrorTargetId": "tmt-02dcdbe2abEXAMPLE", "OwnerId": "111122223333", "Type": "network-interface", "Tags": [] } }

有关更多信息,请参阅《流量镜像指南》中的创建AWS 流量镜像目标

以下代码示例演示如何使用 create-transit-gateway-connect-peer

AWS CLI

创建 Transit Gateway Connect 对等

以下create-transit-gateway-connect-peer示例创建了一个 Connect 对等体。

aws ec2 create-transit-gateway-connect-peer \ --transit-gateway-attachment-id tgw-attach-0f0927767cEXAMPLE \ --peer-address 172.31.1.11 \ --inside-cidr-blocks 169.254.6.0/29

输出:

{ "TransitGatewayConnectPeer": { "TransitGatewayAttachmentId": "tgw-attach-0f0927767cEXAMPLE", "TransitGatewayConnectPeerId": "tgw-connect-peer-0666adbac4EXAMPLE", "State": "pending", "CreationTime": "2021-10-13T03:35:17.000Z", "ConnectPeerConfiguration": { "TransitGatewayAddress": "10.0.0.234", "PeerAddress": "172.31.1.11", "InsideCidrBlocks": [ "169.254.6.0/29" ], "Protocol": "gre", "BgpConfigurations": [ { "TransitGatewayAsn": 64512, "PeerAsn": 64512, "TransitGatewayAddress": "169.254.6.2", "PeerAddress": "169.254.6.1", "BgpStatus": "down" }, { "TransitGatewayAsn": 64512, "PeerAsn": 64512, "TransitGatewayAddress": "169.254.6.3", "PeerAddress": "169.254.6.1", "BgpStatus": "down" } ] } } }

有关更多信息,请参阅《公交网关指南》中的公交网关 Connect 附件和 Transit Gateway Connect 对等体

以下代码示例演示如何使用 create-transit-gateway-connect

AWS CLI

创建公交网关 Connect 附件

以下create-transit-gateway-connect示例使用 “gre” 协议为指定的附件创建一个 Connect 附件。

aws ec2 create-transit-gateway-connect \ --transport-transit-gateway-attachment-id tgw-attach-0a89069f57EXAMPLE \ --options "Protocol=gre"

输出:

{ "TransitGatewayConnect": { "TransitGatewayAttachmentId": "tgw-attach-037012e5dcEXAMPLE", "TransportTransitGatewayAttachmentId": "tgw-attach-0a89069f57EXAMPLE", "TransitGatewayId": "tgw-02f776b1a7EXAMPLE", "State": "pending", "CreationTime": "2021-03-09T19:59:17+00:00", "Options": { "Protocol": "gre" } } }

有关更多信息,请参阅《公交网关指南》中的公交网关 Connect 附件和 Transit Gateway Connect 对等体

以下代码示例演示如何使用 create-transit-gateway-multicast-domain

AWS CLI

示例 1:创建IGMP多播域

以下create-transit-gateway-multicast-domain示例为指定的传输网关创建多播域。禁用静态源后,与多播域关联的子网中的任何实例都可以发送多播流量。如果至少有一个成员使用该IGMP协议,则必须启用IGMPv2支持。

aws ec2 create-transit-gateway-multicast-domain \ --transit-gateway-id tgw-0bf0bffefaEXAMPLE \ --options StaticSourcesSupport=disable,Igmpv2Support=enable

输出:

{ "TransitGatewayMulticastDomain": { "TransitGatewayMulticastDomainId": "tgw-mcast-domain-0c9e29e2a7EXAMPLE", "TransitGatewayId": "tgw-0bf0bffefaEXAMPLE", "TransitGatewayMulticastDomainArn": "arn:aws:ec2:us-west-2:123456789012:transit-gateway-multicast-domain/tgw-mcast-domain-0c9e29e2a7EXAMPLE", "OwnerId": "123456789012", "Options": { "Igmpv2Support": "enable", "StaticSourcesSupport": "disable", "AutoAcceptSharedAssociations": "disable" }, "State": "pending", "CreationTime": "2021-09-29T22:17:13.000Z" } }

示例 2:创建静态多播域

以下create-transit-gateway-multicast-domain示例为指定的传输网关创建多播域。启用静态源后,必须静态添加源。

aws ec2 create-transit-gateway-multicast-domain \ --transit-gateway-id tgw-0bf0bffefaEXAMPLE \ --options StaticSourcesSupport=enable,Igmpv2Support=disable

输出:

{ "TransitGatewayMulticastDomain": { "TransitGatewayMulticastDomainId": "tgw-mcast-domain-000fb24d04EXAMPLE", "TransitGatewayId": "tgw-0bf0bffefaEXAMPLE", "TransitGatewayMulticastDomainArn": "arn:aws:ec2:us-west-2:123456789012:transit-gateway-multicast-domain/tgw-mcast-domain-000fb24d04EXAMPLE", "OwnerId": "123456789012", "Options": { "Igmpv2Support": "disable", "StaticSourcesSupport": "enable", "AutoAcceptSharedAssociations": "disable" }, "State": "pending", "CreationTime": "2021-09-29T22:20:19.000Z" } }

有关更多信息,请参阅《传输网关指南》中的管理多播域

以下代码示例演示如何使用 create-transit-gateway-peering-attachment

AWS CLI

创建公交网关对等连接

以下create-transit-gateway-peering-attachment示例在两个指定的中转网关之间创建对等连接请求。

aws ec2 create-transit-gateway-peering-attachment \ --transit-gateway-id tgw-123abc05e04123abc \ --peer-transit-gateway-id tgw-11223344aabbcc112 \ --peer-account-id 123456789012 \ --peer-region us-east-2

输出:

{ "TransitGatewayPeeringAttachment": { "TransitGatewayAttachmentId": "tgw-attach-4455667788aabbccd", "RequesterTgwInfo": { "TransitGatewayId": "tgw-123abc05e04123abc", "OwnerId": "123456789012", "Region": "us-west-2" }, "AccepterTgwInfo": { "TransitGatewayId": "tgw-11223344aabbcc112", "OwnerId": "123456789012", "Region": "us-east-2" }, "State": "initiatingRequest", "CreationTime": "2019-12-09T11:38:05.000Z" } }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 对等连接附件

以下代码示例演示如何使用 create-transit-gateway-policy-table

AWS CLI

创建传输网关策略表

以下create-transit-gateway-policy-table示例为指定的中转网关创建传输网关策略表。

aws ec2 create-transit-gateway-policy-table \ --transit-gateway-id tgw-067f8505c18f0bd6e

输出:

{ "TransitGatewayPolicyTable": { "TransitGatewayPolicyTableId": "tgw-ptb-0a16f134b78668a81", "TransitGatewayId": "tgw-067f8505c18f0bd6e", "State": "pending", "CreationTime": "2023-11-28T16:36:43+00:00" } }

有关更多信息,请参阅 T ransit Gatewa y 用户指南中的公交网关策略表

以下代码示例演示如何使用 create-transit-gateway-prefix-list-reference

AWS CLI

创建对前缀列表的引用

以下create-transit-gateway-prefix-list-reference示例创建了对指定公交网关路由表中指定前缀列表的引用。

aws ec2 create-transit-gateway-prefix-list-reference \ --transit-gateway-route-table-id tgw-rtb-0123456789abcd123 \ --prefix-list-id pl-11111122222222333 \ --transit-gateway-attachment-id tgw-attach-aaaaaabbbbbb11111

输出:

{ "TransitGatewayPrefixListReference": { "TransitGatewayRouteTableId": "tgw-rtb-0123456789abcd123", "PrefixListId": "pl-11111122222222333", "PrefixListOwnerId": "123456789012", "State": "pending", "Blackhole": false, "TransitGatewayAttachment": { "TransitGatewayAttachmentId": "tgw-attach-aaaaaabbbbbb11111", "ResourceType": "vpc", "ResourceId": "vpc-112233445566aabbc" } } }

有关更多信息,请参阅 T ransit Gateways 指南中的前缀列表参考

以下代码示例演示如何使用 create-transit-gateway-route-table

AWS CLI

创建 Transit Gateway 路由表

以下create-transit-gateway-route-table示例为指定的中转网关创建路由表。

aws ec2 create-transit-gateway-route-table \ --transit-gateway-id tgw-0262a0e521EXAMPLE

输出:

{ "TransitGatewayRouteTable": { "TransitGatewayRouteTableId": "tgw-rtb-0960981be7EXAMPLE", "TransitGatewayId": "tgw-0262a0e521EXAMPLE", "State": "pending", "DefaultAssociationRouteTable": false, "DefaultPropagationRouteTable": false, "CreationTime": "2019-07-10T19:01:46.000Z" } }

有关更多信息,请参阅 T ransit Gateways 指南中的创建中转网关路由表

以下代码示例演示如何使用 create-transit-gateway-route

AWS CLI

创建公交网关路由

以下create-transit-gateway-route示例为指定路由表创建具有指定目的地的路由。

aws ec2 create-transit-gateway-route \ --destination-cidr-block 10.0.2.0/24 \ --transit-gateway-route-table-id tgw-rtb-0b6f6aaa01EXAMPLE \ --transit-gateway-attachment-id tgw-attach-0b5968d3b6EXAMPLE

输出:

{ "Route": { "DestinationCidrBlock": "10.0.2.0/24", "TransitGatewayAttachments": [ { "ResourceId": "vpc-0065acced4EXAMPLE", "TransitGatewayAttachmentId": "tgw-attach-0b5968d3b6EXAMPLE", "ResourceType": "vpc" } ], "Type": "static", "State": "active" } }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 路由表

以下代码示例演示如何使用 create-transit-gateway-vpc-attachment

AWS CLI

示例 1:将传输网关与关联 VPC

以下create-transit-gateway-vpc-attachment示例创建了与指定的 Transit 网关连接VPC。

aws ec2 create-transit-gateway-vpc-attachment \ --transit-gateway-id tgw-0262a0e521EXAMPLE \ --vpc-id vpc-07e8ffd50f49335df \ --subnet-id subnet-0752213d59EXAMPLE

输出:

{ "TransitGatewayVpcAttachment": { "TransitGatewayAttachmentId": "tgw-attach-0a34fe6b4fEXAMPLE", "TransitGatewayId": "tgw-0262a0e521EXAMPLE", "VpcId": "vpc-07e8ffd50fEXAMPLE", "VpcOwnerId": "111122223333", "State": "pending", "SubnetIds": [ "subnet-0752213d59EXAMPLE" ], "CreationTime": "2019-07-10T17:33:46.000Z", "Options": { "DnsSupport": "enable", "Ipv6Support": "disable" } } }

有关更多信息,请参阅 T ransit Gateways 指南VPC中的创建与的中转网关连接

示例 2:将一个传输网关与一个中的多个子网关联 VPC

以下create-transit-gateway-vpc-attachment示例创建了与指定VPC和子网的中转网关连接。

aws ec2 create-transit-gateway-vpc-attachment \ --transit-gateway-id tgw-02f776b1a7EXAMPLE \ --vpc-id vpc-3EXAMPLE \ --subnet-ids "subnet-dEXAMPLE" "subnet-6EXAMPLE"

输出:

{ "TransitGatewayVpcAttachment": { "TransitGatewayAttachmentId": "tgw-attach-0e141e0bebEXAMPLE", "TransitGatewayId": "tgw-02f776b1a7EXAMPLE", "VpcId": "vpc-3EXAMPLE", "VpcOwnerId": "111122223333", "State": "pending", "SubnetIds": [ "subnet-6EXAMPLE", "subnet-dEXAMPLE" ], "CreationTime": "2019-12-17T20:07:52.000Z", "Options": { "DnsSupport": "enable", "Ipv6Support": "disable" } } }

有关更多信息,请参阅 T ransit Gateways 指南VPC中的创建与的中转网关连接

以下代码示例演示如何使用 create-transit-gateway

AWS CLI

创建公交网关

以下create-transit-gateway示例创建了一个传输网关。

aws ec2 create-transit-gateway \ --description MyTGW \ --options AmazonSideAsn=64516,AutoAcceptSharedAttachments=enable,DefaultRouteTableAssociation=enable,DefaultRouteTablePropagation=enable,VpnEcmpSupport=enable,DnsSupport=enable

输出:

{ "TransitGateway": { "TransitGatewayId": "tgw-0262a0e521EXAMPLE", "TransitGatewayArn": "arn:aws:ec2:us-east-2:111122223333:transit-gateway/tgw-0262a0e521EXAMPLE", "State": "pending", "OwnerId": "111122223333", "Description": "MyTGW", "CreationTime": "2019-07-10T14:02:12.000Z", "Options": { "AmazonSideAsn": 64516, "AutoAcceptSharedAttachments": "enable", "DefaultRouteTableAssociation": "enable", "AssociationDefaultRouteTableId": "tgw-rtb-018774adf3EXAMPLE", "DefaultRouteTablePropagation": "enable", "PropagationDefaultRouteTableId": "tgw-rtb-018774adf3EXAMPLE", "VpnEcmpSupport": "enable", "DnsSupport": "enable" } } }

有关更多信息,请参阅《传输网关指南》中的创建传输网关

以下代码示例演示如何使用 create-verified-access-endpoint

AWS CLI

创建已验证访问终端节点

以下create-verified-access-endpoint示例为指定的已验证访问权限组创建已验证访问权限终端节点。指定的网络接口和安全组必须属于相同的网络接口和安全组VPC。

aws ec2 create-verified-access-endpoint \ --verified-access-group-id vagr-0dbe967baf14b7235 \ --endpoint-type network-interface \ --attachment-type vpc \ --domain-certificate-arn arn:aws:acm:us-east-2:123456789012:certificate/eb065ea0-26f9-4e75-a6ce-0a1a7EXAMPLE \ --application-domain example.com \ --endpoint-domain-prefix my-ava-app \ --security-group-ids sg-004915970c4c8f13a \ --network-interface-options NetworkInterfaceId=eni-0aec70418c8d87a0f,Protocol=https,Port=443 \ --tag-specifications ResourceType=verified-access-endpoint,Tags=[{Key=Name,Value=my-va-endpoint}]

输出:

{ "VerifiedAccessEndpoint": { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "VerifiedAccessGroupId": "vagr-0dbe967baf14b7235", "VerifiedAccessEndpointId": "vae-066fac616d4d546f2", "ApplicationDomain": "example.com", "EndpointType": "network-interface", "AttachmentType": "vpc", "DomainCertificateArn": "arn:aws:acm:us-east-2:123456789012:certificate/eb065ea0-26f9-4e75-a6ce-0a1a7EXAMPLE", "EndpointDomain": "my-ava-app.edge-00c3372d53b1540bb.vai-0ce000c0b7643abea.prod.verified-access.us-east-2.amazonaws.com", "SecurityGroupIds": [ "sg-004915970c4c8f13a" ], "NetworkInterfaceOptions": { "NetworkInterfaceId": "eni-0aec70418c8d87a0f", "Protocol": "https", "Port": 443 }, "Status": { "Code": "pending" }, "Description": "", "CreationTime": "2023-08-25T20:54:43", "LastUpdatedTime": "2023-08-25T20:54:43", "Tags": [ { "Key": "Name", "Value": "my-va-endpoint" } ] } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问终端节点

以下代码示例演示如何使用 create-verified-access-group

AWS CLI

创建 “已验证访问权限” 组

以下create-verified-access-group示例为指定的 “已验证访问权限” 实例创建已验证访问权限组。

aws ec2 create-verified-access-group \ --verified-access-instance-id vai-0ce000c0b7643abea \ --tag-specifications ResourceType=verified-access-group,Tags=[{Key=Name,Value=my-va-group}]

输出:

{ "VerifiedAccessGroup": { "VerifiedAccessGroupId": "vagr-0dbe967baf14b7235", "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "Description": "", "Owner": "123456789012", "VerifiedAccessGroupArn": "arn:aws:ec2:us-east-2:123456789012:verified-access-group/vagr-0dbe967baf14b7235", "CreationTime": "2023-08-25T19:55:19", "LastUpdatedTime": "2023-08-25T19:55:19", "Tags": [ { "Key": "Name", "Value": "my-va-group" } ] } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问

以下代码示例演示如何使用 create-verified-access-instance

AWS CLI

创建已验证访问权限实例

以下create-verified-access-instance示例创建了一个带有 Name 标签的已验证访问实例。

aws ec2 create-verified-access-instance \ --tag-specifications ResourceType=verified-access-instance,Tags=[{Key=Name,Value=my-va-instance}]

输出:

{ "VerifiedAccessInstance": { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "Description": "", "VerifiedAccessTrustProviders": [], "CreationTime": "2023-08-25T18:27:56", "LastUpdatedTime": "2023-08-25T18:27:56", "Tags": [ { "Key": "Name", "Value": "my-va-instance" } ] } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问实例

以下代码示例演示如何使用 create-verified-access-trust-provider

AWS CLI

创建已验证访问信任提供商

以下create-verified-access-trust-provider示例使用 Ident AWS ity Center 设置已验证访问信任提供商。

aws ec2 create-verified-access-trust-provider \ --trust-provider-type user \ --user-trust-provider-type iam-identity-center \ --policy-reference-name idc \ --tag-specifications ResourceType=verified-access-trust-provider,Tags=[{Key=Name,Value=my-va-trust-provider}]

输出:

{ "VerifiedAccessTrustProvider": { "VerifiedAccessTrustProviderId": "vatp-0bb32de759a3e19e7", "Description": "", "TrustProviderType": "user", "UserTrustProviderType": "iam-identity-center", "PolicyReferenceName": "idc", "CreationTime": "2023-08-25T18:40:36", "LastUpdatedTime": "2023-08-25T18:40:36", "Tags": [ { "Key": "Name", "Value": "my-va-trust-provider" } ] } }

有关更多信息,请参阅《已验证访问用户指南》中的 “AWS 验证访问权限的信任提供商”。

以下代码示例演示如何使用 create-volume

AWS CLI

创建空的通用型 SSD (gp2) 卷

以下create-volume示例在指定的可用区创建一个 80 GiB 的通用型 SSD (gp2) 卷。请注意,当前区域必须是us-east-1,或者您可以添加--region参数来为命令指定区域。

aws ec2 create-volume \ --volume-type gp2 \ --size 80 \ --availability-zone us-east-1a

输出:

{ "AvailabilityZone": "us-east-1a", "Tags": [], "Encrypted": false, "VolumeType": "gp2", "VolumeId": "vol-1234567890abcdef0", "State": "creating", "Iops": 240, "SnapshotId": "", "CreateTime": "YYYY-MM-DDTHH:MM:SS.000Z", "Size": 80 }

如果您未指定卷类型,则默认卷类型为gp2

aws ec2 create-volume \ --size 80 \ --availability-zone us-east-1a

示例 2:使用快照创建预配置 IOPS SSD (io1) 卷

以下create-volume示例使用指定的快照IOPS在指定可用区创建预配置 IOPS SSD (io1) 卷,其中已配置 1000。

aws ec2 create-volume \ --volume-type io1 \ --iops 1000 \ --snapshot-id snap-066877671789bd71b \ --availability-zone us-east-1a

输出:

{ "AvailabilityZone": "us-east-1a", "Tags": [], "Encrypted": false, "VolumeType": "io1", "VolumeId": "vol-1234567890abcdef0", "State": "creating", "Iops": 1000, "SnapshotId": "snap-066877671789bd71b", "CreateTime": "YYYY-MM-DDTHH:MM:SS.000Z", "Size": 500 }

示例 3:创建加密卷

以下create-volume示例使用默认CMK加密卷创建EBS加密卷。如果默认情况下加密处于禁用状态,则必须按以下方式指定--encrypted参数。

aws ec2 create-volume \ --size 80 \ --encrypted \ --availability-zone us-east-1a

输出:

{ "AvailabilityZone": "us-east-1a", "Tags": [], "Encrypted": true, "VolumeType": "gp2", "VolumeId": "vol-1234567890abcdef0", "State": "creating", "Iops": 240, "SnapshotId": "", "CreateTime": "YYYY-MM-DDTHH:MM:SS.000Z", "Size": 80 }

如果默认启用了加密,则以下示例命令将创建加密卷,即使没有--encrypted参数也是如此。

aws ec2 create-volume \ --size 80 \ --availability-zone us-east-1a

如果您使用--kms-key-id参数指定客户托管CMK,则即使默认启用了加密,也必须指定该--encrypted参数。

aws ec2 create-volume \ --volume-type gp2 \ --size 80 \ --encrypted \ --kms-key-id 0ea3fef3-80a7-4778-9d8c-1c0c6EXAMPLE \ --availability-zone us-east-1a

示例 4:创建带有标签的卷

以下create-volume示例创建了一个卷并添加了两个标签。

aws ec2 create-volume \ --availability-zone us-east-1a \ --volume-type gp2 \ --size 80 \ --tag-specifications 'ResourceType=volume,Tags=[{Key=purpose,Value=production},{Key=cost-center,Value=cc123}]'
  • 有关API详细信息,请参阅AWS CLI 命令参考CreateVolume中的。

以下代码示例演示如何使用 create-vpc-endpoint-connection-notification

AWS CLI

创建端点连接通知

此示例为特定的终端节点服务创建通知,当接口终端节点已连接到您的服务以及您的服务已接受终端节点时,该通知会提醒您。

命令:

aws ec2 create-vpc-endpoint-connection-notification --connection-notification-arn arn:aws:sns:us-east-2:123456789012:VpceNotification --connection-events Connect Accept --service-id vpce-svc-1237881c0d25a3abc

输出:

{ "ConnectionNotification": { "ConnectionNotificationState": "Enabled", "ConnectionNotificationType": "Topic", "ServiceId": "vpce-svc-1237881c0d25a3abc", "ConnectionEvents": [ "Accept", "Connect" ], "ConnectionNotificationId": "vpce-nfn-008776de7e03f5abc", "ConnectionNotificationArn": "arn:aws:sns:us-east-2:123456789012:VpceNotification" } }

以下代码示例演示如何使用 create-vpc-endpoint-service-configuration

AWS CLI

示例 1:为接口终端节点创建终端节点服务配置

以下create-vpc-endpoint-service-configuration示例使用 Network L VPC oad Balancer 创建终端节点服务配置nlb-vpce。此示例还指定必须接受通过接口终端节点连接到服务的请求。

aws ec2 create-vpc-endpoint-service-configuration \ --network-load-balancer-arns arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/nlb-vpce/e94221227f1ba532 \ --acceptance-required

输出:

{ "ServiceConfiguration": { "ServiceType": [ { "ServiceType": "Interface" } ], "NetworkLoadBalancerArns": [ "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/nlb-vpce/e94221227f1ba532" ], "ServiceName": "com.amazonaws.vpce.us-east-1.vpce-svc-03d5ebb7d9579a2b3", "ServiceState": "Available", "ServiceId": "vpce-svc-03d5ebb7d9579a2b3", "AcceptanceRequired": true, "AvailabilityZones": [ "us-east-1d" ], "BaseEndpointDnsNames": [ "vpce-svc-03d5ebb7d9579a2b3.us-east-1.vpce.amazonaws.com" ] } }

示例 2:为 Gateway Load Balancer 终端节点创建终端节点服务配置

以下create-vpc-endpoint-service-configuration示例使用 Gateway Load Balancer 创建VPC终端节点服务配置GWLBService。系统会自动接受通过 Gateway Load Balancer 端点连接到服务的请求。

aws ec2 create-vpc-endpoint-service-configuration \ --gateway-load-balancer-arns arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/gwy/GWLBService/123123123123abcc \ --no-acceptance-required

输出:

{ "ServiceConfiguration": { "ServiceType": [ { "ServiceType": "GatewayLoadBalancer" } ], "ServiceId": "vpce-svc-123123a1c43abc123", "ServiceName": "com.amazonaws.vpce.us-east-1.vpce-svc-123123a1c43abc123", "ServiceState": "Available", "AvailabilityZones": [ "us-east-1d" ], "AcceptanceRequired": false, "ManagesVpcEndpoints": false, "GatewayLoadBalancerArns": [ "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/gwy/GWLBService/123123123123abcc" ] } }

有关更多信息,请参阅 Amazon VPC 用户指南中的VPC终端节点服务

以下代码示例演示如何使用 create-vpc-endpoint

AWS CLI

示例 1:创建网关终端节点

以下create-vpc-endpoint示例us-east-1在该区域VPCvpc-1a2b3c4d和 Amazon S3 之间创建网关VPC终端节点,并将路由表rtb-11aa22bb与该终端节点关联起来。

aws ec2 create-vpc-endpoint \ --vpc-id vpc-1a2b3c4d \ --service-name com.amazonaws.us-east-1.s3 \ --route-table-ids rtb-11aa22bb

输出:

{ "VpcEndpoint": { "PolicyDocument": "{\"Version\":\"2008-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":\"\*\",\"Action\":\"\*\",\"Resource\":\"\*\"}]}", "VpcId": "vpc-1a2b3c4d", "State": "available", "ServiceName": "com.amazonaws.us-east-1.s3", "RouteTableIds": [ "rtb-11aa22bb" ], "VpcEndpointId": "vpc-1a2b3c4d", "CreationTimestamp": "2015-05-15T09:40:50Z" } }

有关更多信息,请参阅AWS PrivateLink 指南中的创建网关终端节点

示例 2:创建接口终端节点

以下create-vpc-endpoint示例us-east-1在该区域VPCvpc-1a2b3c4d和 Amazon S3 之间创建了一个接口VPC终端节点。该命令在子网中创建终端节点subnet-1a2b3c4d,将其与安全组关联sg-1a2b3c4d,并添加密钥为 “服务”、值为 “S3” 的标签。

aws ec2 create-vpc-endpoint \ --vpc-id vpc-1a2b3c4d \ --vpc-endpoint-type Interface \ --service-name com.amazonaws.us-east-1.s3 \ --subnet-ids subnet-7b16de0c \ --security-group-id sg-1a2b3c4d \ --tag-specifications ResourceType=vpc-endpoint,Tags=[{Key=service,Value=S3}]

输出:

{ "VpcEndpoint": { "VpcEndpointId": "vpce-1a2b3c4d5e6f1a2b3", "VpcEndpointType": "Interface", "VpcId": "vpc-1a2b3c4d", "ServiceName": "com.amazonaws.us-east-1.s3", "State": "pending", "RouteTableIds": [], "SubnetIds": [ "subnet-1a2b3c4d" ], "Groups": [ { "GroupId": "sg-1a2b3c4d", "GroupName": "default" } ], "PrivateDnsEnabled": false, "RequesterManaged": false, "NetworkInterfaceIds": [ "eni-0b16f0581c8ac6877" ], "DnsEntries": [ { "DnsName": "*.vpce-1a2b3c4d5e6f1a2b3-9hnenorg.s3.us-east-1.vpce.amazonaws.com", "HostedZoneId": "Z7HUB22UULQXV" }, { "DnsName": "*.vpce-1a2b3c4d5e6f1a2b3-9hnenorg-us-east-1c.s3.us-east-1.vpce.amazonaws.com", "HostedZoneId": "Z7HUB22UULQXV" } ], "CreationTimestamp": "2021-03-05T14:46:16.030000+00:00", "Tags": [ { "Key": "service", "Value": "S3" } ], "OwnerId": "123456789012" } }

有关更多信息,请参阅《用户指南》中的创建接口端点 AWS PrivateLink。

示例 3:创建 Gateway Load Balancer 端点

以下create-vpc-endpoint示例在VPCvpc-111122223333aabbc和和和与使用网关负载均衡器配置的服务之间创建一个 Gateway Load Balancer 端点。

aws ec2 create-vpc-endpoint \ --service-name com.amazonaws.vpce.us-east-1.vpce-svc-123123a1c43abc123 \ --vpc-endpoint-type GatewayLoadBalancer \ --vpc-id vpc-111122223333aabbc \ --subnet-ids subnet-0011aabbcc2233445

输出:

{ "VpcEndpoint": { "VpcEndpointId": "vpce-aabbaabbaabbaabba", "VpcEndpointType": "GatewayLoadBalancer", "VpcId": "vpc-111122223333aabbc", "ServiceName": "com.amazonaws.vpce.us-east-1.vpce-svc-123123a1c43abc123", "State": "pending", "SubnetIds": [ "subnet-0011aabbcc2233445" ], "RequesterManaged": false, "NetworkInterfaceIds": [ "eni-01010120203030405" ], "CreationTimestamp": "2020-11-11T08:06:03.522Z", "OwnerId": "123456789012" } }

有关更多信息,请参阅《用户指南》中的 Gateway Load Balancer 终端节点 AWS PrivateLink。

以下代码示例演示如何使用 create-vpc-peering-connection

AWS CLI

在您的之间VPC创建对等连接 VPCs

此示例请求您的 vpc-1a2b3c4d 和 VPCs vpc-11122233 之间建立对等连接。

命令:

aws ec2 create-vpc-peering-connection --vpc-id vpc-1a2b3c4d --peer-vpc-id vpc-11122233

输出:

{ "VpcPeeringConnection": { "Status": { "Message": "Initiating Request to 444455556666", "Code": "initiating-request" }, "Tags": [], "RequesterVpcInfo": { "OwnerId": "444455556666", "VpcId": "vpc-1a2b3c4d", "CidrBlock": "10.0.0.0/28" }, "VpcPeeringConnectionId": "pcx-111aaa111", "ExpirationTime": "2014-04-02T16:13:36.000Z", "AccepterVpcInfo": { "OwnerId": "444455556666", "VpcId": "vpc-11122233" } } }

与其他账户VPCVPC中的创建对等连接

此示例请求在您的(vpc-1a2b3c4d)和属于账户 123456789012 的VPC(vpc-11122233)之间建立对等连接。VPC AWS

命令:

aws ec2 create-vpc-peering-connection --vpc-id vpc-1a2b3c4d --peer-vpc-id vpc-11122233 --peer-owner-id 123456789012

与其他区域VPC的创建VPC对等连接

此示例请求您在当前区域 (vpc-1a2b3c4d) 与您在该区域的账户VPC中的 (vpc-11122233) 之间建立对等连接。VPC us-west-2

命令:

aws ec2 create-vpc-peering-connection --vpc-id vpc-1a2b3c4d --peer-vpc-id vpc-11122233 --peer-region us-west-2

此示例请求您在VPC当前区域(vpc-1a2b3c4d)与属于该区域账户 123456789012 的(vpc-11122233)之间建立对等连接。VPC AWS us-west-2

命令:

aws ec2 create-vpc-peering-connection --vpc-id vpc-1a2b3c4d --peer-vpc-id vpc-11122233 --peer-owner-id 123456789012 --peer-region us-west-2

以下代码示例演示如何使用 create-vpc

AWS CLI

示例 1:创建 VPC

以下create-vpc示例VPC使用指定的IPv4CIDR区块和 Name 标签创建一个。

aws ec2 create-vpc \ --cidr-block 10.0.0.0/16 \ --tag-specifications ResourceType=vpc,Tags=[{Key=Name,Value=MyVpc}]

输出:

{ "Vpc": { "CidrBlock": "10.0.0.0/16", "DhcpOptionsId": "dopt-5EXAMPLE", "State": "pending", "VpcId": "vpc-0a60eb65b4EXAMPLE", "OwnerId": "123456789012", "InstanceTenancy": "default", "Ipv6CidrBlockAssociationSet": [], "CidrBlockAssociationSet": [ { "AssociationId": "vpc-cidr-assoc-07501b79ecEXAMPLE", "CidrBlock": "10.0.0.0/16", "CidrBlockState": { "State": "associated" } } ], "IsDefault": false, "Tags": [ { "Key": "Name", "Value": MyVpc" } ] } }

示例 2:创建VPC带有专用租赁的

以下create-vpc示例创建了VPC具有指定IPv4CIDR区块和专用租赁的。

aws ec2 create-vpc \ --cidr-block 10.0.0.0/16 \ --instance-tenancy dedicated

输出:

{ "Vpc": { "CidrBlock": "10.0.0.0/16", "DhcpOptionsId": "dopt-19edf471", "State": "pending", "VpcId": "vpc-0a53287fa4EXAMPLE", "OwnerId": "111122223333", "InstanceTenancy": "dedicated", "Ipv6CidrBlockAssociationSet": [], "CidrBlockAssociationSet": [ { "AssociationId": "vpc-cidr-assoc-00b24cc1c2EXAMPLE", "CidrBlock": "10.0.0.0/16", "CidrBlockState": { "State": "associated" } } ], "IsDefault": false } }

示例 3:使用IPv6CIDR方块VPC创建

以下create-vpc示例VPC使用亚马逊提供的IPv6CIDR区块创建一个。

aws ec2 create-vpc \ --cidr-block 10.0.0.0/16 \ --amazon-provided-ipv6-cidr-block

输出:

{ "Vpc": { "CidrBlock": "10.0.0.0/16", "DhcpOptionsId": "dopt-dEXAMPLE", "State": "pending", "VpcId": "vpc-0fc5e3406bEXAMPLE", "OwnerId": "123456789012", "InstanceTenancy": "default", "Ipv6CidrBlockAssociationSet": [ { "AssociationId": "vpc-cidr-assoc-068432c60bEXAMPLE", "Ipv6CidrBlock": "", "Ipv6CidrBlockState": { "State": "associating" }, "Ipv6Pool": "Amazon", "NetworkBorderGroup": "us-west-2" } ], "CidrBlockAssociationSet": [ { "AssociationId": "vpc-cidr-assoc-0669f8f9f5EXAMPLE", "CidrBlock": "10.0.0.0/16", "CidrBlockState": { "State": "associated" } } ], "IsDefault": false } }

示例 4:VPC使用IPAM池CIDR中的创建

以下create-vpc示例使用来CIDR自 VPC Amazon VPC IP 地址管理器 (IPAM) 池的,创建一个。

Linux 和 macOS:

aws ec2 create-vpc \ --ipv4-ipam-pool-id ipam-pool-0533048da7d823723 \ --tag-specifications ResourceType=vpc,Tags='[{Key=Environment,Value="Preprod"},{Key=Owner,Value="Build Team"}]'

Windows:

aws ec2 create-vpc ^ --ipv4-ipam-pool-id ipam-pool-0533048da7d823723 ^ --tag-specifications ResourceType=vpc,Tags=[{Key=Environment,Value="Preprod"},{Key=Owner,Value="Build Team"}]

输出:

{ "Vpc": { "CidrBlock": "10.0.1.0/24", "DhcpOptionsId": "dopt-2afccf50", "State": "pending", "VpcId": "vpc-010e1791024eb0af9", "OwnerId": "123456789012", "InstanceTenancy": "default", "Ipv6CidrBlockAssociationSet": [], "CidrBlockAssociationSet": [ { "AssociationId": "vpc-cidr-assoc-0a77de1d803226d4b", "CidrBlock": "10.0.1.0/24", "CidrBlockState": { "State": "associated" } } ], "IsDefault": false, "Tags": [ { "Key": "Environment", "Value": "Preprod" }, { "Key": "Owner", "Value": "Build Team" } ] } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南CIDR中的创建使用IPAM池的。VPC

  • 有关API详细信息,请参阅AWS CLI 命令参考CreateVpc中的。

以下代码示例演示如何使用 create-vpn-connection-route

AWS CLI

为VPN连接创建静态路由

此示例为指定VPN连接创建静态路由。如果命令成功,则不返回任何输出。

命令:

aws ec2 create-vpn-connection-route --vpn-connection-id vpn-40f41529 --destination-cidr-block 11.12.0.0/16

以下代码示例演示如何使用 create-vpn-connection

AWS CLI

示例 1:使用动态路由创建VPN连接

以下create-vpn-connection示例在指定的虚拟专用网关和指定的客户网关之间创建VPN连接,并将标签应用于该VPN连接。输出包括您的客户网关设备的XML格式配置信息。

aws ec2 create-vpn-connection \ --type ipsec.1 \ --customer-gateway-id cgw-001122334455aabbc \ --vpn-gateway-id vgw-1a1a1a1a1a1a2b2b2 \ --tag-specification 'ResourceType=vpn-connection,Tags=[{Key=Name,Value=BGP-VPN}]'

输出:

{ "VpnConnection": { "CustomerGatewayConfiguration": "...configuration information...", "CustomerGatewayId": "cgw-001122334455aabbc", "Category": "VPN", "State": "pending", "VpnConnectionId": "vpn-123123123123abcab", "VpnGatewayId": "vgw-1a1a1a1a1a1a2b2b2", "Options": { "EnableAcceleration": false, "StaticRoutesOnly": false, "LocalIpv4NetworkCidr": "0.0.0.0/0", "RemoteIpv4NetworkCidr": "0.0.0.0/0", "TunnelInsideIpVersion": "ipv4", "TunnelOptions": [ {}, {} ] }, "Routes": [], "Tags": [ { "Key": "Name", "Value": "BGP-VPN" } ] } }

有关更多信息,请参阅《AWS Site-to-Site VPN用户指南》中的 AWS Site-to-Site VPN工作原理

示例 2:使用静态路由创建VPN连接

以下create-vpn-connection示例在指定的虚拟专用网关和指定的客户网关之间创建VPN连接。这些选项指定静态路由。输出包括您的客户网关设备的XML格式配置信息。

aws ec2 create-vpn-connection \ --type ipsec.1 \ --customer-gateway-id cgw-001122334455aabbc \ --vpn-gateway-id vgw-1a1a1a1a1a1a2b2b2 \ --options "{\"StaticRoutesOnly\":true}"

输出:

{ "VpnConnection": { "CustomerGatewayConfiguration": "..configuration information...", "CustomerGatewayId": "cgw-001122334455aabbc", "Category": "VPN", "State": "pending", "VpnConnectionId": "vpn-123123123123abcab", "VpnGatewayId": "vgw-1a1a1a1a1a1a2b2b2", "Options": { "EnableAcceleration": false, "StaticRoutesOnly": true, "LocalIpv4NetworkCidr": "0.0.0.0/0", "RemoteIpv4NetworkCidr": "0.0.0.0/0", "TunnelInsideIpVersion": "ipv4", "TunnelOptions": [ {}, {} ] }, "Routes": [], "Tags": [] } }

有关更多信息,请参阅《AWS Site-to-Site VPN用户指南》中的 AWS Site-to-Site VPN工作原理

示例 3:创建VPN连接并指定自己的内部密钥CIDR和预共享密钥

以下create-vpn-connection示例创建VPN连接并为每个隧道指定内部 IP 地址CIDR块和自定义预共享密钥。指定的值将在CustomerGatewayConfiguration信息中返回。

aws ec2 create-vpn-connection \ --type ipsec.1 \ --customer-gateway-id cgw-001122334455aabbc \ --vpn-gateway-id vgw-1a1a1a1a1a1a2b2b2 \ --options TunnelOptions='[{TunnelInsideCidr=169.254.12.0/30,PreSharedKey=ExamplePreSharedKey1},{TunnelInsideCidr=169.254.13.0/30,PreSharedKey=ExamplePreSharedKey2}]'

输出:

{ "VpnConnection": { "CustomerGatewayConfiguration": "..configuration information...", "CustomerGatewayId": "cgw-001122334455aabbc", "Category": "VPN", "State": "pending", "VpnConnectionId": "vpn-123123123123abcab", "VpnGatewayId": "vgw-1a1a1a1a1a1a2b2b2", "Options": { "EnableAcceleration": false, "StaticRoutesOnly": false, "LocalIpv4NetworkCidr": "0.0.0.0/0", "RemoteIpv4NetworkCidr": "0.0.0.0/0", "TunnelInsideIpVersion": "ipv4", "TunnelOptions": [ { "OutsideIpAddress": "203.0.113.3", "TunnelInsideCidr": "169.254.12.0/30", "PreSharedKey": "ExamplePreSharedKey1" }, { "OutsideIpAddress": "203.0.113.5", "TunnelInsideCidr": "169.254.13.0/30", "PreSharedKey": "ExamplePreSharedKey2" } ] }, "Routes": [], "Tags": [] } }

有关更多信息,请参阅《AWS Site-to-Site VPN用户指南》中的 AWS Site-to-Site VPN工作原理

示例 4:创建支持IPv6流量的VPN连接

以下create-vpn-connection示例创建了一个VPN连接,该连接支持指定传输网关和指定客户网关之间的IPv6流量。两条隧道的隧道选项都指定了 AWS 必须启动IKE协商的隧道。

aws ec2 create-vpn-connection \ --type ipsec.1 \ --transit-gateway-id tgw-12312312312312312 \ --customer-gateway-id cgw-001122334455aabbc \ --options TunnelInsideIpVersion=ipv6,TunnelOptions=[{StartupAction=start},{StartupAction=start}]

输出:

{ "VpnConnection": { "CustomerGatewayConfiguration": "..configuration information...", "CustomerGatewayId": "cgw-001122334455aabbc", "Category": "VPN", "State": "pending", "VpnConnectionId": "vpn-11111111122222222", "TransitGatewayId": "tgw-12312312312312312", "Options": { "EnableAcceleration": false, "StaticRoutesOnly": false, "LocalIpv6NetworkCidr": "::/0", "RemoteIpv6NetworkCidr": "::/0", "TunnelInsideIpVersion": "ipv6", "TunnelOptions": [ { "OutsideIpAddress": "203.0.113.3", "StartupAction": "start" }, { "OutsideIpAddress": "203.0.113.5", "StartupAction": "start" } ] }, "Routes": [], "Tags": [] } }

有关更多信息,请参阅《AWS Site-to-Site VPN用户指南》中的 AWS Site-to-Site VPN工作原理

以下代码示例演示如何使用 create-vpn-gateway

AWS CLI

创建虚拟专用网关

此示例创建了一个虚拟专用网关。

命令:

aws ec2 create-vpn-gateway --type ipsec.1

输出:

{ "VpnGateway": { "AmazonSideAsn": 64512, "State": "available", "Type": "ipsec.1", "VpnGatewayId": "vgw-9a4cacf3", "VpcAttachments": [] } }

创建具有特定亚马逊端的虚拟专用网关 ASN

此示例创建了一个虚拟私有网关,并为会BGP话的 Amazon 端指定自治系统编号 (ASN)。

命令:

aws ec2 create-vpn-gateway --type ipsec.1 --amazon-side-asn 65001

输出:

{ "VpnGateway": { "AmazonSideAsn": 65001, "State": "available", "Type": "ipsec.1", "VpnGatewayId": "vgw-9a4cacf3", "VpcAttachments": [] } }
  • 有关API详细信息,请参阅AWS CLI 命令参考CreateVpnGateway中的。

以下代码示例演示如何使用 delete-carrier-gateway

AWS CLI

删除您的运营商网关

以下delete-carrier-gateway示例删除了指定的运营商网关。

aws ec2 delete-carrier-gateway \ --carrier-gateway-id cagw-0465cdEXAMPLE1111

输出:

{ "CarrierGateway": { "CarrierGatewayId": "cagw-0465cdEXAMPLE1111", "VpcId": "vpc-0c529aEXAMPLE1111", "State": "deleting", "OwnerId": "123456789012" } }

有关更多信息,请参阅 Amazon Virtual Private Cloud 用户指南中的运营商网关

以下代码示例演示如何使用 delete-client-vpn-endpoint

AWS CLI

删除客户端VPN终端节点

以下delete-client-vpn-endpoint示例删除了指定的客户端VPN终端节点。

aws ec2 delete-client-vpn-endpoint \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde

输出:

{ "Status": { "Code": "deleting" } }

有关更多信息,请参阅《客户机VPN管理员指南》中的AWS 客户端VPN端点

以下代码示例演示如何使用 delete-client-vpn-route

AWS CLI

删除客户端VPN终端节点的路由

以下delete-client-vpn-route示例删除了客户端VPN终端节点的指定子网的0.0.0.0/0路由。

aws ec2 delete-client-vpn-route \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde \ --destination-cidr-block 0.0.0.0/0 \ --target-vpc-subnet-id subnet-0123456789abcabca

输出:

{ "Status": { "Code": "deleting" } }

有关更多信息,请参阅《AWS 客户机VPN管理员指南》中的路由

以下代码示例演示如何使用 delete-coip-cidr

AWS CLI

删除一系列客户拥有的 IP (CoIP) 地址

以下delete-coip-cidr示例删除指定 CoIP 池中指定范围的 CoIP 地址。

aws ec2 delete-coip-cidr \ --cidr 14.0.0.0/24 \ --coip-pool-id ipv4pool-coip-1234567890abcdefg

输出:

{ "CoipCidr": { "Cidr": "14.0.0.0/24", "CoipPoolId": "ipv4pool-coip-1234567890abcdefg", "LocalGatewayRouteTableId": "lgw-rtb-abcdefg1234567890" } }

有关更多信息,请参阅《AWS Outposts 用户指南》中的客户拥有的 IP 地址

  • 有关API详细信息,请参阅AWS CLI 命令参考DeleteCoipCidr中的。

以下代码示例演示如何使用 delete-coip-pool

AWS CLI

删除客户拥有的 IP (CoIP) 地址池

以下delete-coip-pool示例删除了由 CoIP 地址组成的 CoIP 地址池。

aws ec2 delete-coip-pool \ --coip-pool-id ipv4pool-coip-1234567890abcdefg

输出:

{ "CoipPool": { "PoolId": "ipv4pool-coip-1234567890abcdefg", "LocalGatewayRouteTableId": "lgw-rtb-abcdefg1234567890", "PoolArn": "arn:aws:ec2:us-west-2:123456789012:coip-pool/ipv4pool-coip-1234567890abcdefg" } }

有关更多信息,请参阅《AWS Outposts 用户指南》中的客户拥有的 IP 地址

  • 有关API详细信息,请参阅AWS CLI 命令参考DeleteCoipPool中的。

以下代码示例演示如何使用 delete-customer-gateway

AWS CLI

删除客户网关

此示例删除了指定的客户网关。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-customer-gateway --customer-gateway-id cgw-0e11f167

以下代码示例演示如何使用 delete-dhcp-options

AWS CLI

删除DHCP选项集

此示例删除了指定的DHCP选项集。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-dhcp-options --dhcp-options-id dopt-d9070ebb

以下代码示例演示如何使用 delete-egress-only-internet-gateway

AWS CLI

删除仅限出口的互联网网关

此示例删除指定的仅限出口 Internet 网关。

命令:

aws ec2 delete-egress-only-internet-gateway --egress-only-internet-gateway-id eigw-01eadbd45ecd7943f

输出:

{ "ReturnCode": true }

以下代码示例演示如何使用 delete-fleets

AWS CLI

示例 1:删除EC2队列并终止关联的实例

以下delete-fleets示例删除指定的EC2队列并终止相关的按需实例和竞价型实例。

aws ec2 delete-fleets \ --fleet-ids fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE \ --terminate-instances

输出:

{ "SuccessfulFleetDeletions": [ { "CurrentFleetState": "deleted_terminating", "PreviousFleetState": "active", "FleetId": "fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE" } ], "UnsuccessfulFleetDeletions": [] }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的删除EC2队列

示例 2:在不终止关联实例的情况下删除EC2队列

以下delete-fleets示例在不终止关联的按需实例和竞价型实例的情况下删除指定的EC2队列。

aws ec2 delete-fleets \ --fleet-ids fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE \ --no-terminate-instances

输出:

{ "SuccessfulFleetDeletions": [ { "CurrentFleetState": "deleted_running", "PreviousFleetState": "active", "FleetId": "fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE" } ], "UnsuccessfulFleetDeletions": [] }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的删除EC2队列

  • 有关API详细信息,请参阅AWS CLI 命令参考DeleteFleets中的。

以下代码示例演示如何使用 delete-flow-logs

AWS CLI

删除流日志

以下delete-flow-logs示例删除了指定的流日志。

aws ec2 delete-flow-logs --flow-log-id fl-11223344556677889

输出:

{ "Unsuccessful": [] }
  • 有关API详细信息,请参阅AWS CLI 命令参考DeleteFlowLogs中的。

以下代码示例演示如何使用 delete-fpga-image

AWS CLI

删除亚马逊FPGA图片

此示例删除指定的AFI。

命令:

aws ec2 delete-fpga-image --fpga-image-id afi-06b12350a123fbabc

输出:

{ "Return": true }
  • 有关API详细信息,请参阅AWS CLI 命令参考DeleteFpgaImage中的。

以下代码示例演示如何使用 delete-instance-connect-endpoint

AWS CLI

删除 Instance Conn EC2 ect 终端节点

以下delete-instance-connect-endpoint示例删除了指定EC2的 Instance Connect 终端节点。

aws ec2 delete-instance-connect-endpoint \ --instance-connect-endpoint-id eice-03f5e49b83924bbc7

输出:

{ "InstanceConnectEndpoint": { "OwnerId": "111111111111", "InstanceConnectEndpointId": "eice-0123456789example", "InstanceConnectEndpointArn": "arn:aws:ec2:us-east-1:111111111111:instance-connect-endpoint/eice-0123456789example", "State": "delete-in-progress", "StateMessage": "", "NetworkInterfaceIds": [], "VpcId": "vpc-0123abcd", "AvailabilityZone": "us-east-1d", "CreatedAt": "2023-02-07T12:05:37+00:00", "SubnetId": "subnet-0123abcd" } }

有关更多信息,请参阅 Amazon EC2 用户指南中的移EC2除 Instance Connect 终端节点

以下代码示例演示如何使用 delete-instance-event-window

AWS CLI

示例 1:删除事件窗口

以下delete-instance-event-window示例删除了一个事件窗口。

aws ec2 delete-instance-event-window \ --region us-east-1 \ --instance-event-window-id iew-0abcdef1234567890

输出:

{ "InstanceEventWindowState": { "InstanceEventWindowId": "iew-0abcdef1234567890", "State": "deleting" } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

示例 2:强制删除事件窗口

如果事件窗口当前与目标相关联,则以下delete-instance-event-window示例强制删除该事件窗口。

aws ec2 delete-instance-event-window \ --region us-east-1 \ --instance-event-window-id iew-0abcdef1234567890 \ --force-delete

输出:

{ "InstanceEventWindowState": { "InstanceEventWindowId": "iew-0abcdef1234567890", "State": "deleting" } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

以下代码示例演示如何使用 delete-internet-gateway

AWS CLI

删除互联网网关

以下delete-internet-gateway示例删除了指定的互联网网关。

aws ec2 delete-internet-gateway \ --internet-gateway-id igw-0d0fb496b3EXAMPLE

此命令不生成任何输出。

有关更多信息,请参阅 Amazon VPC 用户指南中的互联网网关

以下代码示例演示如何使用 delete-ipam-pool

AWS CLI

删除IPAM池

在此示例中,您是一名IPAM委托管理员,想要删除一个不再需要的IPAM池,但该池已为其CIDR配置了一个存储池。除非您使用该--cascade选项,否则您无法删除CIDRs已为其配置的池,因此您将使用--cascade

要完成此请求,请执行以下操作:

你需要可以获得的矿IPAM池 ID describe-ipam-pools--region必须是IPAM主区域。

以下delete-ipam-pool示例删除了您 AWS 账户中的一个矿IPAM池。

aws ec2 delete-ipam-pool \ --ipam-pool-id ipam-pool-050c886a3ca41cd5b \ --cascade \ --region us-east-1

输出:

{ "IpamPool": { "OwnerId": "320805250157", "IpamPoolId": "ipam-pool-050c886a3ca41cd5b", "IpamPoolArn": "arn:aws:ec2::320805250157:ipam-pool/ipam-pool-050c886a3ca41cd5b", "IpamScopeArn": "arn:aws:ec2::320805250157:ipam-scope/ipam-scope-0a158dde35c51107b", "IpamScopeType": "private", "IpamArn": "arn:aws:ec2::320805250157:ipam/ipam-005f921c17ebd5107", "IpamRegion": "us-east-1", "Locale": "None", "PoolDepth": 1, "State": "delete-in-progress", "Description": "example", "AutoImport": false, "AddressFamily": "ipv4", "AllocationMinNetmaskLength": 0, "AllocationMaxNetmaskLength": 32 } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的删除池

  • 有关API详细信息,请参阅AWS CLI 命令参考DeleteIpamPool中的。

以下代码示例演示如何使用 delete-ipam-resource-discovery

AWS CLI

删除资源发现

在此示例中,您是一名IPAM委托管理员,想要删除您在与组织外部账户集成IPAM过程中为与其他IPAM管理员共享而创建的非默认资源发现。

要完成此请求,请执行以下操作:

--region必须是您创建资源发现的区域。如果出现以下情况,则无法删除默认资源发现。"IsDefault": true默认资源发现是在创建的账户中自动创建的资源发现IPAM。要删除默认资源发现,必须删除IPAM。

以下delete-ipam-resource-discovery示例删除资源发现。

aws ec2 delete-ipam-resource-discovery \ --ipam-resource-discovery-id ipam-res-disco-0e39761475298ee0f \ --region us-east-1

输出:

{ "IpamResourceDiscovery": { "OwnerId": "149977607591", "IpamResourceDiscoveryId": "ipam-res-disco-0e39761475298ee0f", "IpamResourceDiscoveryArn": "arn:aws:ec2::149977607591:ipam-resource-discovery/ipam-res-disco-0e39761475298ee0f", "IpamResourceDiscoveryRegion": "us-east-1", "OperatingRegions": [ { "RegionName": "us-east-1" } ], "IsDefault": false, "State": "delete-in-progress" } }

有关资源发现的更多信息,请参阅 Amazon VPC IPAM 用户指南中的使用资源发现

以下代码示例演示如何使用 delete-ipam-scope

AWS CLI

删除IPAM作用域

以下delete-ipam-scope示例删除了IPAM。

aws ec2 delete-ipam-scope \ --ipam-scope-id ipam-scope-01c1ebab2b63bd7e4

输出:

{ "IpamScope": { "OwnerId": "123456789012", "IpamScopeId": "ipam-scope-01c1ebab2b63bd7e4", "IpamScopeArn": "arn:aws:ec2::123456789012:ipam-scope/ipam-scope-01c1ebab2b63bd7e4", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-08440e7a3acde3908", "IpamRegion": "us-east-1", "IpamScopeType": "private", "IsDefault": false, "Description": "Example description", "PoolCount": 0, "State": "delete-in-progress" } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的删除作用域

  • 有关API详细信息,请参阅AWS CLI 命令参考DeleteIpamScope中的。

以下代码示例演示如何使用 delete-ipam

AWS CLI

要删除 IPAM

以下delete-ipam示例删除了IPAM。

aws ec2 delete-ipam \ --ipam-id ipam-036486dfa6af58ee0

输出:

{ "Ipam": { "OwnerId": "123456789012", "IpamId": "ipam-036486dfa6af58ee0", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-036486dfa6af58ee0", "IpamRegion": "us-east-1", "PublicDefaultScopeId": "ipam-scope-071b8042b0195c183", "PrivateDefaultScopeId": "ipam-scope-0807405dece705a30", "ScopeCount": 2, "OperatingRegions": [ { "RegionName": "us-east-1" }, { "RegionName": "us-east-2" }, { "RegionName": "us-west-1" } ], "State": "delete-in-progress" } }

有关更多信息,请参阅《Amazon VPC IPAM 用户指南》IPAM中的 “删除”。

  • 有关API详细信息,请参阅AWS CLI 命令参考DeleteIpam中的。

以下代码示例演示如何使用 delete-key-pair

AWS CLI

删除密钥对

以下delete-key-pair示例删除指定的 key pair。

aws ec2 delete-key-pair \ --key-name my-key-pair

输出:

{ "Return": true, "KeyPairId": "key-03c8d3aceb53b507" }

有关更多信息,请参阅《AWS 命令行界面用户指南》中的创建和删除密钥对

  • 有关API详细信息,请参阅AWS CLI 命令参考DeleteKeyPair中的。

以下代码示例演示如何使用 delete-launch-template-versions

AWS CLI

删除启动模板版本

此示例删除了指定的启动模板版本。

命令:

aws ec2 delete-launch-template-versions --launch-template-id lt-0abcd290751193123 --versions 1

输出:

{ "UnsuccessfullyDeletedLaunchTemplateVersions": [], "SuccessfullyDeletedLaunchTemplateVersions": [ { "LaunchTemplateName": "TestVersion", "VersionNumber": 1, "LaunchTemplateId": "lt-0abcd290751193123" } ] }

以下代码示例演示如何使用 delete-launch-template

AWS CLI

删除启动模板

本示例将删除指定的启动模板。

命令:

aws ec2 delete-launch-template --launch-template-id lt-0abcd290751193123

输出:

{ "LaunchTemplate": { "LatestVersionNumber": 2, "LaunchTemplateId": "lt-0abcd290751193123", "LaunchTemplateName": "TestTemplate", "DefaultVersionNumber": 2, "CreatedBy": "arn:aws:iam::123456789012:root", "CreateTime": "2017-11-23T16:46:25.000Z" } }

以下代码示例演示如何使用 delete-local-gateway-route-table-virtual-interface-group-association

AWS CLI

取消本地网关路由表与虚拟接口 (VIFs) 组的关联

以下delete-local-gateway-route-table-virtual-interface-group-association示例删除了指定的本地网关路由表和VIF组之间的关联。

aws ec2 delete-local-gateway-route-table-virtual-interface-group-association \ --local-gateway-route-table-virtual-interface-group-association-id lgw-vif-grp-assoc-exampleid12345678

输出:

{ "LocalGatewayRouteTableVirtualInterfaceGroupAssociation": { "LocalGatewayRouteTableVirtualInterfaceGroupAssociationId": "lgw-vif-grp-assoc-exampleid12345678", "LocalGatewayVirtualInterfaceGroupId": "lgw-vif-grp-exampleid0123abcd", "LocalGatewayId": "lgw-exampleid11223344", "LocalGatewayRouteTableId": "lgw-rtb-exampleidabcd1234", "LocalGatewayRouteTableArn": "arn:aws:ec2:us-west-2:111122223333:local-gateway-route-table/lgw-rtb-exampleidabcd1234", "OwnerId": "111122223333", "State": "disassociating", "Tags": [] } }

有关更多信息,请参阅 AWS Outposts 用户指南中的VIF群组关联

以下代码示例演示如何使用 delete-local-gateway-route-table-vpc-association

AWS CLI

取消本地网关路由表与路由表的关联 VPC

以下delete-local-gateway-route-table-vpc-association示例删除了指定的本地网关路由表与之间的关联VPC。

aws ec2 delete-local-gateway-route-table-vpc-association \ --local-gateway-route-table-vpc-association-id vpc-example0123456789

输出:

{ "LocalGatewayRouteTableVpcAssociation": { "LocalGatewayRouteTableVpcAssociationId": "lgw-vpc-assoc-abcd1234wxyz56789", "LocalGatewayRouteTableId": "lgw-rtb-abcdefg1234567890", "LocalGatewayRouteTableArn": "arn:aws:ec2:us-west-2:555555555555:local-gateway-route-table/lgw-rtb-abcdefg1234567890", "LocalGatewayId": "lgw-exampleid01234567", "VpcId": "vpc-example0123456789", "OwnerId": "555555555555", "State": "disassociating" } }

有关更多信息,请参阅 AWS Outposts 用户指南中的VPC关联

以下代码示例演示如何使用 delete-local-gateway-route-table

AWS CLI

删除本地网关路由表

以下delete-local-gateway-route-table示例使用直接VPC路由模式创建本地网关路由表。

aws ec2 delete-local-gateway-route-table \ --local-gateway-route-table-id lgw-rtb-abcdefg1234567890

输出:

{ "LocalGatewayRouteTable": { "LocalGatewayRouteTableId": "lgw-rtb-abcdefg1234567890", "LocalGatewayRouteTableArn": "arn:aws:ec2:us-west-2:111122223333:local-gateway-route-table/lgw-rtb-abcdefg1234567890", "LocalGatewayId": "lgw-1a2b3c4d5e6f7g8h9", "OutpostArn": "arn:aws:outposts:us-west-2:111122223333:outpost/op-021345abcdef67890", "OwnerId": "111122223333", "State": "deleting", "Tags": [], "Mode": "direct-vpc-routing" } }

有关更多信息,请参阅《AWS Outposts 用户指南》中的本地网关路由表

以下代码示例演示如何使用 delete-local-gateway-route

AWS CLI

从本地网关路由表中删除路由

以下delete-local-gateway-route示例从指定的本地网关路由表中删除指定的路由。

aws ec2 delete-local-gateway-route \ --destination-cidr-block 0.0.0.0/0 \ --local-gateway-route-table-id lgw-rtb-059615ef7dEXAMPLE

输出:

{ "Route": { "DestinationCidrBlock": "0.0.0.0/0", "LocalGatewayVirtualInterfaceGroupId": "lgw-vif-grp-07145b276bEXAMPLE", "Type": "static", "State": "deleted", "LocalGatewayRouteTableId": "lgw-rtb-059615ef7EXAMPLE" } }

以下代码示例演示如何使用 delete-managed-prefix-list

AWS CLI

删除前缀列表

以下delete-managed-prefix-list示例删除了指定的前缀列表。

aws ec2 delete-managed-prefix-list \ --prefix-list-id pl-0123456abcabcabc1

输出:

{ "PrefixList": { "PrefixListId": "pl-0123456abcabcabc1", "AddressFamily": "IPv4", "State": "delete-in-progress", "PrefixListArn": "arn:aws:ec2:us-west-2:123456789012:prefix-list/pl-0123456abcabcabc1", "PrefixListName": "test", "MaxEntries": 10, "Version": 1, "OwnerId": "123456789012" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的托管前缀列表

以下代码示例演示如何使用 delete-nat-gateway

AWS CLI

删除网NAT关

此示例删除NAT网关nat-04ae55e711cec5680

命令:

aws ec2 delete-nat-gateway --nat-gateway-id nat-04ae55e711cec5680

输出:

{ "NatGatewayId": "nat-04ae55e711cec5680" }
  • 有关API详细信息,请参阅AWS CLI 命令参考DeleteNatGateway中的。

以下代码示例演示如何使用 delete-network-acl-entry

AWS CLI

删除网络ACL条目

此示例从指定网络ACL中删除了编号为 100 的入口规则。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-network-acl-entry --network-acl-id acl-5fb85d36 --ingress --rule-number 100

以下代码示例演示如何使用 delete-network-acl

AWS CLI

删除网络 ACL

此示例删除了指定的网络ACL。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-network-acl --network-acl-id acl-5fb85d36
  • 有关API详细信息,请参阅AWS CLI 命令参考DeleteNetworkAcl中的。

以下代码示例演示如何使用 delete-network-insights-access-scope-analysis

AWS CLI

删除网络访问范围分析

以下delete-network-insights-access-scope-analysis示例删除了指定的网络访问范围分析。

aws ec2 delete-network-insights-access-scope-analysis \ --network-insights-access-scope-analysis-id nisa-01234567891abcdef

输出:

{ "NetworkInsightsAccessScopeAnalysisId": "nisa-01234567891abcdef }

有关更多信息,请参阅《网络访问分析器指南》 AWS CLI中的 “网络访问分析器入”。

以下代码示例演示如何使用 delete-network-insights-access-scope

AWS CLI

删除网络访问范围

以下delete-network-insights-access-scope示例删除了指定的网络访问范围。

aws ec2 delete-network-insights-access-scope \ --network-insights-access-scope-id nis-123456789abc01234

输出:

{ "NetworkInsightsAccessScopeId": "nis-123456789abc01234" }

有关更多信息,请参阅《网络访问分析器指南》 AWS CLI中的 “网络访问分析器入”。

以下代码示例演示如何使用 delete-network-insights-analysis

AWS CLI

删除路径分析

以下delete-network-insights-analysis示例删除了指定的分析。

aws ec2 delete-network-insights-analysis \ --network-insights-analysis-id nia-02207aa13eb480c7a

输出:

{ "NetworkInsightsAnalysisId": "nia-02207aa13eb480c7a" }

有关更多信息,请参阅 Reach ability Analy AWS CLI zer 指南中的入门使用指南。

以下代码示例演示如何使用 delete-network-insights-path

AWS CLI

删除路径

以下delete-network-insights-path示例删除了指定的路径。在删除路径之前,必须使用delete-network-insights-analysis命令删除其所有分析。

aws ec2 delete-network-insights-path \ --network-insights-path-id nip-0b26f224f1d131fa8

输出:

{ "NetworkInsightsPathId": "nip-0b26f224f1d131fa8" }

有关更多信息,请参阅 Reach ability Analy AWS CLI zer 指南中的入门使用指南。

以下代码示例演示如何使用 delete-network-interface-permission

AWS CLI

删除网络接口权限

此示例删除了指定的网络接口权限。

命令:

aws ec2 delete-network-interface-permission --network-interface-permission-id eni-perm-06fd19020ede149ea

输出:

{ "Return": true }

以下代码示例演示如何使用 delete-network-interface

AWS CLI

删除网络接口

此示例删除了指定的网络接口。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-network-interface --network-interface-id eni-e5aa89a3

以下代码示例演示如何使用 delete-placement-group

AWS CLI

删除置放群组

此示例命令删除指定的置放群组。

命令:

aws ec2 delete-placement-group --group-name my-cluster

以下代码示例演示如何使用 delete-queued-reserved-instances

AWS CLI

删除已排队的购买

以下delete-queued-reserved-instances示例删除了排队等候购买的指定预留实例。

aws ec2 delete-queued-reserved-instances \ --reserved-instances-ids af9f760e-6f91-4559-85f7-4980eexample

输出:

{ "SuccessfulQueuedPurchaseDeletions": [ { "ReservedInstancesId": "af9f760e-6f91-4559-85f7-4980eexample" } ], "FailedQueuedPurchaseDeletions": [] }

以下代码示例演示如何使用 delete-route-table

AWS CLI

删除路由表

此示例删除了指定的路由表。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-route-table --route-table-id rtb-22574640

以下代码示例演示如何使用 delete-route

AWS CLI

删除路线

此示例从指定路由表中删除指定路由。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-route --route-table-id rtb-22574640 --destination-cidr-block 0.0.0.0/0

以下代码示例演示如何使用 delete-security-group

AWS CLI

[EC2-Classic] 删除安全组

本示例将删除名为 MySecurityGroup 的安全组。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-security-group --group-name MySecurityGroup

[EC2-VPC] 删除安全组

本示例将删除 ID 为 sg-903004f8 的安全组。请注意,您不能VPC按名称为 EC2-引用安全组。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-security-group --group-id sg-903004f8

有关更多信息,请参阅《AWS 命令行界面用户指南》中的“使用安全组”。

以下代码示例演示如何使用 delete-snapshot

AWS CLI

删除快照

本示例命令将删除快照 ID 为 snap-1234567890abcdef0 的快照。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-snapshot --snapshot-id snap-1234567890abcdef0

以下代码示例演示如何使用 delete-spot-datafeed-subscription

AWS CLI

取消竞价型实例数据源订阅

此示例命令删除该账户的竞价数据源订阅。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-spot-datafeed-subscription

以下代码示例演示如何使用 delete-subnet-cidr-reservation

AWS CLI

删除子网CIDR预留

以下delete-subnet-cidr-reservation示例删除了指定的子网CIDR预留。

aws ec2 delete-subnet-cidr-reservation \ --subnet-cidr-reservation-id scr-044f977c4eEXAMPLE

输出:

{ "DeletedSubnetCidrReservation": { "SubnetCidrReservationId": "scr-044f977c4eEXAMPLE", "SubnetId": "subnet-03c51e2e6cEXAMPLE", "Cidr": "10.1.0.16/28", "ReservationType": "prefix", "OwnerId": "123456789012" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的子网CIDR预留

以下代码示例演示如何使用 delete-subnet

AWS CLI

删除子网

此示例删除了指定的子网。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-subnet --subnet-id subnet-9d4a7b6c

以下代码示例演示如何使用 delete-tags

AWS CLI

示例 1:从资源中删除标签

以下delete-tags示例Stack=Test从指定图像中删除标签。当您同时指定值和密钥名称时,只有当标签的值与指定值匹配时,才会删除该标签。

aws ec2 delete-tags \ --resources ami-1234567890abcdef0 \ --tags Key=Stack,Value=Test

为标签指定值是可选的。以下delete-tags示例将purpose从指定实例中删除带有密钥名称的标签,而不管该标签的标签值如何。

aws ec2 delete-tags \ --resources i-1234567890abcdef0 \ --tags Key=purpose

如果将空字符串指定为标签值,则仅当标签的值为空字符串时,才会删除标记。以下delete-tags示例将空字符串指定为要删除的标签的标签值。

aws ec2 delete-tags \ --resources i-1234567890abcdef0 \ --tags Key=Name,Value=

示例 2:从多个资源中删除标签

以下delete-tags示例从实例和实例中删除标签 “purpose=test``。AMI如前面的示例所示,您可以省略命令中的标签值。

aws ec2 delete-tags \ --resources i-1234567890abcdef0 ami-1234567890abcdef0 \ --tags Key=Purpose

以下代码示例演示如何使用 delete-traffic-mirror-filter-rule

AWS CLI

删除流量镜像过滤器规则

以下delete-traffic-mirror-filter-rule示例删除了指定的流量镜像过滤规则。

aws ec2 delete-traffic-mirror-filter-rule \ --traffic-mirror-filter-rule-id tmfr-081f71283bEXAMPLE

输出:

{ "TrafficMirrorFilterRuleId": "tmfr-081f71283bEXAMPLE" }

有关更多信息,请参阅《流量镜像指南》中的修改您的AWS 流量镜像过滤器规则

以下代码示例演示如何使用 delete-traffic-mirror-filter

AWS CLI

删除流量镜像过滤器

以下delete-traffic-mirror-filter示例删除了指定的流量镜像过滤器。

aws ec2 delete-traffic-mirror-filter \ --traffic-mirror-filter-id tmf-0be0b25fcdEXAMPLE

输出:

{ "TrafficMirrorFilterId": "tmf-0be0b25fcdEXAMPLE" }

有关更多信息,请参阅《流量镜像指南》中的删除AWS 流量镜像过滤器

以下代码示例演示如何使用 delete-traffic-mirror-session

AWS CLI

删除流量镜像会话

以下delete-traffic-mirror-session示例删除了指定的流量镜像会话。

aws ec2 delete-traffic-mirror-session \ --traffic-mirror-session-id tms-0af3141ce5EXAMPLE

输出:

{ "TrafficMirrorSessionId": "tms-0af3141ce5EXAMPLE" }

有关更多信息,请参阅《流量镜像指南》中的删除AWS 流量镜像会话

以下代码示例演示如何使用 delete-traffic-mirror-target

AWS CLI

删除流量镜像目标

以下delete-traffic-mirror-target示例删除了指定的流量镜像目标。

aws ec2 delete-traffic-mirror-target \ --traffic-mirror-target-id tmt-060f48ce9EXAMPLE

输出:

{ "TrafficMirrorTargetId": "tmt-060f48ce9EXAMPLE" }

有关更多信息,请参阅《流量镜像指南》中的删除AWS 流量镜像目标

以下代码示例演示如何使用 delete-transit-gateway-connect-peer

AWS CLI

删除 Transit Gateway Connect 对等体

以下delete-transit-gateway-connect-peer示例删除指定的 Connect 对等体。

aws ec2 delete-transit-gateway-connect-peer \ --transit-gateway-connect-peer-id tgw-connect-peer-0666adbac4EXAMPLE

输出:

{ "TransitGatewayConnectPeer": { "TransitGatewayAttachmentId": "tgw-attach-0f0927767cEXAMPLE", "TransitGatewayConnectPeerId": "tgw-connect-peer-0666adbac4EXAMPLE", "State": "deleting", "CreationTime": "2021-10-13T03:35:17.000Z", "ConnectPeerConfiguration": { "TransitGatewayAddress": "10.0.0.234", "PeerAddress": "172.31.1.11", "InsideCidrBlocks": [ "169.254.6.0/29" ], "Protocol": "gre", "BgpConfigurations": [ { "TransitGatewayAsn": 64512, "PeerAsn": 64512, "TransitGatewayAddress": "169.254.6.2", "PeerAddress": "169.254.6.1", "BgpStatus": "down" }, { "TransitGatewayAsn": 64512, "PeerAsn": 64512, "TransitGatewayAddress": "169.254.6.3", "PeerAddress": "169.254.6.1", "BgpStatus": "down" } ] } } }

有关更多信息,请参阅《公交网关指南》中的公交网关 Connect 附件和 Transit Gateway Connect 对等体

以下代码示例演示如何使用 delete-transit-gateway-connect

AWS CLI

要删除公交网关 Connect 附件

以下delete-transit-gateway-connect示例删除指定的 Connect 附件。

aws ec2 delete-transit-gateway-connect \ --transit-gateway-attachment-id tgw-attach-037012e5dcEXAMPLE

输出:

{ "TransitGatewayConnect": { "TransitGatewayAttachmentId": "tgw-attach-037012e5dcEXAMPLE", "TransportTransitGatewayAttachmentId": "tgw-attach-0a89069f57EXAMPLE", "TransitGatewayId": "tgw-02f776b1a7EXAMPLE", "State": "deleting", "CreationTime": "2021-03-09T19:59:17+00:00", "Options": { "Protocol": "gre" } } }

有关更多信息,请参阅《公交网关指南》中的公交网关 Connect 附件和 Transit Gateway Connect 对等体

以下代码示例演示如何使用 delete-transit-gateway-multicast-domain

AWS CLI

删除传输网关组播域

以下delete-transit-gateway-multicast-domain示例删除了指定的多播域。

aws ec2 delete-transit-gateway-multicast-domain \ --transit-gateway-multicast-domain-id tgw-mcast-domain-0c4905cef7EXAMPLE

输出:

{ "TransitGatewayMulticastDomain": { "TransitGatewayMulticastDomainId": "tgw-mcast-domain-02bb79002bEXAMPLE", "TransitGatewayId": "tgw-0d88d2d0d5EXAMPLE", "State": "deleting", "CreationTime": "2019-11-20T22:02:03.000Z" } }

有关更多信息,请参阅《传输网关指南》中的管理多播域

以下代码示例演示如何使用 delete-transit-gateway-peering-attachment

AWS CLI

删除传输网关对等连接

以下delete-transit-gateway-peering-attachment示例删除了指定的传输网关对等连接。

aws ec2 delete-transit-gateway-peering-attachment \ --transit-gateway-attachment-id tgw-attach-4455667788aabbccd

输出:

{ "TransitGatewayPeeringAttachment": { "TransitGatewayAttachmentId": "tgw-attach-4455667788aabbccd", "RequesterTgwInfo": { "TransitGatewayId": "tgw-123abc05e04123abc", "OwnerId": "123456789012", "Region": "us-west-2" }, "AccepterTgwInfo": { "TransitGatewayId": "tgw-11223344aabbcc112", "OwnerId": "123456789012", "Region": "us-east-2" }, "State": "deleting", "CreationTime": "2019-12-09T11:38:31.000Z" } }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 对等连接附件

以下代码示例演示如何使用 delete-transit-gateway-policy-table

AWS CLI

删除传输网关策略表

以下delete-transit-gateway-policy-table示例删除了指定的传输网关策略表。

aws ec2 delete-transit-gateway-policy-table \ --transit-gateway-policy-table-id tgw-ptb-0a16f134b78668a81

输出:

{ "TransitGatewayPolicyTables": [ { "TransitGatewayPolicyTableId": "tgw-ptb-0a16f134b78668a81", "TransitGatewayId": "tgw-067f8505c18f0bd6e", "State": "deleting", "CreationTime": "2023-11-28T16:36:43+00:00", "Tags": [] } ] }

有关更多信息,请参阅 T ransit Gatewa y 用户指南中的公交网关策略表

以下代码示例演示如何使用 delete-transit-gateway-prefix-list-reference

AWS CLI

删除前缀列表引用

以下delete-transit-gateway-prefix-list-reference示例删除了指定的前缀列表引用。

aws ec2 delete-transit-gateway-prefix-list-reference \ --transit-gateway-route-table-id tgw-rtb-0123456789abcd123 \ --prefix-list-id pl-11111122222222333

输出:

{ "TransitGatewayPrefixListReference": { "TransitGatewayRouteTableId": "tgw-rtb-0123456789abcd123", "PrefixListId": "pl-11111122222222333", "PrefixListOwnerId": "123456789012", "State": "deleting", "Blackhole": false, "TransitGatewayAttachment": { "TransitGatewayAttachmentId": "tgw-attach-aabbccddaabbccaab", "ResourceType": "vpc", "ResourceId": "vpc-112233445566aabbc" } } }

有关更多信息,请参阅 T ransit Gateways 指南中的前缀列表参考

以下代码示例演示如何使用 delete-transit-gateway-route-table

AWS CLI

删除公交网关路由表

以下delete-transit-gateway-route-table示例删除了指定的公交网关路由表。

aws ec2 delete-transit-gateway-route-table \ --transit-gateway-route-table-id tgw-rtb-0b6f6aaa01EXAMPLE

输出:

{ "TransitGatewayRouteTable": { "TransitGatewayRouteTableId": "tgw-rtb-0b6f6aaa01EXAMPLE", "TransitGatewayId": "tgw-02f776b1a7EXAMPLE", "State": "deleting", "DefaultAssociationRouteTable": false, "DefaultPropagationRouteTable": false, "CreationTime": "2019-07-17T20:27:26.000Z" } }

有关更多信息,请参阅 T ransit Gateways 指南中的删除中转网关路由表

以下代码示例演示如何使用 delete-transit-gateway-route

AWS CLI

从路由表中删除路CIDR块

以下delete-transit-gateway-route示例将该CIDR区块从指定的公交网关路由表中删除。

aws ec2 delete-transit-gateway-route \ --transit-gateway-route-table-id tgw-rtb-0b6f6aaa01EXAMPLE \ --destination-cidr-block 10.0.2.0/24

输出:

{ "Route": { "DestinationCidrBlock": "10.0.2.0/24", "TransitGatewayAttachments": [ { "ResourceId": "vpc-0065acced4EXAMPLE", "TransitGatewayAttachmentId": "tgw-attach-0b5968d3b6EXAMPLE", "ResourceType": "vpc" } ], "Type": "static", "State": "deleted" } }

有关更多信息,请参阅《传输网关指南》中的删除静态路由

以下代码示例演示如何使用 delete-transit-gateway-vpc-attachment

AWS CLI

删除公交网关VPC附件

以下delete-transit-gateway-vpc-attachment示例删除了指定的VPC附件。

aws ec2 delete-transit-gateway-vpc-attachment \ --transit-gateway-attachment-id tgw-attach-0d2c54bdbEXAMPLE

输出:

{ "TransitGatewayVpcAttachment": { "TransitGatewayAttachmentId": "tgw-attach-0d2c54bdb3EXAMPLE", "TransitGatewayId": "tgw-02f776b1a7EXAMPLE", "VpcId": "vpc-0065acced4f61c651", "VpcOwnerId": "111122223333", "State": "deleting", "CreationTime": "2019-07-17T16:04:27.000Z" } }

有关更多信息,请参阅《传输网关指南》中的删除VPC附件

以下代码示例演示如何使用 delete-transit-gateway

AWS CLI

删除传输网关

以下delete-transit-gateway示例删除了指定的传输网关。

aws ec2 delete-transit-gateway \ --transit-gateway-id tgw-01f04542b2EXAMPLE

输出:

{ "TransitGateway": { "TransitGatewayId": "tgw-01f04542b2EXAMPLE", "State": "deleting", "OwnerId": "123456789012", "Description": "Example Transit Gateway", "CreationTime": "2019-08-27T15:04:35.000Z", "Options": { "AmazonSideAsn": 64515, "AutoAcceptSharedAttachments": "disable", "DefaultRouteTableAssociation": "enable", "AssociationDefaultRouteTableId": "tgw-rtb-0ce7a6948fEXAMPLE", "DefaultRouteTablePropagation": "enable", "PropagationDefaultRouteTableId": "tgw-rtb-0ce7a6948fEXAMPLE", "VpnEcmpSupport": "enable", "DnsSupport": "enable" } } }

有关更多信息,请参阅《中转网关指南》中的删除中转网关

以下代码示例演示如何使用 delete-verified-access-endpoint

AWS CLI

删除已验证访问终端节点

以下delete-verified-access-endpoint示例删除了指定的已验证访问终端节点。

aws ec2 delete-verified-access-endpoint \ --verified-access-endpoint-id vae-066fac616d4d546f2

输出:

{ "VerifiedAccessEndpoint": { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "VerifiedAccessGroupId": "vagr-0dbe967baf14b7235", "VerifiedAccessEndpointId": "vae-066fac616d4d546f2", "ApplicationDomain": "example.com", "EndpointType": "network-interface", "AttachmentType": "vpc", "DomainCertificateArn": "arn:aws:acm:us-east-2:123456789012:certificate/eb065ea0-26f9-4e75-a6ce-0a1a7EXAMPLE", "EndpointDomain": "my-ava-app.edge-00c3372d53b1540bb.vai-0ce000c0b7643abea.prod.verified-access.us-east-2.amazonaws.com", "SecurityGroupIds": [ "sg-004915970c4c8f13a" ], "NetworkInterfaceOptions": { "NetworkInterfaceId": "eni-0aec70418c8d87a0f", "Protocol": "https", "Port": 443 }, "Status": { "Code": "deleting" }, "Description": "Testing Verified Access", "CreationTime": "2023-08-25T20:54:43", "LastUpdatedTime": "2023-08-25T22:46:32" } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问终端节点

以下代码示例演示如何使用 delete-verified-access-group

AWS CLI

删除已验证访问权限组

以下delete-verified-access-group示例删除指定的已验证访问权限组。

aws ec2 delete-verified-access-group \ --verified-access-group-id vagr-0dbe967baf14b7235

输出:

{ "VerifiedAccessGroup": { "VerifiedAccessGroupId": "vagr-0dbe967baf14b7235", "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "Description": "Testing Verified Access", "Owner": "123456789012", "VerifiedAccessGroupArn": "arn:aws:ec2:us-east-2:123456789012:verified-access-group/vagr-0dbe967baf14b7235", "CreationTime": "2023-08-25T19:55:19", "LastUpdatedTime": "2023-08-25T22:49:03", "DeletionTime": "2023-08-26T00:58:31" } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问

以下代码示例演示如何使用 delete-verified-access-instance

AWS CLI

删除已验证访问权限实例

以下delete-verified-access-instance示例删除指定的 “已验证访问权限” 实例。

aws ec2 delete-verified-access-instance \ --verified-access-instance-id vai-0ce000c0b7643abea

输出:

{ "VerifiedAccessInstance": { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "Description": "Testing Verified Access", "VerifiedAccessTrustProviders": [], "CreationTime": "2023-08-25T18:27:56", "LastUpdatedTime": "2023-08-26T01:00:18" } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问实例

以下代码示例演示如何使用 delete-verified-access-trust-provider

AWS CLI

删除已验证访问信任提供商

以下delete-verified-access-trust-provider示例删除了指定的已验证访问信任提供商。

aws ec2 delete-verified-access-trust-provider \ --verified-access-trust-provider-id vatp-0bb32de759a3e19e7

输出:

{ "VerifiedAccessTrustProvider": { "VerifiedAccessTrustProviderId": "vatp-0bb32de759a3e19e7", "Description": "Testing Verified Access", "TrustProviderType": "user", "UserTrustProviderType": "iam-identity-center", "PolicyReferenceName": "idc", "CreationTime": "2023-08-25T18:40:36", "LastUpdatedTime": "2023-08-25T18:40:36" } }

有关更多信息,请参阅《已验证访问用户指南》中的 “AWS 验证访问权限的信任提供商”。

以下代码示例演示如何使用 delete-volume

AWS CLI

删除卷

此示例命令删除卷 ID 为的可用卷vol-049df61146c4d7901。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-volume --volume-id vol-049df61146c4d7901

以下代码示例演示如何使用 delete-vpc-endpoint-connection-notifications

AWS CLI

删除端点连接通知

此示例删除了指定的端点连接通知。

命令:

aws ec2 delete-vpc-endpoint-connection-notifications --connection-notification-ids vpce-nfn-008776de7e03f5abc

输出:

{ "Unsuccessful": [] }

以下代码示例演示如何使用 delete-vpc-endpoint-service-configurations

AWS CLI

删除终端节点服务配置

此示例删除了指定的终端节点服务配置。

命令:

aws ec2 delete-vpc-endpoint-service-configurations --service-ids vpce-svc-03d5ebb7d9579a2b3

输出:

{ "Unsuccessful": [] }

以下代码示例演示如何使用 delete-vpc-endpoints

AWS CLI

删除终端节点

此示例删除了端点 vpce-aa22bb33 和 vpce-1a2b3c4d。如果命令部分成功或不成功,则返回失败项目的列表。如果命令成功,则返回的列表为空。

命令:

aws ec2 delete-vpc-endpoints --vpc-endpoint-ids vpce-aa22bb33 vpce-1a2b3c4d

输出:

{ "Unsuccessful": [] }

以下代码示例演示如何使用 delete-vpc-peering-connection

AWS CLI

删除对VPC等连接

此示例删除了指定的对VPC等连接。

命令:

aws ec2 delete-vpc-peering-connection --vpc-peering-connection-id pcx-1a2b3c4d

输出:

{ "Return": true }

以下代码示例演示如何使用 delete-vpc

AWS CLI

要删除 VPC

此示例删除指定的VPC。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-vpc --vpc-id vpc-a01106c2

以下代码示例演示如何使用 delete-vpn-connection-route

AWS CLI

从VPN连接中删除静态路由

此示例从指定VPN连接中删除指定的静态路由。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-vpn-connection-route --vpn-connection-id vpn-40f41529 --destination-cidr-block 11.12.0.0/16

以下代码示例演示如何使用 delete-vpn-connection

AWS CLI

删除VPN连接

此示例删除了指定的VPN连接。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-vpn-connection --vpn-connection-id vpn-40f41529

以下代码示例演示如何使用 delete-vpn-gateway

AWS CLI

删除虚拟专用网关

此示例删除了指定的虚拟专用网关。如果命令成功,则不返回任何输出。

命令:

aws ec2 delete-vpn-gateway --vpn-gateway-id vgw-9a4cacf3

以下代码示例演示如何使用 deprovision-byoip-cidr

AWS CLI

要移除 IP 地址范围,请使用

以下示例删除了与一起使用的指定地址范围 AWS。

aws ec2 deprovision-byoip-cidr \ --cidr 203.0.113.25/24

输出:

{ "ByoipCidr": { "Cidr": "203.0.113.25/24", "State": "pending-deprovision" } }

以下代码示例演示如何使用 deprovision-ipam-pool-cidr

AWS CLI

取消配置池 IPAM CIDR

以下deprovision-ipam-pool-cidr示例取消配置到CIDR池的配置。IPAM

(Linux):

aws ec2 deprovision-ipam-pool-cidr \ --ipam-pool-id ipam-pool-02ec043a19bbe5d08 \ --cidr 11.0.0.0/16

(视窗):

aws ec2 deprovision-ipam-pool-cidr ^ --ipam-pool-id ipam-pool-02ec043a19bbe5d08 ^ --cidr 11.0.0.0/16

输出:

{ "IpamPoolCidr": { "Cidr": "11.0.0.0/16", "State": "pending-deprovision" } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南CIDRs中的取消配置池

以下代码示例演示如何使用 deregister-image

AWS CLI

要取消注册 AMI

此示例取消注册指定的。AMI如果命令成功,则不返回任何输出。

命令:

aws ec2 deregister-image --image-id ami-4fa54026

以下代码示例演示如何使用 deregister-instance-event-notification-attributes

AWS CLI

示例 1:从事件通知中移除所有标签

以下deregister-instance-event-notification-attributes示例移除了IncludeAllTagsOfInstance=true,其效果是IncludeAllTagsOfInstance将其设置为false

aws ec2 deregister-instance-event-notification-attributes \ --instance-tag-attribute IncludeAllTagsOfInstance=true

输出:

{ "InstanceTagAttribute": { "InstanceTagKeys": [], "IncludeAllTagsOfInstance": true } }

有关更多信息,请参阅适用Linux 实例的 Amazon 弹性计算云用户指南中的实例计划事件

示例 2:从事件通知中移除特定标签

以下deregister-instance-event-notification-attributes示例从事件通知中包含的标签中删除指定的标签。要描述事件通知中包含的其余标签,请使用describe-instance-event-notification-attributes

aws ec2 deregister-instance-event-notification-attributes \ --instance-tag-attribute InstanceTagKeys="tag-key2"

输出:

{ "InstanceTagAttribute": { "InstanceTagKeys": [ "tag-key2" ], "IncludeAllTagsOfInstance": false } }

有关更多信息,请参阅适用Linux 实例的 Amazon 弹性计算云用户指南中的实例计划事件

以下代码示例演示如何使用 deregister-transit-gateway-multicast-group-members

AWS CLI

从组播组中取消注册群组成员

此示例将指定的网络接口组成员从传输网关组播组中注销。

aws ec2 deregister-transit-gateway-multicast-group-members \ --transit-gateway-multicast-domain-id tgw-mcast-domain-0c4905cef7EXAMPLE \ --group-ip-address 224.0.1.0 \ --network-interface-ids eni-0e246d3269EXAMPLE

输出:

{ "DeregisteredMulticastGroupMembers": { "TransitGatewayMulticastDomainId": "tgw-mcast-domain-0c4905cef7EXAMPLE", "RegisteredNetworkInterfaceIds": [ "eni-0e246d3269EXAMPLE" ], "GroupIpAddress": "224.0.1.0" } }

有关更多信息,请参阅 T AWS ransit Gateways 用户指南中的从组播组注销成员

以下代码示例演示如何使用 deregister-transit-gateway-multicast-group-source

AWS CLI

从传输网关组播组中取消注册源

此示例从组播组中取消注册指定的网络接口组源。

aws ec2 register-transit-gateway-multicast-group-sources \ --transit-gateway-multicast-domain-id tgw-mcast-domain-0c4905cef79d6e597 \ --group-ip-address 224.0.1.0 \ --network-interface-ids eni-07f290fc3c090cbae

输出:

{ "DeregisteredMulticastGroupSources": { "TransitGatewayMulticastDomainId": "tgw-mcast-domain-0c4905cef79d6e597", "DeregisteredNetworkInterfaceIds": [ "eni-07f290fc3c090cbae" ], "GroupIpAddress": "224.0.1.0" } }

有关更多信息,请参阅 T AWS ransit Gateways 用户指南中的从组播组取消注册源

以下代码示例演示如何使用 describe-account-attributes

AWS CLI

描述您 AWS 账户的所有属性

此示例描述了您的 AWS 账户的属性。

命令:

aws ec2 describe-account-attributes

输出:

{ "AccountAttributes": [ { "AttributeName": "vpc-max-security-groups-per-interface", "AttributeValues": [ { "AttributeValue": "5" } ] }, { "AttributeName": "max-instances", "AttributeValues": [ { "AttributeValue": "20" } ] }, { "AttributeName": "supported-platforms", "AttributeValues": [ { "AttributeValue": "EC2" }, { "AttributeValue": "VPC" } ] }, { "AttributeName": "default-vpc", "AttributeValues": [ { "AttributeValue": "none" } ] }, { "AttributeName": "max-elastic-ips", "AttributeValues": [ { "AttributeValue": "5" } ] }, { "AttributeName": "vpc-max-elastic-ips", "AttributeValues": [ { "AttributeValue": "5" } ] } ] }

描述您 AWS 账户的单个属性

此示例描述了您的 AWS 账户的supported-platforms属性。

命令:

aws ec2 describe-account-attributes --attribute-names supported-platforms

输出:

{ "AccountAttributes": [ { "AttributeName": "supported-platforms", "AttributeValues": [ { "AttributeValue": "EC2" }, { "AttributeValue": "VPC" } ] } ] }

以下代码示例演示如何使用 describe-address-transfers

AWS CLI

描述弹性 IP 地址传输

以下describe-address-transfers示例描述了指定弹性 IP 地址的弹性 IP 地址传输。

aws ec2 describe-address-transfers \ --allocation-ids eipalloc-09ad461b0d03f6aaf

输出:

{ "AddressTransfers": [ { "PublicIp": "100.21.184.216", "AllocationId": "eipalloc-09ad461b0d03f6aaf", "TransferAccountId": "123456789012", "TransferOfferExpirationTimestamp": "2023-02-22T22:51:01.000Z", "AddressTransferStatus": "pending" } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的传输弹性 IP 地址

以下代码示例演示如何使用 describe-addresses-attribute

AWS CLI

查看与弹性 IP 地址关联的域名的属性

以下describe-addresses-attribute示例返回与弹性 IP 地址关联的域名的属性。

Linux:

aws ec2 describe-addresses-attribute \ --allocation-ids eipalloc-abcdef01234567890 \ --attribute domain-name

Windows:

aws ec2 describe-addresses-attribute ^ --allocation-ids eipalloc-abcdef01234567890 ^ --attribute domain-name

输出:

{ "Addresses": [ { "PublicIp": "192.0.2.0", "AllocationId": "eipalloc-abcdef01234567890", "PtrRecord": "example.com." } ] }

要查看弹性 IP 地址的属性,必须先将域名与弹性 IP 地址相关联。有关更多信息,请参阅《Amazon EC2 用户指南》或《AWS CLI命令参考modify-address-attribute中的 “对电子邮件应用程序使用反向 DNS”。

以下代码示例演示如何使用 describe-addresses

AWS CLI

示例 1:检索所有弹性 IP 地址的详细信息

以下 describe addresses 示例显示有关弹性 IP 地址的详细信息。

aws ec2 describe-addresses

输出:

{ "Addresses": [ { "InstanceId": "i-1234567890abcdef0", "PublicIp": "198.51.100.0", "PublicIpv4Pool": "amazon", "Domain": "standard" }, { "Domain": "vpc", "PublicIpv4Pool": "amazon", "InstanceId": "i-1234567890abcdef0", "NetworkInterfaceId": "eni-12345678", "AssociationId": "eipassoc-12345678", "NetworkInterfaceOwnerId": "123456789012", "PublicIp": "203.0.113.0", "AllocationId": "eipalloc-12345678", "PrivateIpAddress": "10.0.1.241" } ] }

示例 2:要检索您的弹性 IP 地址的详细信息 EC2-VPC

以下describe-addresses示例显示了有关您的弹性 IP 地址的详细信息,以便用于中的实例VPC。

aws ec2 describe-addresses \ --filters "Name=domain,Values=vpc"

输出:

{ "Addresses": [ { "Domain": "vpc", "PublicIpv4Pool": "amazon", "InstanceId": "i-1234567890abcdef0", "NetworkInterfaceId": "eni-12345678", "AssociationId": "eipassoc-12345678", "NetworkInterfaceOwnerId": "123456789012", "PublicIp": "203.0.113.0", "AllocationId": "eipalloc-12345678", "PrivateIpAddress": "10.0.1.241" } ] }

示例 3:检索由分配 ID 指定的弹性 IP 地址的详细信息

以下describe-addresses示例显示了有关具有指定分配 ID 的弹性 IP 地址的详细信息,该地址与 EC2-中的实例相关联VPC。

aws ec2 describe-addresses \ --allocation-ids eipalloc-282d9641

输出:

{ "Addresses": [ { "Domain": "vpc", "PublicIpv4Pool": "amazon", "InstanceId": "i-1234567890abcdef0", "NetworkInterfaceId": "eni-1a2b3c4d", "AssociationId": "eipassoc-123abc12", "NetworkInterfaceOwnerId": "1234567891012", "PublicIp": "203.0.113.25", "AllocationId": "eipalloc-282d9641", "PrivateIpAddress": "10.251.50.12" } ] }

示例 4:检索由其VPC私有 IP 地址指定的弹性 IP 地址的详细信息

以下describe-addresses示例显示了与 EC2-中的特定私有 IP 地址关联的弹性 IP 地址的详细信息VPC。

aws ec2 describe-addresses \ --filters "Name=private-ip-address,Values=10.251.50.12"

示例 5:在 EC2-Classic 中检索有关弹性 IP 地址的详细信息

TThe以下describe-addresses示例显示了有关您在 EC2-Classic 中使用的弹性 IP 地址的详细信息。

aws ec2 describe-addresses \ --filters "Name=domain,Values=standard"

输出:

{ "Addresses": [ { "InstanceId": "i-1234567890abcdef0", "PublicIp": "203.0.110.25", "PublicIpv4Pool": "amazon", "Domain": "standard" } ] }

示例 6:检索由公有 IP 地址指定的弹性 IP 地址详细信息

以下describe-addresses示例显示了带有值的弹性 IP 地址的详细信息203.0.110.25,该地址与 EC2-Classic 中的实例相关联。

aws ec2 describe-addresses \ --public-ips 203.0.110.25

输出:

{ "Addresses": [ { "InstanceId": "i-1234567890abcdef0", "PublicIp": "203.0.110.25", "PublicIpv4Pool": "amazon", "Domain": "standard" } ] }

以下代码示例演示如何使用 describe-aggregate-id-format

AWS CLI

描述区域中所有资源类型的加长 ID 格式设置

以下describe-aggregate-id-format示例描述了当前区域的整体 long ID 格式状态。该Deadline值表示这些资源从短 ID 格式永久切换到长 ID 格式的截止日期已过期。该UseLongIdsAggregated值表示所有IAM用户和IAM角色都配置为对所有资源类型使用长 ID 格式。

aws ec2 describe-aggregate-id-format

输出:

{ "UseLongIdsAggregated": true, "Statuses": [ { "Deadline": "2018-08-13T02:00:00.000Z", "Resource": "network-interface-attachment", "UseLongIds": true }, { "Deadline": "2016-12-13T02:00:00.000Z", "Resource": "instance", "UseLongIds": true }, { "Deadline": "2018-08-13T02:00:00.000Z", "Resource": "elastic-ip-association", "UseLongIds": true }, ... ] }

以下代码示例演示如何使用 describe-availability-zones

AWS CLI

描述可用区

以下示例 describe-availability-zones 显示了可供您使用的可用区详细信息。响应仅包括当前区域的可用区。在本示例中,将使用配置文件默认的 us-west-2(俄勒冈州)区域。

aws ec2 describe-availability-zones

输出:

{ "AvailabilityZones": [ { "State": "available", "OptInStatus": "opt-in-not-required", "Messages": [], "RegionName": "us-west-2", "ZoneName": "us-west-2a", "ZoneId": "usw2-az1", "GroupName": "us-west-2", "NetworkBorderGroup": "us-west-2" }, { "State": "available", "OptInStatus": "opt-in-not-required", "Messages": [], "RegionName": "us-west-2", "ZoneName": "us-west-2b", "ZoneId": "usw2-az2", "GroupName": "us-west-2", "NetworkBorderGroup": "us-west-2" }, { "State": "available", "OptInStatus": "opt-in-not-required", "Messages": [], "RegionName": "us-west-2", "ZoneName": "us-west-2c", "ZoneId": "usw2-az3", "GroupName": "us-west-2", "NetworkBorderGroup": "us-west-2" }, { "State": "available", "OptInStatus": "opt-in-not-required", "Messages": [], "RegionName": "us-west-2", "ZoneName": "us-west-2d", "ZoneId": "usw2-az4", "GroupName": "us-west-2", "NetworkBorderGroup": "us-west-2" }, { "State": "available", "OptInStatus": "opted-in", "Messages": [], "RegionName": "us-west-2", "ZoneName": "us-west-2-lax-1a", "ZoneId": "usw2-lax1-az1", "GroupName": "us-west-2-lax-1", "NetworkBorderGroup": "us-west-2-lax-1" } ] }

以下代码示例演示如何使用 describe-aws-network-performance-metric-subscription

AWS CLI

描述您的指标订阅

以下describe-aws-network-performance-metric-subscriptions示例描述了您的指标订阅。

aws ec2 describe-aws-network-performance-metric-subscriptions

输出:

{ "Subscriptions": [ { "Source": "us-east-1", "Destination": "eu-west-1", "Metric": "aggregate-latency", "Statistic": "p50", "Period": "five-minutes" } ] }

有关更多信息,请参阅《基础架构性能用户指南》中的管理订阅

以下代码示例演示如何使用 describe-aws-network-performance-metric-subscriptions

AWS CLI

描述您的指标订阅

以下describe-aws-network-performance-metric-subscriptions示例描述了您的指标订阅。

aws ec2 describe-aws-network-performance-metric-subscriptions

输出:

{ "Subscriptions": [ { "Source": "us-east-1", "Destination": "eu-west-1", "Metric": "aggregate-latency", "Statistic": "p50", "Period": "five-minutes" } ] }

有关更多信息,请参阅《基础架构性能用户指南》中的管理订阅

以下代码示例演示如何使用 describe-bundle-tasks

AWS CLI

描述你的捆绑任务

此示例描述了您的所有捆绑包任务。

命令:

aws ec2 describe-bundle-tasks

输出:

{ "BundleTasks": [ { "UpdateTime": "2015-09-15T13:26:54.000Z", "InstanceId": "i-1234567890abcdef0", "Storage": { "S3": { "Prefix": "winami", "Bucket": "bundletasks" } }, "State": "bundling", "StartTime": "2015-09-15T13:24:35.000Z", "Progress": "3%", "BundleId": "bun-2a4e041c" } ] }

以下代码示例演示如何使用 describe-byoip-cidrs

AWS CLI

描述您的预配置地址范围

以下describe-byoip-cidrs示例显示了有关您预配置供使用的公共IPv4地址范围的详细信息。 AWS

aws ec2 describe-byoip-cidrs

输出:

{ "ByoipCidrs": [ { "Cidr": "203.0.113.25/24", "StatusMessage": "ipv4pool-ec2-1234567890abcdef0", "State": "provisioned" } ] }

以下代码示例演示如何使用 describe-capacity-reservation-fleets

AWS CLI

查看容量预留队列

以下describe-capacity-reservation-fleets示例列出了指定容量预留队列的配置和容量信息。它还列出了有关舰队内部各个容量预留的详细信息。 :

aws ec2 describe-capacity-reservation-fleets \ --capacity-reservation-fleet-ids crf-abcdef01234567890

输出:

{ "CapacityReservationFleets": [ { "Status": "active", "EndDate": "2022-12-31T23:59:59.000Z", "InstanceMatchCriteria": "open", "Tags": [], "CapacityReservationFleetId": "crf-abcdef01234567890", "Tenancy": "default", "InstanceTypeSpecifications": [ { "CapacityReservationId": "cr-1234567890abcdef0", "AvailabilityZone": "us-east-1a", "FulfilledCapacity": 5.0, "Weight": 1.0, "CreateDate": "2022-07-02T08:34:33.398Z", "InstancePlatform": "Linux/UNIX", "TotalInstanceCount": 5, "Priority": 1, "EbsOptimized": true, "InstanceType": "m5.xlarge" } ], "TotalTargetCapacity": 5, "TotalFulfilledCapacity": 5.0, "CreateTime": "2022-07-02T08:34:33.397Z", "AllocationStrategy": "prioritized" } ] }

有关容量预留队列的更多信息,请参阅 A mazon EC2 用户指南中的容量预留队列。

以下代码示例演示如何使用 describe-capacity-reservations

AWS CLI

示例 1:描述您的一个或多个容量预留

以下describe-capacity-reservations示例显示了有关您在当前 AWS 地区的所有容量预留的详细信息。

aws ec2 describe-capacity-reservations

输出:

{ "CapacityReservations": [ { "CapacityReservationId": "cr-1234abcd56EXAMPLE ", "EndDateType": "unlimited", "AvailabilityZone": "eu-west-1a", "InstanceMatchCriteria": "open", "Tags": [], "EphemeralStorage": false, "CreateDate": "2019-08-16T09:03:18.000Z", "AvailableInstanceCount": 1, "InstancePlatform": "Linux/UNIX", "TotalInstanceCount": 1, "State": "active", "Tenancy": "default", "EbsOptimized": true, "InstanceType": "a1.medium" }, { "CapacityReservationId": "cr-abcdEXAMPLE9876ef ", "EndDateType": "unlimited", "AvailabilityZone": "eu-west-1a", "InstanceMatchCriteria": "open", "Tags": [], "EphemeralStorage": false, "CreateDate": "2019-08-07T11:34:19.000Z", "AvailableInstanceCount": 3, "InstancePlatform": "Linux/UNIX", "TotalInstanceCount": 3, "State": "cancelled", "Tenancy": "default", "EbsOptimized": true, "InstanceType": "m5.large" } ] }

示例 2:描述您的一个或多个容量预留

以下describe-capacity-reservations示例显示了有关指定容量预留的详细信息。

aws ec2 describe-capacity-reservations \ --capacity-reservation-ids cr-1234abcd56EXAMPLE

输出:

{ "CapacityReservations": [ { "CapacityReservationId": "cr-1234abcd56EXAMPLE", "EndDateType": "unlimited", "AvailabilityZone": "eu-west-1a", "InstanceMatchCriteria": "open", "Tags": [], "EphemeralStorage": false, "CreateDate": "2019-08-16T09:03:18.000Z", "AvailableInstanceCount": 1, "InstancePlatform": "Linux/UNIX", "TotalInstanceCount": 1, "State": "active", "Tenancy": "default", "EbsOptimized": true, "InstanceType": "a1.medium" } ] }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的查看容量预留

以下代码示例演示如何使用 describe-carrier-gateways

AWS CLI

描述所有运营商网关

以下describe-carrier-gateways示例列出了您的所有运营商网关。

aws ec2 describe-carrier-gateways

输出:

{ "CarrierGateways": [ { "CarrierGatewayId": "cagw-0465cdEXAMPLE1111", "VpcId": "vpc-0c529aEXAMPLE", "State": "available", "OwnerId": "123456789012", "Tags": [ { "Key": "example", "Value": "tag" } ] } ] }

有关更多信息,请参阅《亚马逊虚拟私有云用户指南》中的运营商网关 < https://docs.aws.amazon.com/vpc/ latest/userguide/Carrier _gateway.html>。

以下代码示例演示如何使用 describe-classic-link-instances

AWS CLI

描述链接的EC2经典实例

此示例列出了所有关联的 EC2-Classic 实例。

命令:

aws ec2 describe-classic-link-instances

输出:

{ "Instances": [ { "InstanceId": "i-1234567890abcdef0", "VpcId": "vpc-88888888", "Groups": [ { "GroupId": "sg-11122233" } ], "Tags": [ { "Value": "ClassicInstance", "Key": "Name" } ] }, { "InstanceId": "i-0598c7d356eba48d7", "VpcId": "vpc-12312312", "Groups": [ { "GroupId": "sg-aabbccdd" } ], "Tags": [ { "Value": "ClassicInstance2", "Key": "Name" } ] } ] }

此示例列出了所有关联的 EC2-Classic 实例,并筛选响应以仅包含链接到 VPC vpc-88888888 的实例。

命令:

aws ec2 describe-classic-link-instances --filter "Name=vpc-id,Values=vpc-88888888"

输出:

{ "Instances": [ { "InstanceId": "i-1234567890abcdef0", "VpcId": "vpc-88888888", "Groups": [ { "GroupId": "sg-11122233" } ], "Tags": [ { "Value": "ClassicInstance", "Key": "Name" } ] } ] }

以下代码示例演示如何使用 describe-client-vpn-authorization-rules

AWS CLI

描述客户端VPN终端节点的授权规则

以下describe-client-vpn-authorization-rules示例显示了有关指定客户端VPN终端节点的授权规则的详细信息。

aws ec2 describe-client-vpn-authorization-rules \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde

输出:

{ "AuthorizationRules": [ { "ClientVpnEndpointId": "cvpn-endpoint-123456789123abcde", "GroupId": "", "AccessAll": true, "DestinationCidr": "0.0.0.0/0", "Status": { "Code": "active" } } ] }

有关更多信息,请参阅《AWS 客户机VPN管理员指南》中的授权规则

以下代码示例演示如何使用 describe-client-vpn-connections

AWS CLI

描述与客户端VPN终端节点的连接

以下describe-client-vpn-connections示例显示了有关客户端与指定客户端VPN终端节点的连接的详细信息。

aws ec2 describe-client-vpn-connections \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde

输出:

{ "Connections": [ { "ClientVpnEndpointId": "cvpn-endpoint-123456789123abcde", "Timestamp": "2019-08-12 07:58:34", "ConnectionId": "cvpn-connection-0e03eb24267165acd", "ConnectionEstablishedTime": "2019-08-12 07:57:14", "IngressBytes": "32302", "EgressBytes": "5696", "IngressPackets": "332", "EgressPackets": "67", "ClientIp": "172.31.0.225", "CommonName": "client1.domain.tld", "Status": { "Code": "terminated" }, "ConnectionEndTime": "2019-08-12 07:58:34" }, { "ClientVpnEndpointId": "cvpn-endpoint-123456789123abcde", "Timestamp": "2019-08-12 08:02:54", "ConnectionId": "cvpn-connection-00668867a40f18253", "ConnectionEstablishedTime": "2019-08-12 08:02:53", "IngressBytes": "2951", "EgressBytes": "2611", "IngressPackets": "9", "EgressPackets": "6", "ClientIp": "172.31.0.226", "CommonName": "client1.domain.tld", "Status": { "Code": "active" }, "ConnectionEndTime": "-" } ] }

有关更多信息,请参阅《客户机VPN管理员指南》中的 “AWS 客户端连接”。

以下代码示例演示如何使用 describe-client-vpn-endpoints

AWS CLI

描述您的客户端VPN终端节点

以下describe-client-vpn-endpoints示例显示有关您的所有客户端VPN终端节点的详细信息。

aws ec2 describe-client-vpn-endpoints

输出:

{ "ClientVpnEndpoints": [ { "ClientVpnEndpointId": "cvpn-endpoint-123456789123abcde", "Description": "Endpoint for Admin access", "Status": { "Code": "available" }, "CreationTime": "2020-11-13T11:37:27", "DnsName": "*.cvpn-endpoint-123456789123abcde.prod.clientvpn.ap-south-1.amazonaws.com", "ClientCidrBlock": "172.31.0.0/16", "DnsServers": [ "8.8.8.8" ], "SplitTunnel": false, "VpnProtocol": "openvpn", "TransportProtocol": "udp", "VpnPort": 443, "ServerCertificateArn": "arn:aws:acm:ap-south-1:123456789012:certificate/a1b2c3d4-5678-90ab-cdef-11111EXAMPLE", "AuthenticationOptions": [ { "Type": "certificate-authentication", "MutualAuthentication": { "ClientRootCertificateChain": "arn:aws:acm:ap-south-1:123456789012:certificate/a1b2c3d4-5678-90ab-cdef-22222EXAMPLE" } } ], "ConnectionLogOptions": { "Enabled": true, "CloudwatchLogGroup": "Client-vpn-connection-logs", "CloudwatchLogStream": "cvpn-endpoint-123456789123abcde-ap-south-1-2020/11/13-FCD8HEMVaCcw" }, "Tags": [ { "Key": "Name", "Value": "Client VPN" } ], "SecurityGroupIds": [ "sg-aabbcc11223344567" ], "VpcId": "vpc-a87f92c1", "SelfServicePortalUrl": "https://self-service.clientvpn.amazonaws.com/endpoints/cvpn-endpoint-123456789123abcde", "ClientConnectOptions": { "Enabled": false } } ] }

有关更多信息,请参阅《客户机VPN管理员指南》中的AWS 客户端VPN端点

以下代码示例演示如何使用 describe-client-vpn-routes

AWS CLI

描述客户端VPN终端节点的路由

以下describe-client-vpn-routes示例显示有关指定客户端VPN终端节点的路由的详细信息。

aws ec2 describe-client-vpn-routes \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde

输出:

{ "Routes": [ { "ClientVpnEndpointId": "cvpn-endpoint-123456789123abcde", "DestinationCidr": "10.0.0.0/16", "TargetSubnet": "subnet-0123456789abcabca", "Type": "Nat", "Origin": "associate", "Status": { "Code": "active" }, "Description": "Default Route" }, { "ClientVpnEndpointId": "cvpn-endpoint-123456789123abcde", "DestinationCidr": "0.0.0.0/0", "TargetSubnet": "subnet-0123456789abcabca", "Type": "Nat", "Origin": "add-route", "Status": { "Code": "active" } } ] }

有关更多信息,请参阅《AWS 客户机VPN管理员指南》中的路由

以下代码示例演示如何使用 describe-client-vpn-target-networks

AWS CLI

描述客户端VPN终端节点的目标网络

以下describe-client-vpn-target-networks示例显示有关指定客户端VPN终端节点的目标网络的详细信息。

aws ec2 describe-client-vpn-target-networks \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde

输出:

{ "ClientVpnTargetNetworks": [ { "AssociationId": "cvpn-assoc-012e837060753dc3d", "VpcId": "vpc-11111222222333333", "TargetNetworkId": "subnet-0123456789abcabca", "ClientVpnEndpointId": "cvpn-endpoint-123456789123abcde", "Status": { "Code": "associating" }, "SecurityGroups": [ "sg-012345678910abcab" ] } ] }

有关更多信息,请参阅《AWS 客户机VPN管理员指南》中的 “目标网络”。

以下代码示例演示如何使用 describe-coip-pools

AWS CLI

描述客户拥有的 IP 地址池

以下describe-coip-pools示例描述了您 AWS 账户中客户拥有的 IP 地址池。

aws ec2 describe-coip-pools

输出:

{ "CoipPools": [ { "PoolId": "ipv4pool-coip-123a45678bEXAMPLE", "PoolCidrs": [ "0.0.0.0/0" ], "LocalGatewayRouteTableId": "lgw-rtb-059615ef7dEXAMPLE", "PoolArn": "arn:aws:ec2:us-west-2:123456789012:coip-pool/ipv4pool-coip-123a45678bEXAMPLE" } ] }

有关更多信息,请参阅《AWS Outposts 用户指南》中的客户拥有的 IP 地址

以下代码示例演示如何使用 describe-conversion-tasks

AWS CLI

查看转换任务的状态

此示例返回 ID 为 import-i-ffvko 9js 的转换任务的状态。

命令:

aws ec2 describe-conversion-tasks --conversion-task-ids import-i-ffvko9js

输出:

{ "ConversionTasks": [ { "ConversionTaskId": "import-i-ffvko9js", "ImportInstance": { "InstanceId": "i-1234567890abcdef0", "Volumes": [ { "Volume": { "Id": "vol-049df61146c4d7901", "Size": 16 }, "Status": "completed", "Image": { "Size": 1300687360, "ImportManifestUrl": "https://s3.amazonaws.com/myimportbucket/411443cd-d620-4f1c-9d66-13144EXAMPLE/RHEL5.vmdkmanifest.xml?AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Expires=140EXAMPLE&Signature=XYNhznHNgCqsjDxL9wRL%2FJvEXAMPLE", "Format": "VMDK" }, "BytesConverted": 1300682960, "AvailabilityZone": "us-east-1d" } ] }, "ExpirationTime": "2014-05-14T22:06:23Z", "State": "completed" } ] }

以下代码示例演示如何使用 describe-customer-gateways

AWS CLI

描述您的客户网关

此示例描述了您的客户网关。

命令:

aws ec2 describe-customer-gateways

输出:

{ "CustomerGateways": [ { "CustomerGatewayId": "cgw-b4dc3961", "IpAddress": "203.0.113.12", "State": "available", "Type": "ipsec.1", "BgpAsn": "65000" }, { "CustomerGatewayId": "cgw-0e11f167", "IpAddress": "12.1.2.3", "State": "available", "Type": "ipsec.1", "BgpAsn": "65534" } ] }

描述特定的客户网关

此示例描述了指定的客户网关。

命令:

aws ec2 describe-customer-gateways --customer-gateway-ids cgw-0e11f167

输出:

{ "CustomerGateways": [ { "CustomerGatewayId": "cgw-0e11f167", "IpAddress": "12.1.2.3", "State": "available", "Type": "ipsec.1", "BgpAsn": "65534" } ] }

以下代码示例演示如何使用 describe-dhcp-options

AWS CLI

示例 1:描述您的DHCP选项

以下describe-dhcp-options示例检索有关您的DHCP选项的详细信息。

aws ec2 describe-dhcp-options

输出:

{ "DhcpOptions": [ { "DhcpConfigurations": [ { "Key": "domain-name", "Values": [ { "Value": "us-east-2.compute.internal" } ] }, { "Key": "domain-name-servers", "Values": [ { "Value": "AmazonProvidedDNS" } ] } ], "DhcpOptionsId": "dopt-19edf471", "OwnerId": "111122223333" }, { "DhcpConfigurations": [ { "Key": "domain-name", "Values": [ { "Value": "us-east-2.compute.internal" } ] }, { "Key": "domain-name-servers", "Values": [ { "Value": "AmazonProvidedDNS" } ] } ], "DhcpOptionsId": "dopt-fEXAMPLE", "OwnerId": "111122223333" } ] }

有关更多信息,请参阅《AWS VPC用户指南》中的 “使用DHCP选项集”

示例 2:描述您的DHCP选项并筛选输出

以下describe-dhcp-options示例描述了您的DHCP选项,并使用筛选器仅返回example.com适用于域名服务器的DHCP选项。该示例使用--query参数在输出中仅显示配置信息和 ID。

aws ec2 describe-dhcp-options \ --filters Name=key,Values=domain-name-servers Name=value,Values=example.com \ --query "DhcpOptions[*].[DhcpConfigurations,DhcpOptionsId]"

输出:

[ [ [ { "Key": "domain-name", "Values": [ { "Value": "example.com" } ] }, { "Key": "domain-name-servers", "Values": [ { "Value": "172.16.16.16" } ] } ], "dopt-001122334455667ab" ] ]

有关更多信息,请参阅《AWS VPC用户指南》中的 “使用DHCP选项集”

以下代码示例演示如何使用 describe-egress-only-internet-gateways

AWS CLI

描述您的仅限出口的互联网网关

此示例描述了您的仅限出口的互联网网关。

命令:

aws ec2 describe-egress-only-internet-gateways

输出:

{ "EgressOnlyInternetGateways": [ { "EgressOnlyInternetGatewayId": "eigw-015e0e244e24dfe8a", "Attachments": [ { "State": "attached", "VpcId": "vpc-0c62a468" } ] } ] }

以下代码示例演示如何使用 describe-elastic-gpus

AWS CLI

描述弹性 GPU

命令:

aws ec2 describe-elastic-gpus --elastic-gpu-ids egpu-12345678901234567890abcdefghijkl

以下代码示例演示如何使用 describe-export-image-tasks

AWS CLI

监视导出图像任务

以下describe-export-image-tasks示例检查指定导出图像任务的状态。在 Amazon S3 中生成的图像文件是my-export-bucket/exports/export-ami-1234567890abcdef0.vmdk

aws ec2 describe-export-image-tasks \ --export-image-task-ids export-ami-1234567890abcdef0

正在执行的导出图像任务的输出。

{ "ExportImageTasks": [ { "ExportImageTaskId": "export-ami-1234567890abcdef0" "Progress": "21", "S3ExportLocation": { "S3Bucket": "my-export-bucket", "S3Prefix": "exports/" }, "Status": "active", "StatusMessage": "updating" } ] }

已完成的导出图像任务的输出。

{ "ExportImageTasks": [ { "ExportImageTaskId": "export-ami-1234567890abcdef0" "S3ExportLocation": { "S3Bucket": "my-export-bucket", "S3Prefix": "exports/" }, "Status": "completed" } ] }

有关更多信息,请参阅《虚拟机导入/导出用户AMI指南》中的从中导出虚拟机

以下代码示例演示如何使用 describe-export-tasks

AWS CLI

列出有关实例导出任务的详细信息

此示例描述了 ID 为 export-i-fh 8sjjsq 的导出任务。

命令:

aws ec2 describe-export-tasks --export-task-ids export-i-fh8sjjsq

输出:

{ "ExportTasks": [ { "State": "active", "InstanceExportDetails": { "InstanceId": "i-1234567890abcdef0", "TargetEnvironment": "vmware" }, "ExportToS3Task": { "S3Bucket": "myexportbucket", "S3Key": "RHEL5export-i-fh8sjjsq.ova", "DiskImageFormat": "vmdk", "ContainerFormat": "ova" }, "Description": "RHEL5 instance", "ExportTaskId": "export-i-fh8sjjsq" } ] }

以下代码示例演示如何使用 describe-fast-launch-images

AWS CLI

描述为加快启动速度而配置AMIs的 Windows 的详细信息

以下describe-fast-launch-images示例描述了您账户AMIs中为更快启动而配置的各项的详细信息,包括资源类型、快照配置、启动模板详细信息、并行启动的最大数量、AMI所有者 ID、快速启动配置的状态、状态更改的原因以及状态更改发生的时间。

aws ec2 describe-fast-launch-images

输出:

{ "FastLaunchImages": [ { "ImageId": "ami-01234567890abcedf", "ResourceType": "snapshot", "SnapshotConfiguration": {}, "LaunchTemplate": { "LaunchTemplateId": "lt-01234567890abcedf", "LaunchTemplateName": "EC2FastLaunchDefaultResourceCreation-a8c6215d-94e6-441b-9272-dbd1f87b07e2", "Version": "1" }, "MaxParallelLaunches": 6, "OwnerId": "0123456789123", "State": "enabled", "StateTransitionReason": "Client.UserInitiated", "StateTransitionTime": "2022-01-27T22:20:06.552000+00:00" } ] }

有关配置 Windows 以加快启动速度AMI的更多信息,请参阅 Amazon EC2 用户指南中的配置您的AMI以加快启动速度

以下代码示例演示如何使用 describe-fast-snapshot-restores

AWS CLI

描述快速快照恢复

以下describe-fast-snapshot-restores示例显示了状态为的所有快速快照恢复的disabled详细信息。

aws ec2 describe-fast-snapshot-restores \ --filters Name=state,Values=disabled

输出:

{ "FastSnapshotRestores": [ { "SnapshotId": "snap-1234567890abcdef0", "AvailabilityZone": "us-west-2c", "State": "disabled", "StateTransitionReason": "Client.UserInitiated - Lifecycle state transition", "OwnerId": "123456789012", "EnablingTime": "2020-01-25T23:57:49.596Z", "OptimizingTime": "2020-01-25T23:58:25.573Z", "EnabledTime": "2020-01-25T23:59:29.852Z", "DisablingTime": "2020-01-26T00:40:56.069Z", "DisabledTime": "2020-01-26T00:41:27.390Z" } ] }

以下describe-fast-snapshot-restores示例描述了所有快速快照恢复。

aws ec2 describe-fast-snapshot-restores

以下代码示例演示如何使用 describe-fleet-history

AWS CLI

描述EC2舰队的历史

以下describe-fleet-history示例返回指定EC2舰队从指定时间开始的历史记录。输出适用于具有两个正在运行的实例的EC2队列。

aws ec2 describe-fleet-history \ --fleet-id fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE \ --start-time 2020-09-01T00:00:00Z

输出:

{ "HistoryRecords": [ { "EventInformation": { "EventSubType": "submitted" }, "EventType": "fleetRequestChange", "Timestamp": "2020-09-01T18:26:05.000Z" }, { "EventInformation": { "EventSubType": "active" }, "EventType": "fleetRequestChange", "Timestamp": "2020-09-01T18:26:15.000Z" }, { "EventInformation": { "EventDescription": "t2.small, ami-07c8bc5c1ce9598c3, ...", "EventSubType": "progress" }, "EventType": "fleetRequestChange", "Timestamp": "2020-09-01T18:26:17.000Z" }, { "EventInformation": { "EventDescription": "{\"instanceType\":\"t2.small\", ...}", "EventSubType": "launched", "InstanceId": "i-083a1c446e66085d2" }, "EventType": "instanceChange", "Timestamp": "2020-09-01T18:26:17.000Z" }, { "EventInformation": { "EventDescription": "{\"instanceType\":\"t2.small\", ...}", "EventSubType": "launched", "InstanceId": "i-090db02406cc3c2d6" }, "EventType": "instanceChange", "Timestamp": "2020-09-01T18:26:17.000Z" } ], "LastEvaluatedTime": "2020-09-01T19:10:19.000Z", "FleetId": "fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE", "StartTime": "2020-08-31T23:53:20.000Z" }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的管理EC2队列

以下代码示例演示如何使用 describe-fleet-instances

AWS CLI

描述EC2舰队的运行实例

以下describe-fleet-instances示例描述了指定EC2队列的正在运行的实例。

aws ec2 describe-fleet-instances \ --fleet-id 12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE

输出:

{ "ActiveInstances": [ { "InstanceId": "i-090db02406cc3c2d6", "InstanceType": "t2.small", "SpotInstanceRequestId": "sir-a43gtpfk", "InstanceHealth": "healthy" }, { "InstanceId": "i-083a1c446e66085d2", "InstanceType": "t2.small", "SpotInstanceRequestId": "sir-iwcit2nj", "InstanceHealth": "healthy" } ], "FleetId": "fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE" }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的管理EC2队列

以下代码示例演示如何使用 describe-fleets

AWS CLI

描述EC2舰队

以下describe-fleets示例描述了指定的EC2舰队。

aws ec2 describe-fleets \ --fleet-ids fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE

输出:

{ "Fleets": [ { "ActivityStatus": "pending_fulfillment", "CreateTime": "2020-09-01T18:26:05.000Z", "FleetId": "fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE", "FleetState": "active", "ExcessCapacityTerminationPolicy": "termination", "FulfilledCapacity": 0.0, "FulfilledOnDemandCapacity": 0.0, "LaunchTemplateConfigs": [ { "LaunchTemplateSpecification": { "LaunchTemplateId": "lt-0e632f2855a979cd5", "Version": "1" } } ], "TargetCapacitySpecification": { "TotalTargetCapacity": 2, "OnDemandTargetCapacity": 0, "SpotTargetCapacity": 2, "DefaultTargetCapacityType": "spot" }, "TerminateInstancesWithExpiration": false, "Type": "maintain", "ReplaceUnhealthyInstances": false, "SpotOptions": { "AllocationStrategy": "lowestPrice", "InstanceInterruptionBehavior": "terminate", "InstancePoolsToUseCount": 1 }, "OnDemandOptions": { "AllocationStrategy": "lowestPrice" } } ] }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的管理EC2队列

以下代码示例演示如何使用 describe-flow-logs

AWS CLI

示例 1:描述您的所有流日志

以下describe-flow-logs示例显示了所有流日志的详细信息。

aws ec2 describe-flow-logs

输出:

{ "FlowLogs": [ { "CreationTime": "2018-02-21T13:22:12.644Z", "DeliverLogsPermissionArn": "arn:aws:iam::123456789012:role/flow-logs-role", "DeliverLogsStatus": "SUCCESS", "FlowLogId": "fl-aabbccdd112233445", "MaxAggregationInterval": 600, "FlowLogStatus": "ACTIVE", "LogGroupName": "FlowLogGroup", "ResourceId": "subnet-12345678901234567", "TrafficType": "ALL", "LogDestinationType": "cloud-watch-logs", "LogFormat": "${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action} ${log-status}" }, { "CreationTime": "2020-02-04T15:22:29.986Z", "DeliverLogsStatus": "SUCCESS", "FlowLogId": "fl-01234567890123456", "MaxAggregationInterval": 60, "FlowLogStatus": "ACTIVE", "ResourceId": "vpc-00112233445566778", "TrafficType": "ACCEPT", "LogDestinationType": "s3", "LogDestination": "arn:aws:s3:::my-flow-log-bucket/custom", "LogFormat": "${version} ${vpc-id} ${subnet-id} ${instance-id} ${interface-id} ${account-id} ${type} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${pkt-srcaddr} ${pkt-dstaddr} ${protocol} ${bytes} ${packets} ${start} ${end} ${action} ${tcp-flags} ${log-status}" } ] }

示例 2:描述您的流日志的子集

以下describe-flow-logs示例使用筛选器仅显示 Amazon CloudWatch Logs 中指定日志组中的流日志的详细信息。

aws ec2 describe-flow-logs \ --filter "Name=log-group-name,Values=MyFlowLogs"

以下代码示例演示如何使用 describe-fpga-image-attribute

AWS CLI

描述 Amazon FPGA 图片的属性

此示例描述了指定项的加载权限AFI。

命令:

aws ec2 describe-fpga-image-attribute --fpga-image-id afi-0d123e123bfc85abc --attribute loadPermission

输出:

{ "FpgaImageAttribute": { "FpgaImageId": "afi-0d123e123bfc85abc", "LoadPermissions": [ { "UserId": "123456789012" } ] } }

以下代码示例演示如何使用 describe-fpga-images

AWS CLI

描述亚马逊FPGA图片

此示例描述AFIs了由账户拥有的内容123456789012

命令:

aws ec2 describe-fpga-images --filters Name=owner-id,Values=123456789012

输出:

{ "FpgaImages": [ { "UpdateTime": "2017-12-22T12:09:14.000Z", "Name": "my-afi", "PciId": { "SubsystemVendorId": "0xfedd", "VendorId": "0x1d0f", "DeviceId": "0xf000", "SubsystemId": "0x1d51" }, "FpgaImageGlobalId": "agfi-123cb27b5e84a0abc", "Public": false, "State": { "Code": "available" }, "ShellVersion": "0x071417d3", "OwnerId": "123456789012", "FpgaImageId": "afi-0d123e123bfc85abc", "CreateTime": "2017-12-22T11:43:33.000Z", "Description": "my-afi" } ] }

以下代码示例演示如何使用 describe-host-reservation-offerings

AWS CLI

描述专用主机预留服务

此示例描述了可供购买的 M4 实例系列的专用主机预留。

命令:

aws ec2 describe-host-reservation-offerings --filter Name=instance-family,Values=m4

输出:

{ "OfferingSet": [ { "HourlyPrice": "1.499", "OfferingId": "hro-03f707bf363b6b324", "InstanceFamily": "m4", "PaymentOption": "NoUpfront", "UpfrontPrice": "0.000", "Duration": 31536000 }, { "HourlyPrice": "1.045", "OfferingId": "hro-0ef9181cabdef7a02", "InstanceFamily": "m4", "PaymentOption": "NoUpfront", "UpfrontPrice": "0.000", "Duration": 94608000 }, { "HourlyPrice": "0.714", "OfferingId": "hro-04567a15500b92a51", "InstanceFamily": "m4", "PaymentOption": "PartialUpfront", "UpfrontPrice": "6254.000", "Duration": 31536000 }, { "HourlyPrice": "0.484", "OfferingId": "hro-0d5d7a9d23ed7fbfe", "InstanceFamily": "m4", "PaymentOption": "PartialUpfront", "UpfrontPrice": "12720.000", "Duration": 94608000 }, { "HourlyPrice": "0.000", "OfferingId": "hro-05da4108ca998c2e5", "InstanceFamily": "m4", "PaymentOption": "AllUpfront", "UpfrontPrice": "23913.000", "Duration": 94608000 }, { "HourlyPrice": "0.000", "OfferingId": "hro-0a9f9be3b95a3dc8f", "InstanceFamily": "m4", "PaymentOption": "AllUpfront", "UpfrontPrice": "12257.000", "Duration": 31536000 } ] }

以下代码示例演示如何使用 describe-host-reservations

AWS CLI

描述您账户中的专用主机预留

此示例描述了您账户中的专用主机预留。

命令:

aws ec2 describe-host-reservations

输出:

{ "HostReservationSet": [ { "Count": 1, "End": "2019-01-10T12:14:09Z", "HourlyPrice": "1.499", "InstanceFamily": "m4", "OfferingId": "hro-03f707bf363b6b324", "PaymentOption": "NoUpfront", "State": "active", "HostIdSet": [ "h-013abcd2a00cbd123" ], "Start": "2018-01-10T12:14:09Z", "HostReservationId": "hr-0d418a3a4ffc669ae", "UpfrontPrice": "0.000", "Duration": 31536000 } ] }

以下代码示例演示如何使用 describe-hosts

AWS CLI

查看有关专用主机的详细信息

以下describe-hosts示例显示了您 AWS 账户中available专用主机的详细信息。

aws ec2 describe-hosts --filter "Name=state,Values=available"

输出:

{ "Hosts": [ { "HostId": "h-07879acf49EXAMPLE", "Tags": [ { "Value": "production", "Key": "purpose" } ], "HostProperties": { "Cores": 48, "TotalVCpus": 96, "InstanceType": "m5.large", "Sockets": 2 }, "Instances": [], "State": "available", "AvailabilityZone": "eu-west-1a", "AvailableCapacity": { "AvailableInstanceCapacity": [ { "AvailableCapacity": 48, "InstanceType": "m5.large", "TotalCapacity": 48 } ], "AvailableVCpus": 96 }, "HostRecovery": "on", "AllocationTime": "2019-08-19T08:57:44.000Z", "AutoPlacement": "off" } ] }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的查看专用主机

以下代码示例演示如何使用 describe-iam-instance-profile-associations

AWS CLI

描述IAM实例配置文件关联

此示例描述了您的所有IAM实例配置文件关联。

命令:

aws ec2 describe-iam-instance-profile-associations

输出:

{ "IamInstanceProfileAssociations": [ { "InstanceId": "i-09eb09efa73ec1dee", "State": "associated", "AssociationId": "iip-assoc-0db249b1f25fa24b8", "IamInstanceProfile": { "Id": "AIPAJVQN4F5WVLGCJDRGM", "Arn": "arn:aws:iam::123456789012:instance-profile/admin-role" } }, { "InstanceId": "i-0402909a2f4dffd14", "State": "associating", "AssociationId": "iip-assoc-0d1ec06278d29f44a", "IamInstanceProfile": { "Id": "AGJAJVQN4F5WVLGCJABCM", "Arn": "arn:aws:iam::123456789012:instance-profile/user1-role" } } ] }

以下代码示例演示如何使用 describe-id-format

AWS CLI

示例 1:描述资源的 ID 格式

以下describe-id-format示例描述了安全组的 ID 格式。

aws ec2 describe-id-format \ --resource security-group

在以下示例输出中,该Deadline值表示该资源类型从短 ID 格式永久切换到长 ID 格式的最后期限已于 2018 年 8 月 15 UTC 日 00:00 到期。

{ "Statuses": [ { "Deadline": "2018-08-15T00:00:00.000Z", "Resource": "security-group", "UseLongIds": true } ] }

示例 2:描述所有资源的 ID 格式

以下describe-id-format示例描述了所有资源类型的 ID 格式。所有支持短 ID 格式的资源类型均已切换为使用长 ID 格式。

aws ec2 describe-id-format

以下代码示例演示如何使用 describe-identity-id-format

AWS CLI

描述IAM角色的 ID 格式

以下describe-identity-id-format示例描述了由您的 AWS 账户EC2Role中的IAM角色创建的实例所接收的 ID 格式。

aws ec2 describe-identity-id-format \ --principal-arn arn:aws:iam::123456789012:role/my-iam-role \ --resource instance

以下输出表明此角色创建的实例IDs以长 ID 格式接收。

{ "Statuses": [ { "Deadline": "2016-12-15T00:00:00Z", "Resource": "instance", "UseLongIds": true } ] }

描述IAM用户的 ID 格式

以下describe-identity-id-format示例描述了IAM用户在您的 AWS 账户AdminUser中创建的快照所接收的 ID 格式。

aws ec2 describe-identity-id-format \ --principal-arn arn:aws:iam::123456789012:user/AdminUser \ --resource snapshot

输出表明此用户创建的快照IDs以长 ID 格式接收。

{ "Statuses": [ { "Deadline": "2016-12-15T00:00:00Z", "Resource": "snapshot", "UseLongIds": true } ] }

以下代码示例演示如何使用 describe-image-attribute

AWS CLI

描述的启动权限 AMI

此示例描述了指定项的启动权限AMI。

命令:

aws ec2 describe-image-attribute --image-id ami-5731123e --attribute launchPermission

输出:

{ "LaunchPermissions": [ { "UserId": "123456789012" } ], "ImageId": "ami-5731123e", }

描述某人的产品代码 AMI

此示例描述了指定的产品代码AMI。请注意,这AMI没有产品代码。

命令:

aws ec2 describe-image-attribute --image-id ami-5731123e --attribute productCodes

输出:

{ "ProductCodes": [], "ImageId": "ami-5731123e", }

以下代码示例演示如何使用 describe-images

AWS CLI

示例 1:描述 AMI

以下describe-images示例描述了在指定区域AMI中指定的内容。

aws ec2 describe-images \ --region us-east-1 \ --image-ids ami-1234567890EXAMPLE

输出:

{ "Images": [ { "VirtualizationType": "hvm", "Description": "Provided by Red Hat, Inc.", "PlatformDetails": "Red Hat Enterprise Linux", "EnaSupport": true, "Hypervisor": "xen", "State": "available", "SriovNetSupport": "simple", "ImageId": "ami-1234567890EXAMPLE", "UsageOperation": "RunInstances:0010", "BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "SnapshotId": "snap-111222333444aaabb", "DeleteOnTermination": true, "VolumeType": "gp2", "VolumeSize": 10, "Encrypted": false } } ], "Architecture": "x86_64", "ImageLocation": "123456789012/RHEL-8.0.0_HVM-20190618-x86_64-1-Hourly2-GP2", "RootDeviceType": "ebs", "OwnerId": "123456789012", "RootDeviceName": "/dev/sda1", "CreationDate": "2019-05-10T13:17:12.000Z", "Public": true, "ImageType": "machine", "Name": "RHEL-8.0.0_HVM-20190618-x86_64-1-Hourly2-GP2" } ] }

有关更多信息,请参阅《亚马逊EC2用户指南》中的亚马逊系统映像 (AMI)

示例 2:AMIs根据过滤器进行描述

以下describe-images示例描述了由亚马逊AMIs提供的、由亚马逊提供支持的 Windows EBS。

aws ec2 describe-images \ --owners amazon \ --filters "Name=platform,Values=windows" "Name=root-device-type,Values=ebs"

有关 describe-images 的输出示例,请参阅示例 1。

有关使用筛选条件的其他示例,请参阅 Amazon EC2 用户指南中的列出和筛选您的资源

示例 3:AMIs根据标签进行描述

以下describe-images示例描述了所有带有AMIs该标签的内容Type=Custom。该示例使用--query参数仅显示AMIIDs。

aws ec2 describe-images \ --filters "Name=tag:Type,Values=Custom" \ --query 'Images[*].[ImageId]' \ --output text

输出:

ami-1234567890EXAMPLE ami-0abcdef1234567890

有关使用标签筛选条件的其他示例,请参阅 Amazon EC2 用户指南中的使用标签

以下代码示例演示如何使用 describe-import-image-tasks

AWS CLI

监视导入图像任务

以下describe-import-image-tasks示例检查指定导入映像任务的状态。

aws ec2 describe-import-image-tasks \ --import-task-ids import-ami-1234567890abcdef0

正在进行的导入图像任务的输出。

{ "ImportImageTasks": [ { "ImportTaskId": "import-ami-1234567890abcdef0", "Progress": "28", "SnapshotDetails": [ { "DiskImageSize": 705638400.0, "Format": "ova", "Status": "completed", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.ova" } } ], "Status": "active", "StatusMessage": "converting" } ] }

已完成的导入图像任务的输出。结果的 ID AMI 由提供ImageId

{ "ImportImageTasks": [ { "ImportTaskId": "import-ami-1234567890abcdef0", "ImageId": "ami-1234567890abcdef0", "SnapshotDetails": [ { "DiskImageSize": 705638400.0, "Format": "ova", "SnapshotId": "snap-1234567890abcdef0" "Status": "completed", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.ova" } } ], "Status": "completed" } ] }

以下代码示例演示如何使用 describe-import-snapshot-tasks

AWS CLI

监视导入快照任务

以下describe-import-snapshot-tasks示例检查指定导入快照任务的状态。

aws ec2 describe-import-snapshot-tasks \ --import-task-ids import-snap-1234567890abcdef0

正在进行的导入快照任务的输出:

{ "ImportSnapshotTasks": [ { "Description": "My server VMDK", "ImportTaskId": "import-snap-1234567890abcdef0", "SnapshotTaskDetail": { "Description": "My server VMDK", "DiskImageSize": "705638400.0", "Format": "VMDK", "Progress": "42", "Status": "active", "StatusMessage": "downloading/converting", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.vmdk" } } } ] }

已完成的导入快照任务的输出。生成的快照的 ID 由提供SnapshotId

{ "ImportSnapshotTasks": [ { "Description": "My server VMDK", "ImportTaskId": "import-snap-1234567890abcdef0", "SnapshotTaskDetail": { "Description": "My server VMDK", "DiskImageSize": "705638400.0", "Format": "VMDK", "SnapshotId": "snap-1234567890abcdef0" "Status": "completed", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.vmdk" } } } ] }

以下代码示例演示如何使用 describe-instance-attribute

AWS CLI

描述实例类型

此示例描述了指定实例的实例类型。

命令:

aws ec2 describe-instance-attribute --instance-id i-1234567890abcdef0 --attribute instanceType

输出:

{ "InstanceId": "i-1234567890abcdef0" "InstanceType": { "Value": "t1.micro" } }

描述该 disableApiTermination 属性

此示例描述了指定实例的disableApiTermination属性。

命令:

aws ec2 describe-instance-attribute --instance-id i-1234567890abcdef0 --attribute disableApiTermination

输出:

{ "InstanceId": "i-1234567890abcdef0" "DisableApiTermination": { "Value": "false" } }

描述实例的块储存设备映射

此示例描述了指定实例的blockDeviceMapping属性。

命令:

aws ec2 describe-instance-attribute --instance-id i-1234567890abcdef0 --attribute blockDeviceMapping

输出:

{ "InstanceId": "i-1234567890abcdef0" "BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "Status": "attached", "DeleteOnTermination": true, "VolumeId": "vol-049df61146c4d7901", "AttachTime": "2013-05-17T22:42:34.000Z" } }, { "DeviceName": "/dev/sdf", "Ebs": { "Status": "attached", "DeleteOnTermination": false, "VolumeId": "vol-049df61146c4d7901", "AttachTime": "2013-09-10T23:07:00.000Z" } } ], }

以下代码示例演示如何使用 describe-instance-connect-endpoints

AWS CLI

描述 Instance Conn EC2 ect 终端节点

以下describe-instance-connect-endpoints示例描述了指定EC2的 Instance Connect 终端节点。

aws ec2 describe-instance-connect-endpoints \ --region us-east-1 \ --instance-connect-endpoint-ids eice-0123456789example

输出:

{ "InstanceConnectEndpoints": [ { "OwnerId": "111111111111", "InstanceConnectEndpointId": "eice-0123456789example", "InstanceConnectEndpointArn": "arn:aws:ec2:us-east-1:111111111111:instance-connect-endpoint/eice-0123456789example", "State": "create-complete", "StateMessage": "", "DnsName": "eice-0123456789example.b67b86ba.ec2-instance-connect-endpoint.us-east-1.amazonaws.com", "NetworkInterfaceIds": [ "eni-0123456789example" ], "VpcId": "vpc-0123abcd", "AvailabilityZone": "us-east-1d", "CreatedAt": "2023-02-07T12:05:37+00:00", "SubnetId": "subnet-0123abcd", "Tags": [] } ] }

有关更多信息,请参阅 Amazon EC2 用户指南中的创EC2建 Instance Connect 终端节点

以下代码示例演示如何使用 describe-instance-credit-specifications

AWS CLI

描述CPU使用一个或多个实例的积分选项

以下describe-instance-credit-specifications示例描述了指定实例的CPU积分选项。

aws ec2 describe-instance-credit-specifications \ --instance-ids i-1234567890abcdef0

输出:

{ "InstanceCreditSpecifications": [ { "InstanceId": "i-1234567890abcdef0", "CpuCredits": "unlimited" } ] }

有关更多信息,请参阅 Amazon EC2 用户指南中的使用突发性能实例

以下代码示例演示如何使用 describe-instance-event-notification-attributes

AWS CLI

描述计划事件通知的标签

以下describe-instance-event-notification-attributes示例描述了要在计划的事件通知中显示的标签。

aws ec2 describe-instance-event-notification-attributes

输出:

{ "InstanceTagAttribute": { "InstanceTagKeys": [], "IncludeAllTagsOfInstance": true } }

有关更多信息,请参阅适用Linux 实例的 Amazon 弹性计算云用户指南中的实例计划事件

以下代码示例演示如何使用 describe-instance-event-windows

AWS CLI

示例 1:描述所有事件窗口

以下describe-instance-event-windows示例描述了指定区域中的所有事件窗口。

aws ec2 describe-instance-event-windows \ --region us-east-1

输出:

{ "InstanceEventWindows": [ { "InstanceEventWindowId": "iew-0abcdef1234567890", "Name": "myEventWindowName", "CronExpression": "* 21-23 * * 2,3", "AssociationTarget": { "InstanceIds": [ "i-1234567890abcdef0", "i-0598c7d356eba48d7" ], "Tags": [], "DedicatedHostIds": [] }, "State": "active", "Tags": [] } ... ], "NextToken": "9d624e0c-388b-4862-a31e-a85c64fc1d4a" }

示例 2:描述特定的事件窗口

以下describe-instance-event-windows示例通过使用instance-event-window参数描述特定事件窗口来描述特定事件。

aws ec2 describe-instance-event-windows \ --region us-east-1 \ --instance-event-window-ids iew-0abcdef1234567890

输出:

{ "InstanceEventWindows": [ { "InstanceEventWindowId": "iew-0abcdef1234567890", "Name": "myEventWindowName", "CronExpression": "* 21-23 * * 2,3", "AssociationTarget": { "InstanceIds": [ "i-1234567890abcdef0", "i-0598c7d356eba48d7" ], "Tags": [], "DedicatedHostIds": [] }, "State": "active", "Tags": [] } }

示例 3:描述与一个或多个过滤器匹配的事件窗口

以下describe-instance-event-windows示例使用filter参数描述了与一个或多个过滤器匹配的事件窗口。instance-id过滤器用于描述与指定实例关联的所有事件窗口。使用筛选器时,它会进行直接匹配。但是,instance-id 筛选器不同。如果与实例 ID 没有直接匹配,则它会退回到与事件窗口的间接关联,例如实例的标签或专用主机 ID(如果实例是专用主机)。

aws ec2 describe-instance-event-windows \ --region us-east-1 \ --filters Name=instance-id,Values=i-1234567890abcdef0 \ --max-results 100 \ --next-token <next-token-value>

输出:

{ "InstanceEventWindows": [ { "InstanceEventWindowId": "iew-0dbc0adb66f235982", "TimeRanges": [ { "StartWeekDay": "sunday", "StartHour": 2, "EndWeekDay": "sunday", "EndHour": 8 } ], "Name": "myEventWindowName", "AssociationTarget": { "InstanceIds": [], "Tags": [], "DedicatedHostIds": [ "h-0140d9a7ecbd102dd" ] }, "State": "active", "Tags": [] } ] }

在示例输出中,实例位于与事件窗口关联的专用主机上。

有关事件窗口限制的信息,请参阅 Amazon EC2 用户指南中的注意事项

以下代码示例演示如何使用 describe-instance-status

AWS CLI

描述实例的状态

以下 describe-instance-status 示例描述了指定实例的当前状态。

aws ec2 describe-instance-status \ --instance-ids i-1234567890abcdef0

输出:

{ "InstanceStatuses": [ { "InstanceId": "i-1234567890abcdef0", "InstanceState": { "Code": 16, "Name": "running" }, "AvailabilityZone": "us-east-1d", "SystemStatus": { "Status": "ok", "Details": [ { "Status": "passed", "Name": "reachability" } ] }, "InstanceStatus": { "Status": "ok", "Details": [ { "Status": "passed", "Name": "reachability" } ] } } ] }

有关更多信息,请参阅 Amazon EC2 用户指南中的监控实例状态

以下代码示例演示如何使用 describe-instance-topology

AWS CLI

描述所有实例的实例拓扑

以下describe-instance-topology示例描述了与该命令支持的实例类型相匹配的所有实例的拓扑。

aws ec2 describe-instance-topology \ --region us-west-2

输出:

{ "Instances": [ { "InstanceId": "i-1111111111example", "InstanceType": "p4d.24xlarge", "GroupName": "my-ml-cpg", "NetworkNodes": [ "nn-1111111111example", "nn-2222222222example", "nn-3333333333example" ], "ZoneId": "usw2-az2", "AvailabilityZone": "us-west-2a" }, { "InstanceId": "i-2222222222example", "InstanceType": "p4d.24xlarge", "NetworkNodes": [ "nn-1111111111example", "nn-2222222222example", "nn-3333333333example" ], "ZoneId": "usw2-az2", "AvailabilityZone": "us-west-2a" }, { "InstanceId": "i-3333333333example", "InstanceType": "trn1.32xlarge", "NetworkNodes": [ "nn-1212121212example", "nn-1211122211example", "nn-1311133311example" ], "ZoneId": "usw2-az4", "AvailabilityZone": "us-west-2d" }, { "InstanceId": "i-444444444example", "InstanceType": "trn1.2xlarge", "NetworkNodes": [ "nn-1111111111example", "nn-5434334334example", "nn-1235301234example" ], "ZoneId": "usw2-az2", "AvailabilityZone": "us-west-2a" } ], "NextToken": "SomeEncryptedToken" }

有关更多信息,包括更多示例,请参阅亚马逊EC2用户指南中的亚马逊EC2实例拓扑

以下代码示例演示如何使用 describe-instance-type-offerings

AWS CLI

示例 1:列出某个地区提供的实例类型

以下describe-instance-type-offerings示例列出了配置为默认区域的区域中提供的实例类型 AWS CLI。

aws ec2 describe-instance-type-offerings

要列出不同区域提供的实例类型,请使用--region参数指定区域。

aws ec2 describe-instance-type-offerings \ --region us-east-2

输出:

{ "InstanceTypeOfferings": [ { "InstanceType": "m5.2xlarge", "LocationType": "region", "Location": "us-east-2" }, { "InstanceType": "t3.micro", "LocationType": "region", "Location": "us-east-2" }, ... ] }

示例 2:列出可用区中提供的实例类型

以下describe-instance-type-offerings示例列出了指定可用区中提供的实例类型。可用区必须位于指定的区域内。

aws ec2 describe-instance-type-offerings \ --location-type availability-zone \ --filters Name=location,Values=us-east-2a \ --region us-east-2

示例 3:检查是否支持某个实例类型

以下describe-instance-type-offerings命令指示指定区域是否支持该c5.xlarge实例类型。

aws ec2 describe-instance-type-offerings \ --filters Name=instance-type,Values=c5.xlarge \ --region us-east-2

以下describe-instance-type-offerings示例列出了指定区域支持的所有 C5 实例类型。

aws ec2 describe-instance-type-offerings \ --filters Name=instance-type,Values=c5* \ --query "InstanceTypeOfferings[].InstanceType" \ --region us-east-2

输出:

[ "c5d.12xlarge", "c5d.9xlarge", "c5n.xlarge", "c5.xlarge", "c5d.metal", "c5n.metal", "c5.large", "c5d.2xlarge", "c5n.4xlarge", "c5.2xlarge", "c5n.large", "c5n.9xlarge", "c5d.large", "c5.18xlarge", "c5d.18xlarge", "c5.12xlarge", "c5n.18xlarge", "c5.metal", "c5d.4xlarge", "c5.24xlarge", "c5d.xlarge", "c5n.2xlarge", "c5d.24xlarge", "c5.9xlarge", "c5.4xlarge" ]

以下代码示例演示如何使用 describe-instance-types

AWS CLI

示例 1:描述实例类型

以下 describe-instance-types 示例显示指定实例类型的详细信息。

aws ec2 describe-instance-types \ --instance-types t2.micro

输出:

{ "InstanceTypes": [ { "InstanceType": "t2.micro", "CurrentGeneration": true, "FreeTierEligible": true, "SupportedUsageClasses": [ "on-demand", "spot" ], "SupportedRootDeviceTypes": [ "ebs" ], "BareMetal": false, "Hypervisor": "xen", "ProcessorInfo": { "SupportedArchitectures": [ "i386", "x86_64" ], "SustainedClockSpeedInGhz": 2.5 }, "VCpuInfo": { "DefaultVCpus": 1, "DefaultCores": 1, "DefaultThreadsPerCore": 1, "ValidCores": [ 1 ], "ValidThreadsPerCore": [ 1 ] }, "MemoryInfo": { "SizeInMiB": 1024 }, "InstanceStorageSupported": false, "EbsInfo": { "EbsOptimizedSupport": "unsupported", "EncryptionSupport": "supported" }, "NetworkInfo": { "NetworkPerformance": "Low to Moderate", "MaximumNetworkInterfaces": 2, "Ipv4AddressesPerInterface": 2, "Ipv6AddressesPerInterface": 2, "Ipv6Supported": true, "EnaSupport": "unsupported" }, "PlacementGroupInfo": { "SupportedStrategies": [ "partition", "spread" ] }, "HibernationSupported": false, "BurstablePerformanceSupported": true, "DedicatedHostsSupported": false, "AutoRecoverySupported": true } ] }

有关更多信息,请参阅适用于 Linux 实例的 Amazon 弹性计算云用户指南中的实例类型

示例 2:筛选可用的实例类型

可以指定筛选器,将结果范围限定为具有特定特征的实例类型。以下 describe-instance-types 示例列出支持休眠的实例类型。

aws ec2 describe-instance-types \ --filters Name=hibernation-supported,Values=true --query 'InstanceTypes[*].InstanceType'

输出:

[ "m5.8xlarge", "r3.large", "c3.8xlarge", "r5.large", "m4.4xlarge", "c4.large", "m5.xlarge", "m4.xlarge", "c3.large", "c4.8xlarge", "c4.4xlarge", "c5.xlarge", "c5.12xlarge", "r5.4xlarge", "c5.4xlarge" ]

有关更多信息,请参阅适用于 Linux 实例的 Amazon 弹性计算云用户指南中的实例类型

以下代码示例演示如何使用 describe-instances

AWS CLI

示例 1:描述实例

以下 describe-instances 示例描述了指定的实例。

aws ec2 describe-instances \ --instance-ids i-1234567890abcdef0

输出:

{ "Reservations": [ { "Groups": [], "Instances": [ { "AmiLaunchIndex": 0, "ImageId": "ami-0abcdef1234567890", "InstanceId": "i-1234567890abcdef0", "InstanceType": "t3.nano", "KeyName": "my-key-pair", "LaunchTime": "2022-11-15T10:48:59+00:00", "Monitoring": { "State": "disabled" }, "Placement": { "AvailabilityZone": "us-east-2a", "GroupName": "", "Tenancy": "default" }, "PrivateDnsName": "ip-10-0-0-157.us-east-2.compute.internal", "PrivateIpAddress": "10-0-0-157", "ProductCodes": [], "PublicDnsName": "ec2-34-253-223-13.us-east-2.compute.amazonaws.com", "PublicIpAddress": "34.253.223.13", "State": { "Code": 16, "Name": "running" }, "StateTransitionReason": "", "SubnetId": "subnet-04a636d18e83cfacb", "VpcId": "vpc-1234567890abcdef0", "Architecture": "x86_64", "BlockDeviceMappings": [ { "DeviceName": "/dev/xvda", "Ebs": { "AttachTime": "2022-11-15T10:49:00+00:00", "DeleteOnTermination": true, "Status": "attached", "VolumeId": "vol-02e6ccdca7de29cf2" } } ], "ClientToken": "1234abcd-1234-abcd-1234-d46a8903e9bc", "EbsOptimized": true, "EnaSupport": true, "Hypervisor": "xen", "IamInstanceProfile": { "Arn": "arn:aws:iam::111111111111:instance-profile/AmazonSSMRoleForInstancesQuickSetup", "Id": "111111111111111111111" }, "NetworkInterfaces": [ { "Association": { "IpOwnerId": "amazon", "PublicDnsName": "ec2-34-253-223-13.us-east-2.compute.amazonaws.com", "PublicIp": "34.253.223.13" }, "Attachment": { "AttachTime": "2022-11-15T10:48:59+00:00", "AttachmentId": "eni-attach-1234567890abcdefg", "DeleteOnTermination": true, "DeviceIndex": 0, "Status": "attached", "NetworkCardIndex": 0 }, "Description": "", "Groups": [ { "GroupName": "launch-wizard-146", "GroupId": "sg-1234567890abcdefg" } ], "Ipv6Addresses": [], "MacAddress": "00:11:22:33:44:55", "NetworkInterfaceId": "eni-1234567890abcdefg", "OwnerId": "104024344472", "PrivateDnsName": "ip-10-0-0-157.us-east-2.compute.internal", "PrivateIpAddress": "10-0-0-157", "PrivateIpAddresses": [ { "Association": { "IpOwnerId": "amazon", "PublicDnsName": "ec2-34-253-223-13.us-east-2.compute.amazonaws.com", "PublicIp": "34.253.223.13" }, "Primary": true, "PrivateDnsName": "ip-10-0-0-157.us-east-2.compute.internal", "PrivateIpAddress": "10-0-0-157" } ], "SourceDestCheck": true, "Status": "in-use", "SubnetId": "subnet-1234567890abcdefg", "VpcId": "vpc-1234567890abcdefg", "InterfaceType": "interface" } ], "RootDeviceName": "/dev/xvda", "RootDeviceType": "ebs", "SecurityGroups": [ { "GroupName": "launch-wizard-146", "GroupId": "sg-1234567890abcdefg" } ], "SourceDestCheck": true, "Tags": [ { "Key": "Name", "Value": "my-instance" } ], "VirtualizationType": "hvm", "CpuOptions": { "CoreCount": 1, "ThreadsPerCore": 2 }, "CapacityReservationSpecification": { "CapacityReservationPreference": "open" }, "HibernationOptions": { "Configured": false }, "MetadataOptions": { "State": "applied", "HttpTokens": "optional", "HttpPutResponseHopLimit": 1, "HttpEndpoint": "enabled", "HttpProtocolIpv6": "disabled", "InstanceMetadataTags": "enabled" }, "EnclaveOptions": { "Enabled": false }, "PlatformDetails": "Linux/UNIX", "UsageOperation": "RunInstances", "UsageOperationUpdateTime": "2022-11-15T10:48:59+00:00", "PrivateDnsNameOptions": { "HostnameType": "ip-name", "EnableResourceNameDnsARecord": true, "EnableResourceNameDnsAAAARecord": false }, "MaintenanceOptions": { "AutoRecovery": "default" } } ], "OwnerId": "111111111111", "ReservationId": "r-1234567890abcdefg" } ] }

示例 2:筛选具有指定类型的实例

以下 describe-instances 示例使用筛选器,将结果范围限定为指定类型的实例。

aws ec2 describe-instances \ --filters Name=instance-type,Values=m5.large

有关示例输出,请参阅示例 1。

有关更多信息,请参阅使用 Amazon EC2 用户指南CLI中的列出和筛选

示例 3:筛选具有指定类型和可用区的实例

以下 describe-instances 示例使用多个筛选器,将结果范围限定为同样位于指定可用区且具有指定类型的实例。

aws ec2 describe-instances \ --filters Name=instance-type,Values=t2.micro,t3.micro Name=availability-zone,Values=us-east-2c

有关示例输出,请参阅示例 1。

示例 4:使用JSON文件筛选具有指定类型和可用区的实例

以下describe-instances示例使用JSON输入文件执行与上一个示例相同的筛选。当过滤器变得更加复杂时,可以更轻松地在JSON文件中指定它们。

aws ec2 describe-instances \ --filters file://filters.json

filters.json 的内容:

[ { "Name": "instance-type", "Values": ["t2.micro", "t3.micro"] }, { "Name": "availability-zone", "Values": ["us-east-2c"] } ]

有关示例输出,请参阅示例 1。

示例 5:筛选具有指定 Owner 标签的实例

以下 describe-instances 示例使用标签筛选器,将结果范围限定为具有指定标签键(Owner)标签的实例,无论标签值如何。

aws ec2 describe-instances \ --filters "Name=tag-key,Values=Owner"

有关示例输出,请参阅示例 1。

示例 6:筛选具有指定 my-team 标签值的实例

以下 describe-instances 示例使用标签筛选器,将结果范围限定为具有指定标签值(my-team)标签的实例,无论标签键如何。

aws ec2 describe-instances \ --filters "Name=tag-value,Values=my-team"

有关示例输出,请参阅示例 1。

示例 7:筛选具有指定 Owner 标签和 my-team 值的实例

以下 describe-instances 示例使用标签筛选器,将结果范围限定为具有指定标签值(Owner=my-team)的实例。

aws ec2 describe-instances \ --filters "Name=tag:Owner,Values=my-team"

有关示例输出,请参阅示例 1。

示例 8:仅显示所有实例IDs的实例和子网

以下describe-instances示例使用--query参数仅以JSON格式显示所有实例IDs的实例和子网。

Linux 和 macOS:

aws ec2 describe-instances \ --query 'Reservations[*].Instances[*].{Instance:InstanceId,Subnet:SubnetId}' \ --output json

Windows:

aws ec2 describe-instances ^ --query "Reservations[*].Instances[*].{Instance:InstanceId,Subnet:SubnetId}" ^ --output json

输出:

[ { "Instance": "i-057750d42936e468a", "Subnet": "subnet-069beee9b12030077" }, { "Instance": "i-001efd250faaa6ffa", "Subnet": "subnet-0b715c6b7db68927a" }, { "Instance": "i-027552a73f021f3bd", "Subnet": "subnet-0250c25a1f4e15235" } ... ]

示例 9:筛选指定类型的实例并仅显示其实例 IDs

以下describe-instances示例使用筛选器将结果范围限定为指定类型的实例,并使用--query参数仅显示实例IDs。

aws ec2 describe-instances \ --filters "Name=instance-type,Values=t2.micro" \ --query "Reservations[*].Instances[*].[InstanceId]" \ --output text

输出:

i-031c0dc19de2fb70c i-00d8bff789a736b75 i-0b715c6b7db68927a i-0626d4edd54f1286d i-00b8ae04f9f99908e i-0fc71c25d2374130c

示例 10:筛选指定类型的实例并仅显示其实例IDs、可用区和指定的标签值

以下 describe-instances 示例以表格格式显示实例的实例 ID、可用区和 Name 标签值,这些实例有一个名为 tag-key 的标签。

Linux 和 macOS:

aws ec2 describe-instances \ --filters Name=tag-key,Values=Name \ --query 'Reservations[*].Instances[*].{Instance:InstanceId,AZ:Placement.AvailabilityZone,Name:Tags[?Key==`Name`]|[0].Value}' \ --output table

Windows:

aws ec2 describe-instances ^ --filters Name=tag-key,Values=Name ^ --query "Reservations[*].Instances[*].{Instance:InstanceId,AZ:Placement.AvailabilityZone,Name:Tags[?Key=='Name']|[0].Value}" ^ --output table

输出:

------------------------------------------------------------- | DescribeInstances | +--------------+-----------------------+--------------------+ | AZ | Instance | Name | +--------------+-----------------------+--------------------+ | us-east-2b | i-057750d42936e468a | my-prod-server | | us-east-2a | i-001efd250faaa6ffa | test-server-1 | | us-east-2a | i-027552a73f021f3bd | test-server-2 | +--------------+-----------------------+--------------------+

示例 11:描述分区置放群组中的实例

以下 describe-instances 示例描述了指定的实例。输出包括实例的置放信息,其中包含实例的置放群组名称和分区编号。

aws ec2 describe-instances \ --instance-ids i-0123a456700123456 \ --query "Reservations[*].Instances[*].Placement"

输出:

[ [ { "AvailabilityZone": "us-east-1c", "GroupName": "HDFS-Group-A", "PartitionNumber": 3, "Tenancy": "default" } ] ]

有关更多信息,请参阅 Amazon EC2 用户指南中的描述置放群组中的实例

示例 12:筛选具有指定置放群组和分区编号的实例

以下 describe-instances 示例将结果筛选为仅具有指定置放群组和分区编号的实例。

aws ec2 describe-instances \ --filters "Name=placement-group-name,Values=HDFS-Group-A" "Name=placement-partition-number,Values=7"

以下仅显示输出中的相关信息。

"Instances": [ { "InstanceId": "i-0123a456700123456", "InstanceType": "r4.large", "Placement": { "AvailabilityZone": "us-east-1c", "GroupName": "HDFS-Group-A", "PartitionNumber": 7, "Tenancy": "default" } }, { "InstanceId": "i-9876a543210987654", "InstanceType": "r4.large", "Placement": { "AvailabilityZone": "us-east-1c", "GroupName": "HDFS-Group-A", "PartitionNumber": 7, "Tenancy": "default" } ],

有关更多信息,请参阅 Amazon EC2 用户指南中的描述置放群组中的实例

示例 13:筛选配置为允许从实例元数据访问标签的实例

以下 describe-instances 示例将结果筛选为,仅显示配置为允许从实例元数据访问实例标签的实例。

aws ec2 describe-instances \ --filters "Name=metadata-options.instance-metadata-tags,Values=enabled" \ --query "Reservations[*].Instances[*].InstanceId" \ --output text

预期的输出如下所示。

i-1234567890abcdefg i-abcdefg1234567890 i-11111111aaaaaaaaa i-aaaaaaaa111111111

有关更多信息,请参阅 Amazon EC2 用户指南中的使用实例元数据中的实例标签

以下代码示例演示如何使用 describe-internet-gateways

AWS CLI

描述互联网网关

以下describe-internet-gateways示例描述了指定的互联网网关。

aws ec2 describe-internet-gateways \ --internet-gateway-ids igw-0d0fb496b3EXAMPLE

输出:

{ "InternetGateways": [ { "Attachments": [ { "State": "available", "VpcId": "vpc-0a60eb65b4EXAMPLE" } ], "InternetGatewayId": "igw-0d0fb496b3EXAMPLE", "OwnerId": "123456789012", "Tags": [ { "Key": "Name", "Value": "my-igw" } ] } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的互联网网关

以下代码示例演示如何使用 describe-ipam-pools

AWS CLI

查看IPAM池的详细信息

以下describe-ipam-pools示例显示了池的详细信息。

(Linux):

aws ec2 describe-ipam-pools \ --filters Name=owner-id,Values=123456789012 Name=ipam-scope-id,Values=ipam-scope-02fc38cd4c48e7d38

(视窗):

aws ec2 describe-ipam-pools ^ --filters Name=owner-id,Values=123456789012 Name=ipam-scope-id,Values=ipam-scope-02fc38cd4c48e7d38

输出:

{ "IpamPools": [ { "OwnerId": "123456789012", "IpamPoolId": "ipam-pool-02ec043a19bbe5d08", "IpamPoolArn": "arn:aws:ec2::123456789012:ipam-pool/ipam-pool-02ec043a19bbe5d08", "IpamScopeArn": "arn:aws:ec2::123456789012:ipam-scope/ipam-scope-02fc38cd4c48e7d38", "IpamScopeType": "private", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-08440e7a3acde3908", "IpamRegion": "us-east-1", "Locale": "None", "PoolDepth": 1, "State": "create-complete", "AutoImport": true, "AddressFamily": "ipv4", "AllocationMinNetmaskLength": 16, "AllocationMaxNetmaskLength": 26, "AllocationDefaultNetmaskLength": 24, "AllocationResourceTags": [ { "Key": "Environment", "Value": "Preprod" } ], "Tags": [ { "Key": "Name", "Value": "Preprod pool" } ] } ] }

以下代码示例演示如何使用 describe-ipam-resource-discoveries

AWS CLI

示例 1:查看资源发现的完整详情

在此示例中,您是一名授权IPAM管理员,想要创建资源发现并与其他 AWS 组织中的IPAM管理员共享,以便管理员可以管理和监控组织中资源的 IP 地址。

在以下情况下,此示例可能很有用:

您尝试创建资源发现,但出现错误,提示您已达到 1 的上限。您意识到自己可能已经创建了资源发现,并想在自己的账户中查看该发现。您在某个区域中有未被发现的资源。IPAM您要查看为资源--operating-regions定义的,并确保已将正确的区域添加为运营区域,以便可以发现那里的资源。

以下describe-ipam-resource-discoveries示例列出了您的 AWS 账户中资源发现的详细信息。您可以为每个 AWS 区域进行一次资源发现。

aws ec2 describe-ipam-resource-discoveries \ --region us-east-1

输出:

{ "IpamResourceDiscoveries": [ { "OwnerId": "149977607591", "IpamResourceDiscoveryId": "ipam-res-disco-0f8bdee9067137c0d", "IpamResourceDiscoveryArn": "arn:aws:ec2::149977607591:ipam-resource-discovery/ipam-res-disco-0f8bdee9067137c0d", "IpamResourceDiscoveryRegion": "us-east-1", "OperatingRegions": [ { "RegionName": "us-east-1" } ], "IsDefault": false, "State": "create-complete", "Tags": [] } ] }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的IPAM与组织外部账户集成

示例 2:仅查看资源发现 IDs

以下describe-ipam-resource-discoveries示例列出了您 AWS 账户中资源发现的 ID。您可以为每个 AWS 区域进行一次资源发现。

aws ec2 describe-ipam-resource-discoveries \ --query "IpamResourceDiscoveries[*].IpamResourceDiscoveryId" \ --output text

输出:

ipam-res-disco-0481e39b242860333

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的IPAM与组织外部账户集成

以下代码示例演示如何使用 describe-ipam-resource-discovery-associations

AWS CLI

查看与您的所有资源发现关联 IPAM

在此示例中,您是一名IPAM委托管理员,他已将资源发现与您的关联IPAM以将其他账户与您的账户集成IPAM。您已经注意到,您IPAM没有按预期在资源发现的操作区域中发现资源。您需要检查资源发现的状态和状态,以确保创建资源的帐户仍处于活动状态,并且资源发现仍在共享中。

--region必须是您的家乡区域IPAM。

以下describe-ipam-resource-discovery-associations示例列出了您 AWS 账户中的资源发现关联。

aws ec2 describe-ipam-resource-discovery-associations \ --region us-east-1

输出:

{ "IpamResourceDiscoveryAssociations": [ { "OwnerId": "320805250157", "IpamResourceDiscoveryAssociationId": "ipam-res-disco-assoc-05e6b45eca5bf5cf7", "IpamResourceDiscoveryAssociationArn": "arn:aws:ec2::320805250157:ipam-resource-discovery-association/ipam-res-disco-assoc-05e6b45eca5bf5cf7", "IpamResourceDiscoveryId": "ipam-res-disco-0f4ef577a9f37a162", "IpamId": "ipam-005f921c17ebd5107", "IpamArn": "arn:aws:ec2::320805250157:ipam/ipam-005f921c17ebd5107", "IpamRegion": "us-east-1", "IsDefault": true, "ResourceDiscoveryStatus": "active", "State": "associate-complete", "Tags": [] }, { "OwnerId": "149977607591", "IpamResourceDiscoveryAssociationId": "ipam-res-disco-assoc-0dfd21ae189ab5f62", "IpamResourceDiscoveryAssociationArn": "arn:aws:ec2::149977607591:ipam-resource-discovery-association/ipam-res-disco-assoc-0dfd21ae189ab5f62", "IpamResourceDiscoveryId": "ipam-res-disco-0365d2977fc1672fe", "IpamId": "ipam-005f921c17ebd5107", "IpamArn": "arn:aws:ec2::149977607591:ipam/ipam-005f921c17ebd5107", "IpamRegion": "us-east-1", "IsDefault": false, "ResourceDiscoveryStatus": "active", "State": "create-complete", "Tags": [] } ] }

在此示例中,运行此命令后,您会注意到发现了一个非默认资源("IsDefault": false ``) that is ``"ResourceDiscoveryStatus": "not-found""State": "create-complete"。资源发现所有者的账户已关闭。在另一种情况下,如果您注意到即"ResourceDiscoveryStatus": "not-found""State": "associate-complete",则表示发生了以下情况之一:

资源发现已被资源发现所有者删除。资源发现所有者取消了资源发现的共享。

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的IPAM与组织外部账户集成

以下代码示例演示如何使用 describe-ipam-scopes

AWS CLI

查看IPAM作用域的详细信息

以下describe-ipam-scopes示例显示了作用域的详细信息。

aws ec2 describe-ipam-scopes \ --filters Name=owner-id,Values=123456789012 Name=ipam-id,Values=ipam-08440e7a3acde3908

输出:

{ "IpamScopes": [ { "OwnerId": "123456789012", "IpamScopeId": "ipam-scope-02fc38cd4c48e7d38", "IpamScopeArn": "arn:aws:ec2::123456789012:ipam-scope/ipam-scope-02fc38cd4c48e7d38", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-08440e7a3acde3908", "IpamRegion": "us-east-1", "IpamScopeType": "private", "IsDefault": true, "PoolCount": 2, "State": "create-complete", "Tags": [] }, { "OwnerId": "123456789012", "IpamScopeId": "ipam-scope-0b9eed026396dbc16", "IpamScopeArn": "arn:aws:ec2::123456789012:ipam-scope/ipam-scope-0b9eed026396dbc16", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-08440e7a3acde3908", "IpamRegion": "us-east-1", "IpamScopeType": "public", "IsDefault": true, "PoolCount": 0, "State": "create-complete", "Tags": [] }, { "OwnerId": "123456789012", "IpamScopeId": "ipam-scope-0f1aff29486355c22", "IpamScopeArn": "arn:aws:ec2::123456789012:ipam-scope/ipam-scope-0f1aff29486355c22", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-08440e7a3acde3908", "IpamRegion": "us-east-1", "IpamScopeType": "private", "IsDefault": false, "Description": "Example description", "PoolCount": 0, "State": "create-complete", "Tags": [ { "Key": "Name", "Value": "Example name value" } ] } ] }

以下代码示例演示如何使用 describe-ipams

AWS CLI

要查看的详细信息 IPAM

以下describe-ipams示例显示了的详细信息IPAM。

aws ec2 describe-ipams \ --filters Name=owner-id,Values=123456789012

输出:

{ "Ipams": [ { "OwnerId": "123456789012", "IpamId": "ipam-08440e7a3acde3908", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-08440e7a3acde3908", "IpamRegion": "us-east-1", "PublicDefaultScopeId": "ipam-scope-0b9eed026396dbc16", "PrivateDefaultScopeId": "ipam-scope-02fc38cd4c48e7d38", "ScopeCount": 3, "OperatingRegions": [ { "RegionName": "us-east-1" }, { "RegionName": "us-east-2" }, { "RegionName": "us-west-1" } ], "State": "create-complete", "Tags": [ { "Key": "Name", "Value": "ExampleIPAM" } ] } ] }

以下代码示例演示如何使用 describe-ipv6-pools

AWS CLI

描述您的IPv6地址池

以下describe-ipv6-pools示例显示了所有IPv6地址池的详细信息。

aws ec2 describe-ipv6-pools

输出:

{ "Ipv6Pools": [ { "PoolId": "ipv6pool-ec2-012345abc12345abc", "PoolCidrBlocks": [ { "Cidr": "2001:db8:123::/48" } ], "Tags": [ { "Key": "pool-1", "Value": "public" } ] } ] }
  • 有关API详细信息,请参阅《AWS CLI 命令参考》中的 DescribeIpv6Poo ls。

以下代码示例演示如何使用 describe-key-pairs

AWS CLI

显示密钥对

以下 describe-key-pairs 示例显示有关指定密钥对的信息。

aws ec2 describe-key-pairs \ --key-names my-key-pair

输出:

{ "KeyPairs": [ { "KeyPairId": "key-0b94643da6EXAMPLE", "KeyFingerprint": "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f", "KeyName": "my-key-pair", "KeyType": "rsa", "Tags": [], "CreateTime": "2022-05-27T21:51:16.000Z" } ] }

有关更多信息,请参阅 Amazon EC2 用户指南中的描述公钥

以下代码示例演示如何使用 describe-launch-template-versions

AWS CLI

描述启动模板版本

此示例描述了指定启动模板的版本。

命令:

aws ec2 describe-launch-template-versions --launch-template-id lt-068f72b72934aff71

输出:

{ "LaunchTemplateVersions": [ { "LaunchTemplateId": "lt-068f72b72934aff71", "LaunchTemplateName": "Webservers", "VersionNumber": 3, "CreatedBy": "arn:aws:iam::123456789102:root", "LaunchTemplateData": { "KeyName": "kp-us-east", "ImageId": "ami-6057e21a", "InstanceType": "t2.small", "NetworkInterfaces": [ { "SubnetId": "subnet-7b16de0c", "DeviceIndex": 0, "Groups": [ "sg-7c227019" ] } ] }, "DefaultVersion": false, "CreateTime": "2017-11-20T13:19:54.000Z" }, { "LaunchTemplateId": "lt-068f72b72934aff71", "LaunchTemplateName": "Webservers", "VersionNumber": 2, "CreatedBy": "arn:aws:iam::123456789102:root", "LaunchTemplateData": { "KeyName": "kp-us-east", "ImageId": "ami-6057e21a", "InstanceType": "t2.medium", "NetworkInterfaces": [ { "SubnetId": "subnet-1a2b3c4d", "DeviceIndex": 0, "Groups": [ "sg-7c227019" ] } ] }, "DefaultVersion": false, "CreateTime": "2017-11-20T13:12:32.000Z" }, { "LaunchTemplateId": "lt-068f72b72934aff71", "LaunchTemplateName": "Webservers", "VersionNumber": 1, "CreatedBy": "arn:aws:iam::123456789102:root", "LaunchTemplateData": { "UserData": "", "KeyName": "kp-us-east", "ImageId": "ami-aabbcc11", "InstanceType": "t2.medium", "NetworkInterfaces": [ { "SubnetId": "subnet-7b16de0c", "DeviceIndex": 0, "DeleteOnTermination": false, "Groups": [ "sg-7c227019" ], "AssociatePublicIpAddress": true } ] }, "DefaultVersion": true, "CreateTime": "2017-11-20T12:52:33.000Z" } ] }

以下代码示例演示如何使用 describe-launch-templates

AWS CLI

描述启动模板

此示例描述了您的启动模板。

命令:

aws ec2 describe-launch-templates

输出:

{ "LaunchTemplates": [ { "LatestVersionNumber": 2, "LaunchTemplateId": "lt-0e06d290751193123", "LaunchTemplateName": "TemplateForWebServer", "DefaultVersionNumber": 2, "CreatedBy": "arn:aws:iam::123456789012:root", "CreateTime": "2017-11-27T09:30:23.000Z" }, { "LatestVersionNumber": 6, "LaunchTemplateId": "lt-0c45b5e061ec98456", "LaunchTemplateName": "DBServersTemplate", "DefaultVersionNumber": 1, "CreatedBy": "arn:aws:iam::123456789012:root", "CreateTime": "2017-11-20T09:25:22.000Z" }, { "LatestVersionNumber": 1, "LaunchTemplateId": "lt-0d47d774e8e52dabc", "LaunchTemplateName": "MyLaunchTemplate2", "DefaultVersionNumber": 1, "CreatedBy": "arn:aws:iam::123456789012:root", "CreateTime": "2017-11-02T12:06:21.000Z" }, { "LatestVersionNumber": 3, "LaunchTemplateId": "lt-01e5f948eb4f589d6", "LaunchTemplateName": "testingtemplate2", "DefaultVersionNumber": 1, "CreatedBy": "arn:aws:sts::123456789012:assumed-role/AdminRole/i-03ee35176e2e5aabc", "CreateTime": "2017-12-01T08:19:48.000Z" }, ] }

以下代码示例演示如何使用 describe-local-gateway-route-table-virtual-interface-group-associations

AWS CLI

描述虚拟接口组和本地网关路由表之间的关联

以下describe-local-gateway-route-table-virtual-interface-group-associations示例描述了您的 AWS 账户中虚拟接口组和本地网关路由表之间的关联。

aws ec2 describe-local-gateway-route-table-virtual-interface-group-associations

输出:

{ "LocalGatewayRouteTableVirtualInterfaceGroupAssociations": [ { "LocalGatewayRouteTableVirtualInterfaceGroupAssociationId": "lgw-vif-grp-assoc-07145b276bEXAMPLE", "LocalGatewayVirtualInterfaceGroupId": "lgw-vif-grp-07145b276bEXAMPLE", "LocalGatewayId": "lgw-0ab1c23d4eEXAMPLE", "LocalGatewayRouteTableId": "lgw-rtb-059615ef7dEXAMPLE", "LocalGatewayRouteTableArn": "arn:aws:ec2:us-west-2:123456789012:local-gateway-route-table/lgw-rtb-059615ef7dEXAMPLE", "OwnerId": "123456789012", "State": "associated", "Tags": [] } ] }

有关更多信息,请参阅 AWS Outposts 用户指南中的使用本地网关

以下代码示例演示如何使用 describe-local-gateway-route-table-vpc-associations

AWS CLI

描述本地网关路由表VPCs和本地网关路由表之间的关联

以下describe-local-gateway-route-table-vpc-associations示例显示了与本地网关路由表VPCs之间的指定关联的相关信息。

aws ec2 describe-local-gateway-route-table-vpc-associations \ --local-gateway-route-table-vpc-association-ids lgw-vpc-assoc-0e0f27af15EXAMPLE

输出:

{ "LocalGatewayRouteTableVpcAssociation": { "LocalGatewayRouteTableVpcAssociationId": "lgw-vpc-assoc-0e0f27af1EXAMPLE", "LocalGatewayRouteTableId": "lgw-rtb-059615ef7dEXAMPLE", "LocalGatewayId": "lgw-09b493aa7cEXAMPLE", "VpcId": "vpc-0efe9bde08EXAMPLE", "State": "associated" } }

有关更多信息,请参阅《 Outposts 用户指南》中的本地网关路由表

以下代码示例演示如何使用 describe-local-gateway-route-tables

AWS CLI

描述您的本地网关路由表

以下describe-local-gateway-route-tables示例显示有关本地网关路由表的详细信息。

aws ec2 describe-local-gateway-route-tables

输出:

{ "LocalGatewayRouteTables": [ { "LocalGatewayRouteTableId": "lgw-rtb-059615ef7deEXAMPLE", "LocalGatewayId": "lgw-09b493aa7cEXAMPLE", "OutpostArn": "arn:aws:outposts:us-west-2:111122223333:outpost/op-0dc11b66edEXAMPLE", "State": "available" } ] }

以下代码示例演示如何使用 describe-local-gateway-virtual-interface-groups

AWS CLI

描述本地网关虚拟接口组

以下describe-local-gateway-virtual-interface-groups示例描述了您 AWS 账户中的本地网关虚拟接口组。

aws ec2 describe-local-gateway-virtual-interface-groups

输出:

{ "LocalGatewayVirtualInterfaceGroups": [ { "LocalGatewayVirtualInterfaceGroupId": "lgw-vif-grp-07145b276bEXAMPLE", "LocalGatewayVirtualInterfaceIds": [ "lgw-vif-01a23bc4d5EXAMPLE", "lgw-vif-543ab21012EXAMPLE" ], "LocalGatewayId": "lgw-0ab1c23d4eEXAMPLE", "OwnerId": "123456789012", "Tags": [] } ] }

有关更多信息,请参阅 AWS Outposts 用户指南中的使用本地网关

以下代码示例演示如何使用 describe-local-gateway-virtual-interfaces

AWS CLI

描述本地网关虚拟接口

以下describe-local-gateway-virtual-interfaces示例描述了您 AWS 账户中的本地网关虚拟接口。

aws ec2 describe-local-gateway-virtual-interfaces

输出:

{ "LocalGatewayVirtualInterfaces": [ { "LocalGatewayVirtualInterfaceId": "lgw-vif-01a23bc4d5EXAMPLE", "LocalGatewayId": "lgw-0ab1c23d4eEXAMPLE", "Vlan": 2410, "LocalAddress": "0.0.0.0/0", "PeerAddress": "0.0.0.0/0", "LocalBgpAsn": 65010, "PeerBgpAsn": 65000, "OwnerId": "123456789012", "Tags": [] }, { "LocalGatewayVirtualInterfaceId": "lgw-vif-543ab21012EXAMPLE", "LocalGatewayId": "lgw-0ab1c23d4eEXAMPLE", "Vlan": 2410, "LocalAddress": "0.0.0.0/0", "PeerAddress": "0.0.0.0/0", "LocalBgpAsn": 65010, "PeerBgpAsn": 65000, "OwnerId": "123456789012", "Tags": [] } ] }

有关更多信息,请参阅 AWS Outposts 用户指南中的使用本地网关

以下代码示例演示如何使用 describe-local-gateways

AWS CLI

描述您的本地网关

以下describe-local-gateways示例显示了可供您使用的本地网关的详细信息。

aws ec2 describe-local-gateways

输出:

{ "LocalGateways": [ { "LocalGatewayId": "lgw-09b493aa7cEXAMPLE", "OutpostArn": "arn:aws:outposts:us-west-2:123456789012:outpost/op-0dc11b66ed59f995a", "OwnerId": "123456789012", "State": "available" } ] }

以下代码示例演示如何使用 describe-locked-snapshots

AWS CLI

描述快照的锁定状态

以下describe-locked-snapshots示例描述了指定快照的锁定状态。

aws ec2 describe-locked-snapshots \ --snapshot-ids snap-0b5e733b4a8df6e0d

输出:

{ "Snapshots": [ { "OwnerId": "123456789012", "SnapshotId": "snap-0b5e733b4a8df6e0d", "LockState": "governance", "LockDuration": 365, "LockCreatedOn": "2024-05-05T00:56:06.208000+00:00", "LockDurationStartTime": "2024-05-05T00:56:06.208000+00:00", "LockExpiresOn": "2025-05-05T00:56:06.208000+00:00" } ] }

有关更多信息,请参阅 Amazon EBS 用户指南中的快照锁

以下代码示例演示如何使用 describe-managed-prefix-lists

AWS CLI

描述托管前缀列表

以下describe-managed-prefix-lists示例描述了 AWS 账户拥有的前缀列表123456789012

aws ec2 describe-managed-prefix-lists \ --filters Name=owner-id,Values=123456789012

输出:

{ "PrefixLists": [ { "PrefixListId": "pl-11223344556677aab", "AddressFamily": "IPv6", "State": "create-complete", "PrefixListArn": "arn:aws:ec2:us-west-2:123456789012:prefix-list/pl-11223344556677aab", "PrefixListName": "vpc-ipv6-cidrs", "MaxEntries": 25, "Version": 1, "Tags": [], "OwnerId": "123456789012" }, { "PrefixListId": "pl-0123456abcabcabc1", "AddressFamily": "IPv4", "State": "active", "PrefixListArn": "arn:aws:ec2:us-west-2:123456789012:prefix-list/pl-0123456abcabcabc1", "PrefixListName": "vpc-cidrs", "MaxEntries": 10, "Version": 1, "Tags": [], "OwnerId": "123456789012" } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的托管前缀列表

以下代码示例演示如何使用 describe-moving-addresses

AWS CLI

描述您的搬家地址

此示例描述了您的所有移动弹性 IP 地址。

命令:

aws ec2 describe-moving-addresses

输出:

{ "MovingAddressStatuses": [ { "PublicIp": "198.51.100.0", "MoveStatus": "MovingToVpc" } ] }

此示例描述了所有要移至 EC2-VPC 平台的地址。

命令:

aws ec2 describe-moving-addresses --filters Name=moving-status,Values=MovingToVpc

以下代码示例演示如何使用 describe-nat-gateways

AWS CLI

示例 1:描述公共NAT网关

以下describe-nat-gateways示例描述了指定的公共NAT网关。

aws ec2 describe-nat-gateways \ --nat-gateway-id nat-01234567890abcdef

输出:

{ "NatGateways": [ { "CreateTime": "2023-08-25T01:56:51.000Z", "NatGatewayAddresses": [ { "AllocationId": "eipalloc-0790180cd2EXAMPLE", "NetworkInterfaceId": "eni-09cc4b2558794f7f9", "PrivateIp": "10.0.0.211", "PublicIp": "54.85.121.213", "AssociationId": "eipassoc-04d295cc9b8815b24", "IsPrimary": true, "Status": "succeeded" }, { "AllocationId": "eipalloc-0be6ecac95EXAMPLE", "NetworkInterfaceId": "eni-09cc4b2558794f7f9", "PrivateIp": "10.0.0.74", "PublicIp": "3.211.231.218", "AssociationId": "eipassoc-0f96bdca17EXAMPLE", "IsPrimary": false, "Status": "succeeded" } ], "NatGatewayId": "nat-01234567890abcdef", "State": "available", "SubnetId": "subnet-655eab5f08EXAMPLE", "VpcId": "vpc-098eb5ef58EXAMPLE", "Tags": [ { "Key": "Name", "Value": "public-nat" } ], "ConnectivityType": "public" } ] }

示例 2:描述私有NAT网关

以下describe-nat-gateways示例描述了指定的私有NAT网关。

aws ec2 describe-nat-gateways \ --nat-gateway-id nat-1234567890abcdef0

输出:

{ "NatGateways": [ { "CreateTime": "2023-08-25T00:50:05.000Z", "NatGatewayAddresses": [ { "NetworkInterfaceId": "eni-0065a61b324d1897a", "PrivateIp": "10.0.20.240", "IsPrimary": true, "Status": "succeeded" }, { "NetworkInterfaceId": "eni-0065a61b324d1897a", "PrivateIp": "10.0.20.33", "IsPrimary": false, "Status": "succeeded" }, { "NetworkInterfaceId": "eni-0065a61b324d1897a", "PrivateIp": "10.0.20.197", "IsPrimary": false, "Status": "succeeded" } ], "NatGatewayId": "nat-1234567890abcdef0", "State": "available", "SubnetId": "subnet-08fc749671EXAMPLE", "VpcId": "vpc-098eb5ef58EXAMPLE", "Tags": [ { "Key": "Name", "Value": "private-nat" } ], "ConnectivityType": "private" } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的NAT网关

以下代码示例演示如何使用 describe-network-acls

AWS CLI

描述您的网络 ACLs

以下describe-network-acls示例检索有关您的网络ACLs的详细信息。

aws ec2 describe-network-acls

输出:

{ "NetworkAcls": [ { "Associations": [ { "NetworkAclAssociationId": "aclassoc-0c1679dc41EXAMPLE", "NetworkAclId": "acl-0ea1f54ca7EXAMPLE", "SubnetId": "subnet-0931fc2fa5EXAMPLE" } ], "Entries": [ { "CidrBlock": "0.0.0.0/0", "Egress": true, "Protocol": "-1", "RuleAction": "allow", "RuleNumber": 100 }, { "CidrBlock": "0.0.0.0/0", "Egress": true, "Protocol": "-1", "RuleAction": "deny", "RuleNumber": 32767 }, { "CidrBlock": "0.0.0.0/0", "Egress": false, "Protocol": "-1", "RuleAction": "allow", "RuleNumber": 100 }, { "CidrBlock": "0.0.0.0/0", "Egress": false, "Protocol": "-1", "RuleAction": "deny", "RuleNumber": 32767 } ], "IsDefault": true, "NetworkAclId": "acl-0ea1f54ca7EXAMPLE", "Tags": [], "VpcId": "vpc-06e4ab6c6cEXAMPLE", "OwnerId": "111122223333" }, { "Associations": [], "Entries": [ { "CidrBlock": "0.0.0.0/0", "Egress": true, "Protocol": "-1", "RuleAction": "allow", "RuleNumber": 100 }, { "Egress": true, "Ipv6CidrBlock": "::/0", "Protocol": "-1", "RuleAction": "allow", "RuleNumber": 101 }, { "CidrBlock": "0.0.0.0/0", "Egress": true, "Protocol": "-1", "RuleAction": "deny", "RuleNumber": 32767 }, { "Egress": true, "Ipv6CidrBlock": "::/0", "Protocol": "-1", "RuleAction": "deny", "RuleNumber": 32768 }, { "CidrBlock": "0.0.0.0/0", "Egress": false, "Protocol": "-1", "RuleAction": "allow", "RuleNumber": 100 }, { "Egress": false, "Ipv6CidrBlock": "::/0", "Protocol": "-1", "RuleAction": "allow", "RuleNumber": 101 }, { "CidrBlock": "0.0.0.0/0", "Egress": false, "Protocol": "-1", "RuleAction": "deny", "RuleNumber": 32767 }, { "Egress": false, "Ipv6CidrBlock": "::/0", "Protocol": "-1", "RuleAction": "deny", "RuleNumber": 32768 } ], "IsDefault": true, "NetworkAclId": "acl-0e2a78e4e2EXAMPLE", "Tags": [], "VpcId": "vpc-03914afb3eEXAMPLE", "OwnerId": "111122223333" } ] }

有关更多信息,请参阅《AWS VPC用户指南》ACLs中的 “网络”。

以下代码示例演示如何使用 describe-network-insights-access-scope-analyses

AWS CLI

描述 Network Insights 访问范围分析

以下describe-network-insights-access-scope-analyses示例描述了您 AWS 账户中的访问范围分析。

aws ec2 describe-network-insights-access-scope-analyses \ --region us-east-1

输出:

{ "NetworkInsightsAccessScopeAnalyses": [ { "NetworkInsightsAccessScopeAnalysisId": "nisa-123456789111", "NetworkInsightsAccessScopeAnalysisArn": "arn:aws:ec2:us-east-1:123456789012:network-insights-access-scope-analysis/nisa-123456789111", "NetworkInsightsAccessScopeId": "nis-123456789222", "Status": "succeeded", "StartDate": "2022-01-25T19:45:36.842000+00:00", "FindingsFound": "true", "Tags": [] } ] }

有关更多信息,请参阅《网络访问分析器指南》 AWS CLI中的 “网络访问分析器入”。

以下代码示例演示如何使用 describe-network-insights-access-scopes

AWS CLI

描述网络见解访问范围

以下describe-network-insights-access-scopes示例描述了您 AWS 账户中的访问范围分析。

aws ec2 describe-network-insights-access-scopes \ --region us-east-1

输出:

{ "NetworkInsightsAccessScopes": [ { "NetworkInsightsAccessScopeId": "nis-123456789111", "NetworkInsightsAccessScopeArn": "arn:aws:ec2:us-east-1:123456789012:network-insights-access-scope/nis-123456789111", "CreatedDate": "2021-11-29T21:12:41.416000+00:00", "UpdatedDate": "2021-11-29T21:12:41.416000+00:00", "Tags": [] } ] }

有关更多信息,请参阅《网络访问分析器指南》 AWS CLI中的 “网络访问分析器入”。

以下代码示例演示如何使用 describe-network-insights-analyses

AWS CLI

查看路径分析的结果

以下describe-network-insights-analyses示例描述了指定的分析。在此示例中,源是互联网网关,目的地是EC2实例,协议是TCP。分析成功(Statussucceeded),路径无法到达(NetworkPathFoundfalse)。解释代码ENI_SG_RULES_MISMATCH表示实例的安全组不包含允许目标端口上流量的规则。

aws ec2 describe-network-insights-analyses \ --network-insights-analysis-ids nia-02207aa13eb480c7a

输出:

{ "NetworkInsightsAnalyses": [ { "NetworkInsightsAnalysisId": "nia-02207aa13eb480c7a", "NetworkInsightsAnalysisArn": "arn:aws:ec2:us-east-1:123456789012:network-insights-analysis/nia-02207aa13eb480c7a", "NetworkInsightsPathId": "nip-0b26f224f1d131fa8", "StartDate": "2021-01-20T22:58:37.495Z", "Status": "succeeded", "NetworkPathFound": false, "Explanations": [ { "Direction": "ingress", "ExplanationCode": "ENI_SG_RULES_MISMATCH", "NetworkInterface": { "Id": "eni-0a25edef15a6cc08c", "Arn": "arn:aws:ec2:us-east-1:123456789012:network-interface/eni-0a25edef15a6cc08c" }, "SecurityGroups": [ { "Id": "sg-02f0d35a850ba727f", "Arn": "arn:aws:ec2:us-east-1:123456789012:security-group/sg-02f0d35a850ba727f" } ], "Subnet": { "Id": "subnet-004ff41eccb4d1194", "Arn": "arn:aws:ec2:us-east-1:123456789012:subnet/subnet-004ff41eccb4d1194" }, "Vpc": { "Id": "vpc-f1663d98ad28331c7", "Arn": "arn:aws:ec2:us-east-1:123456789012:vpc/vpc-f1663d98ad28331c7" } } ], "Tags": [] } ] }

有关更多信息,请参阅 Reach ability Analy AWS CLI zer 指南中的入门使用指南。

以下代码示例演示如何使用 describe-network-insights-paths

AWS CLI

描述路径

以下describe-network-insights-paths示例描述了指定的路径。

aws ec2 describe-network-insights-paths \ --network-insights-path-ids nip-0b26f224f1d131fa8

输出:

{ "NetworkInsightsPaths": [ { "NetworkInsightsPathId": "nip-0b26f224f1d131fa8", "NetworkInsightsPathArn": "arn:aws:ec2:us-east-1:123456789012:network-insights-path/nip-0b26f224f1d131fa8", "CreatedDate": "2021-01-20T22:43:46.933Z", "Source": "igw-0797cccdc9d73b0e5", "Destination": "i-0495d385ad28331c7", "Protocol": "tcp" } ] }

有关更多信息,请参阅 Reach ability Analy AWS CLI zer 指南中的入门使用指南。

以下代码示例演示如何使用 describe-network-interface-attribute

AWS CLI

描述网络接口的连接属性

此示例命令描述了指定网络接口的attachment属性。

命令:

aws ec2 describe-network-interface-attribute --network-interface-id eni-686ea200 --attribute attachment

输出:

{ "NetworkInterfaceId": "eni-686ea200", "Attachment": { "Status": "attached", "DeviceIndex": 0, "AttachTime": "2015-05-21T20:02:20.000Z", "InstanceId": "i-1234567890abcdef0", "DeleteOnTermination": true, "AttachmentId": "eni-attach-43348162", "InstanceOwnerId": "123456789012" } }

描述网络接口的描述属性

此示例命令描述了指定网络接口的description属性。

命令:

aws ec2 describe-network-interface-attribute --network-interface-id eni-686ea200 --attribute description

输出:

{ "NetworkInterfaceId": "eni-686ea200", "Description": { "Value": "My description" } }

描述网络接口的 groupSet 属性

此示例命令描述了指定网络接口的groupSet属性。

命令:

aws ec2 describe-network-interface-attribute --network-interface-id eni-686ea200 --attribute groupSet

输出:

{ "NetworkInterfaceId": "eni-686ea200", "Groups": [ { "GroupName": "my-security-group", "GroupId": "sg-903004f8" } ] }

描述网络接口的 sourceDestCheck 属性

此示例命令描述了指定网络接口的sourceDestCheck属性。

命令:

aws ec2 describe-network-interface-attribute --network-interface-id eni-686ea200 --attribute sourceDestCheck

输出:

{ "NetworkInterfaceId": "eni-686ea200", "SourceDestCheck": { "Value": true } }

以下代码示例演示如何使用 describe-network-interface-permissions

AWS CLI

描述您的网络接口权限

此示例描述了您的所有网络接口权限。

命令:

aws ec2 describe-network-interface-permissions

输出:

{ "NetworkInterfacePermissions": [ { "PermissionState": { "State": "GRANTED" }, "NetworkInterfacePermissionId": "eni-perm-06fd19020ede149ea", "NetworkInterfaceId": "eni-b909511a", "Permission": "INSTANCE-ATTACH", "AwsAccountId": "123456789012" } ] }

以下代码示例演示如何使用 describe-network-interfaces

AWS CLI

描述您的网络接口

此示例描述了您的所有网络接口。

命令:

aws ec2 describe-network-interfaces

输出:

{ "NetworkInterfaces": [ { "Status": "in-use", "MacAddress": "02:2f:8f:b0:cf:75", "SourceDestCheck": true, "VpcId": "vpc-a01106c2", "Description": "my network interface", "Association": { "PublicIp": "203.0.113.12", "AssociationId": "eipassoc-0fbb766a", "PublicDnsName": "ec2-203-0-113-12.compute-1.amazonaws.com", "IpOwnerId": "123456789012" }, "NetworkInterfaceId": "eni-e5aa89a3", "PrivateIpAddresses": [ { "PrivateDnsName": "ip-10-0-1-17.ec2.internal", "Association": { "PublicIp": "203.0.113.12", "AssociationId": "eipassoc-0fbb766a", "PublicDnsName": "ec2-203-0-113-12.compute-1.amazonaws.com", "IpOwnerId": "123456789012" }, "Primary": true, "PrivateIpAddress": "10.0.1.17" } ], "RequesterManaged": false, "Ipv6Addresses": [], "PrivateDnsName": "ip-10-0-1-17.ec2.internal", "AvailabilityZone": "us-east-1d", "Attachment": { "Status": "attached", "DeviceIndex": 1, "AttachTime": "2013-11-30T23:36:42.000Z", "InstanceId": "i-1234567890abcdef0", "DeleteOnTermination": false, "AttachmentId": "eni-attach-66c4350a", "InstanceOwnerId": "123456789012" }, "Groups": [ { "GroupName": "default", "GroupId": "sg-8637d3e3" } ], "SubnetId": "subnet-b61f49f0", "OwnerId": "123456789012", "TagSet": [], "PrivateIpAddress": "10.0.1.17" }, { "Status": "in-use", "MacAddress": "02:58:f5:ef:4b:06", "SourceDestCheck": true, "VpcId": "vpc-a01106c2", "Description": "Primary network interface", "Association": { "PublicIp": "198.51.100.0", "IpOwnerId": "amazon" }, "NetworkInterfaceId": "eni-f9ba99bf", "PrivateIpAddresses": [ { "Association": { "PublicIp": "198.51.100.0", "IpOwnerId": "amazon" }, "Primary": true, "PrivateIpAddress": "10.0.1.149" } ], "RequesterManaged": false, "Ipv6Addresses": [], "AvailabilityZone": "us-east-1d", "Attachment": { "Status": "attached", "DeviceIndex": 0, "AttachTime": "2013-11-30T23:35:33.000Z", "InstanceId": "i-0598c7d356eba48d7", "DeleteOnTermination": true, "AttachmentId": "eni-attach-1b9db777", "InstanceOwnerId": "123456789012" }, "Groups": [ { "GroupName": "default", "GroupId": "sg-8637d3e3" } ], "SubnetId": "subnet-b61f49f0", "OwnerId": "123456789012", "TagSet": [], "PrivateIpAddress": "10.0.1.149" } ] }

此示例描述了带有带有密钥Purpose和值的标签的网络接口Prod

命令:

aws ec2 describe-network-interfaces --filters Name=tag:Purpose,Values=Prod

输出:

{ "NetworkInterfaces": [ { "Status": "available", "MacAddress": "12:2c:bd:f9:bf:17", "SourceDestCheck": true, "VpcId": "vpc-8941ebec", "Description": "ProdENI", "NetworkInterfaceId": "eni-b9a5ac93", "PrivateIpAddresses": [ { "PrivateDnsName": "ip-10-0-1-55.ec2.internal", "Primary": true, "PrivateIpAddress": "10.0.1.55" }, { "PrivateDnsName": "ip-10-0-1-117.ec2.internal", "Primary": false, "PrivateIpAddress": "10.0.1.117" } ], "RequesterManaged": false, "PrivateDnsName": "ip-10-0-1-55.ec2.internal", "AvailabilityZone": "us-east-1d", "Ipv6Addresses": [], "Groups": [ { "GroupName": "MySG", "GroupId": "sg-905002f5" } ], "SubnetId": "subnet-31d6c219", "OwnerId": "123456789012", "TagSet": [ { "Value": "Prod", "Key": "Purpose" } ], "PrivateIpAddress": "10.0.1.55" } ] }

以下代码示例演示如何使用 describe-placement-groups

AWS CLI

描述您的置放群组

此示例命令描述了您的所有置放群组。

命令:

aws ec2 describe-placement-groups

输出:

{ "PlacementGroups": [ { "GroupName": "my-cluster", "State": "available", "Strategy": "cluster" }, ... ] }

以下代码示例演示如何使用 describe-prefix-lists

AWS CLI

描述前缀列表

此示例列出了该区域的所有可用前缀列表。

命令:

aws ec2 describe-prefix-lists

输出:

{ "PrefixLists": [ { "PrefixListName": "com.amazonaws.us-east-1.s3", "Cidrs": [ "54.231.0.0/17" ], "PrefixListId": "pl-63a5400a" } ] }

以下代码示例演示如何使用 describe-principal-id-format

AWS CLI

描述启用长 ID 格式的IAM用户和角色的 ID 格式

以下describe-principal-id-format示例描述了 root 用户、所有IAM角色和所有启用长 ID 格式的IAM用户的 ID 格式。

aws ec2 describe-principal-id-format \ --resource instance

输出:

{ "Principals": [ { "Arn": "arn:aws:iam::123456789012:root", "Statuses": [ { "Deadline": "2016-12-15T00:00:00.000Z", "Resource": "reservation", "UseLongIds": true }, { "Deadline": "2016-12-15T00:00:00.000Z", "Resource": "instance", "UseLongIds": true }, { "Deadline": "2016-12-15T00:00:00.000Z", "Resource": "volume", "UseLongIds": true }, ] }, ... ] }

以下代码示例演示如何使用 describe-public-ipv4-pools

AWS CLI

描述您的公共IPv4地址池

以下describe-public-ipv4-pools示例显示了有关您使用 Bring Your Own IP 地址(BYOIP)配置公共IPv4地址范围时创建的地址池的详细信息。

aws ec2 describe-public-ipv4-pools

输出:

{ "PublicIpv4Pools": [ { "PoolId": "ipv4pool-ec2-1234567890abcdef0", "PoolAddressRanges": [ { "FirstAddress": "203.0.113.0", "LastAddress": "203.0.113.255", "AddressCount": 256, "AvailableAddressCount": 256 } ], "TotalAddressCount": 256, "TotalAvailableAddressCount": 256 } ] }

以下代码示例演示如何使用 describe-regions

AWS CLI

示例 1:描述所有已启用的区域

以下 describe-regions 示例描述了为您的账户启用的所有区域。

aws ec2 describe-regions

输出:

{ "Regions": [ { "Endpoint": "ec2.eu-north-1.amazonaws.com", "RegionName": "eu-north-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ap-south-1.amazonaws.com", "RegionName": "ap-south-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.eu-west-3.amazonaws.com", "RegionName": "eu-west-3", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.eu-west-2.amazonaws.com", "RegionName": "eu-west-2", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.eu-west-1.amazonaws.com", "RegionName": "eu-west-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ap-northeast-3.amazonaws.com", "RegionName": "ap-northeast-3", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ap-northeast-2.amazonaws.com", "RegionName": "ap-northeast-2", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ap-northeast-1.amazonaws.com", "RegionName": "ap-northeast-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.sa-east-1.amazonaws.com", "RegionName": "sa-east-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ca-central-1.amazonaws.com", "RegionName": "ca-central-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ap-southeast-1.amazonaws.com", "RegionName": "ap-southeast-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ap-southeast-2.amazonaws.com", "RegionName": "ap-southeast-2", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.eu-central-1.amazonaws.com", "RegionName": "eu-central-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.us-east-1.amazonaws.com", "RegionName": "us-east-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.us-east-2.amazonaws.com", "RegionName": "us-east-2", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.us-west-1.amazonaws.com", "RegionName": "us-west-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.us-west-2.amazonaws.com", "RegionName": "us-west-2", "OptInStatus": "opt-in-not-required" } ] }

有关更多信息,请参阅 Amazon EC2 用户指南中的区域和区域

示例 2:描述具有端点的已启用区域,其名称包含特定字符串

以下 describe-regions 示例描述了在端点中具有字符串“us”的所有已启用区域。

aws ec2 describe-regions \ --filters "Name=endpoint,Values=*us*"

输出:

{ "Regions": [ { "Endpoint": "ec2.us-east-1.amazonaws.com", "RegionName": "us-east-1" }, { "Endpoint": "ec2.us-east-2.amazonaws.com", "RegionName": "us-east-2" }, { "Endpoint": "ec2.us-west-1.amazonaws.com", "RegionName": "us-west-1" }, { "Endpoint": "ec2.us-west-2.amazonaws.com", "RegionName": "us-west-2" } ] }

有关更多信息,请参阅 Amazon EC2 用户指南中的区域和区域

示例 3:描述所有区域

以下 describe-regions 示例描述了所有可用区域,包括已禁用的区域。

aws ec2 describe-regions \ --all-regions

输出:

{ "Regions": [ { "Endpoint": "ec2.eu-north-1.amazonaws.com", "RegionName": "eu-north-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ap-south-1.amazonaws.com", "RegionName": "ap-south-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.eu-west-3.amazonaws.com", "RegionName": "eu-west-3", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.eu-west-2.amazonaws.com", "RegionName": "eu-west-2", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.eu-west-1.amazonaws.com", "RegionName": "eu-west-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ap-northeast-3.amazonaws.com", "RegionName": "ap-northeast-3", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.me-south-1.amazonaws.com", "RegionName": "me-south-1", "OptInStatus": "not-opted-in" }, { "Endpoint": "ec2.ap-northeast-2.amazonaws.com", "RegionName": "ap-northeast-2", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ap-northeast-1.amazonaws.com", "RegionName": "ap-northeast-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.sa-east-1.amazonaws.com", "RegionName": "sa-east-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ca-central-1.amazonaws.com", "RegionName": "ca-central-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ap-east-1.amazonaws.com", "RegionName": "ap-east-1", "OptInStatus": "not-opted-in" }, { "Endpoint": "ec2.ap-southeast-1.amazonaws.com", "RegionName": "ap-southeast-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.ap-southeast-2.amazonaws.com", "RegionName": "ap-southeast-2", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.eu-central-1.amazonaws.com", "RegionName": "eu-central-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.us-east-1.amazonaws.com", "RegionName": "us-east-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.us-east-2.amazonaws.com", "RegionName": "us-east-2", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.us-west-1.amazonaws.com", "RegionName": "us-west-1", "OptInStatus": "opt-in-not-required" }, { "Endpoint": "ec2.us-west-2.amazonaws.com", "RegionName": "us-west-2", "OptInStatus": "opt-in-not-required" } ] }

有关更多信息,请参阅 Amazon EC2 用户指南中的区域和区域

示例 4:仅列出区域名称

以下 describe-regions 示例使用 --query 参数筛选输出,并仅以文本形式返回区域的名称。

aws ec2 describe-regions \ --all-regions \ --query "Regions[].{Name:RegionName}" \ --output text

输出:

eu-north-1 ap-south-1 eu-west-3 eu-west-2 eu-west-1 ap-northeast-3 ap-northeast-2 me-south-1 ap-northeast-1 sa-east-1 ca-central-1 ap-east-1 ap-southeast-1 ap-southeast-2 eu-central-1 us-east-1 us-east-2 us-west-1 us-west-2

有关更多信息,请参阅 Amazon EC2 用户指南中的区域和区域

以下代码示例演示如何使用 describe-replace-root-volume-tasks

AWS CLI

示例 1:查看有关特定根卷更换任务的信息

以下describe-replace-root-volume-tasks示例描述了根卷替换任务 replacevol-0111122223333abcd。

aws ec2 describe-replace-root-volume-tasks \ --replace-root-volume-task-ids replacevol-0111122223333abcd

输出:

{ "ReplaceRootVolumeTasks": [ { "ReplaceRootVolumeTaskId": "replacevol-0111122223333abcd", "Tags": [], "InstanceId": "i-0123456789abcdefa", "TaskState": "succeeded", "StartTime": "2022-03-14T15:16:28Z", "CompleteTime": "2022-03-14T15:16:52Z" } ] }

有关更多信息,请参阅 Amazon 弹性计算云用户指南中的替换根卷

示例 2:查看有关特定实例的所有根卷更换任务的信息

以下describe-replace-root-volume-tasks示例描述了所有根卷更换任务,例如 i-0123456789abcdefa。

aws ec2 describe-replace-root-volume-tasks \ --filters Name=instance-id,Values=i-0123456789abcdefa

输出:

{ "ReplaceRootVolumeTasks": [ { "ReplaceRootVolumeTaskId": "replacevol-0111122223333abcd", "Tags": [], "InstanceId": "i-0123456789abcdefa", "TaskState": "succeeded", "StartTime": "2022-03-14T15:06:38Z", "CompleteTime": "2022-03-14T15:07:03Z" }, { "ReplaceRootVolumeTaskId": "replacevol-0444455555555abcd", "Tags": [], "InstanceId": "i-0123456789abcdefa", "TaskState": "succeeded", "StartTime": "2022-03-14T15:16:28Z", "CompleteTime": "2022-03-14T15:16:52Z" } ] }

有关更多信息,请参阅 Amazon 弹性计算云用户指南中的替换根卷

以下代码示例演示如何使用 describe-reserved-instances-listings

AWS CLI

描述预留实例清单

以下describe-reserved-instances-listings示例检索有关指定预留实例列表的信息。

aws ec2 describe-reserved-instances-listings \ --reserved-instances-listing-id 5ec28771-05ff-4b9b-aa31-9e57dexample

此命令不生成任何输出。

以下代码示例演示如何使用 describe-reserved-instances-modifications

AWS CLI

描述预留实例的修改

此示例命令描述了为您的账户提交的所有预留实例修改请求。

命令:

aws ec2 describe-reserved-instances-modifications

输出:

{ "ReservedInstancesModifications": [ { "Status": "fulfilled", "ModificationResults": [ { "ReservedInstancesId": "93bbbca2-62f1-4d9d-b225-16bada29e6c7", "TargetConfiguration": { "AvailabilityZone": "us-east-1b", "InstanceType": "m1.large", "InstanceCount": 3 } }, { "ReservedInstancesId": "1ba8e2e3-aabb-46c3-bcf5-3fe2fda922e6", "TargetConfiguration": { "AvailabilityZone": "us-east-1d", "InstanceType": "m1.xlarge", "InstanceCount": 1 } } ], "EffectiveDate": "2015-08-12T17:00:00.000Z", "CreateDate": "2015-08-12T17:52:52.630Z", "UpdateDate": "2015-08-12T18:08:06.698Z", "ClientToken": "c9adb218-3222-4889-8216-0cf0e52dc37e: "ReservedInstancesModificationId": "rimod-d3ed4335-b1d3-4de6-ab31-0f13aaf46687", "ReservedInstancesIds": [ { "ReservedInstancesId": "b847fa93-e282-4f55-b59a-1342f5bd7c02" } ] } ] }

以下代码示例演示如何使用 describe-reserved-instances-offerings

AWS CLI

描述预留实例产品

此示例命令描述了该地区所有可供购买的预留实例。

命令:

aws ec2 describe-reserved-instances-offerings

输出:

{ "ReservedInstancesOfferings": [ { "OfferingType": "Partial Upfront", "AvailabilityZone": "us-east-1b", "InstanceTenancy": "default", "PricingDetails": [], "ProductDescription": "Red Hat Enterprise Linux", "UsagePrice": 0.0, "RecurringCharges": [ { "Amount": 0.088, "Frequency": "Hourly" } ], "Marketplace": false, "CurrencyCode": "USD", "FixedPrice": 631.0, "Duration": 94608000, "ReservedInstancesOfferingId": "9a06095a-bdc6-47fe-a94a-2a382f016040", "InstanceType": "c1.medium" }, { "OfferingType": "PartialUpfront", "AvailabilityZone": "us-east-1b", "InstanceTenancy": "default", "PricingDetails": [], "ProductDescription": "Linux/UNIX", "UsagePrice": 0.0, "RecurringCharges": [ { "Amount": 0.028, "Frequency": "Hourly" } ], "Marketplace": false, "CurrencyCode": "USD", "FixedPrice": 631.0, "Duration": 94608000, "ReservedInstancesOfferingId": "bfbefc6c-0d10-418d-b144-7258578d329d", "InstanceType": "c1.medium" }, ... }

使用选项描述您的预留实例产品

此示例列出了按以下规格提供的 AWS 预留实例:t1.micro 实例类型、Windows (AmazonVPC) 产品和高使用率产品。

命令:

aws ec2 describe-reserved-instances-offerings --no-include-marketplace --instance-type "t1.micro" --product-description "Windows (Amazon VPC)" --offering-type "no upfront"

输出:

{ "ReservedInstancesOfferings": [ { "OfferingType": "No Upfront", "AvailabilityZone": "us-east-1b", "InstanceTenancy": "default", "PricingDetails": [], "ProductDescription": "Windows", "UsagePrice": 0.0, "RecurringCharges": [ { "Amount": 0.015, "Frequency": "Hourly" } ], "Marketplace": false, "CurrencyCode": "USD", "FixedPrice": 0.0, "Duration": 31536000, "ReservedInstancesOfferingId": "c48ab04c-fe69-4f94-8e39-a23842292823", "InstanceType": "t1.micro" }, ... { "OfferingType": "No Upfront", "AvailabilityZone": "us-east-1d", "InstanceTenancy": "default", "PricingDetails": [], "ProductDescription": "Windows (Amazon VPC)", "UsagePrice": 0.0, "RecurringCharges": [ { "Amount": 0.015, "Frequency": "Hourly" } ], "Marketplace": false, "CurrencyCode": "USD", "FixedPrice": 0.0, "Duration": 31536000, "ReservedInstancesOfferingId": "3a98bf7d-2123-42d4-b4f5-8dbec4b06dc6", "InstanceType": "t1.micro" } ] }

以下代码示例演示如何使用 describe-reserved-instances

AWS CLI

描述您的预留实例

此示例命令描述了您拥有的预留实例。

命令:

aws ec2 describe-reserved-instances

输出:

{ "ReservedInstances": [ { "ReservedInstancesId": "b847fa93-e282-4f55-b59a-1342fexample", "OfferingType": "No Upfront", "AvailabilityZone": "us-west-1c", "End": "2016-08-14T21:34:34.000Z", "ProductDescription": "Linux/UNIX", "UsagePrice": 0.00, "RecurringCharges": [ { "Amount": 0.104, "Frequency": "Hourly" } ], "Start": "2015-08-15T21:34:35.086Z", "State": "active", "FixedPrice": 0.0, "CurrencyCode": "USD", "Duration": 31536000, "InstanceTenancy": "default", "InstanceType": "m3.medium", "InstanceCount": 2 }, ... ] }

使用筛选器描述您的预留实例

此示例对响应进行筛选,仅包含 us-west-1c 中为期三年、t2.micro Linux/ UNIX 预留实例。

命令:

aws ec2 describe-reserved-instances --filters Name=duration,Values=94608000 Name=instance-type,Values=t2.micro Name=product-description,Values=Linux/UNIX Name=availability-zone,Values=us-east-1e

输出:

{ "ReservedInstances": [ { "ReservedInstancesId": "f127bd27-edb7-44c9-a0eb-0d7e09259af0", "OfferingType": "All Upfront", "AvailabilityZone": "us-east-1e", "End": "2018-03-26T21:34:34.000Z", "ProductDescription": "Linux/UNIX", "UsagePrice": 0.00, "RecurringCharges": [], "Start": "2015-03-27T21:34:35.848Z", "State": "active", "FixedPrice": 151.0, "CurrencyCode": "USD", "Duration": 94608000, "InstanceTenancy": "default", "InstanceType": "t2.micro", "InstanceCount": 1 } ] }

有关更多信息,请参阅AWS 命令行界面用户指南中的使用 Amazon EC2 实例。

以下代码示例演示如何使用 describe-route-tables

AWS CLI

描述您的路由表

以下describe-route-tables示例检索有关您的路由表的详细信息

aws ec2 describe-route-tables

输出:

{ "RouteTables": [ { "Associations": [ { "Main": true, "RouteTableAssociationId": "rtbassoc-0df3f54e06EXAMPLE", "RouteTableId": "rtb-09ba434c1bEXAMPLE" } ], "PropagatingVgws": [], "RouteTableId": "rtb-09ba434c1bEXAMPLE", "Routes": [ { "DestinationCidrBlock": "10.0.0.0/16", "GatewayId": "local", "Origin": "CreateRouteTable", "State": "active" }, { "DestinationCidrBlock": "0.0.0.0/0", "NatGatewayId": "nat-06c018cbd8EXAMPLE", "Origin": "CreateRoute", "State": "blackhole" } ], "Tags": [], "VpcId": "vpc-0065acced4EXAMPLE", "OwnerId": "111122223333" }, { "Associations": [ { "Main": true, "RouteTableAssociationId": "rtbassoc-9EXAMPLE", "RouteTableId": "rtb-a1eec7de" } ], "PropagatingVgws": [], "RouteTableId": "rtb-a1eec7de", "Routes": [ { "DestinationCidrBlock": "172.31.0.0/16", "GatewayId": "local", "Origin": "CreateRouteTable", "State": "active" }, { "DestinationCidrBlock": "0.0.0.0/0", "GatewayId": "igw-fEXAMPLE", "Origin": "CreateRoute", "State": "active" } ], "Tags": [], "VpcId": "vpc-3EXAMPLE", "OwnerId": "111122223333" }, { "Associations": [ { "Main": false, "RouteTableAssociationId": "rtbassoc-0b100c28b2EXAMPLE", "RouteTableId": "rtb-07a98f76e5EXAMPLE", "SubnetId": "subnet-0d3d002af8EXAMPLE" } ], "PropagatingVgws": [], "RouteTableId": "rtb-07a98f76e5EXAMPLE", "Routes": [ { "DestinationCidrBlock": "10.0.0.0/16", "GatewayId": "local", "Origin": "CreateRouteTable", "State": "active" }, { "DestinationCidrBlock": "0.0.0.0/0", "GatewayId": "igw-06cf664d80EXAMPLE", "Origin": "CreateRoute", "State": "active" } ], "Tags": [], "VpcId": "vpc-0065acced4EXAMPLE", "OwnerId": "111122223333" } ] }

有关更多信息,请参阅AWS VPC用户指南中的使用路由表

以下代码示例演示如何使用 describe-scheduled-instance-availability

AWS CLI

描述可用的日程安排

此示例描述了从指定日期开始每周星期日发生的日程安排。

命令:

aws ec2 describe-scheduled-instance-availability --recurrence Frequency=Weekly,Interval=1,OccurrenceDays=[1] --first-slot-start-time-range EarliestTime=2016-01-31T00:00:00Z,LatestTime=2016-01-31T04:00:00Z

输出:

{ "ScheduledInstanceAvailabilitySet": [ { "AvailabilityZone": "us-west-2b", "TotalScheduledInstanceHours": 1219, "PurchaseToken": "eyJ2IjoiMSIsInMiOjEsImMiOi...", "MinTermDurationInDays": 366, "AvailableInstanceCount": 20, "Recurrence": { "OccurrenceDaySet": [ 1 ], "Interval": 1, "Frequency": "Weekly", "OccurrenceRelativeToEnd": false }, "Platform": "Linux/UNIX", "FirstSlotStartTime": "2016-01-31T00:00:00Z", "MaxTermDurationInDays": 366, "SlotDurationInHours": 23, "NetworkPlatform": "EC2-VPC", "InstanceType": "c4.large", "HourlyPrice": "0.095" }, ... ] }

要缩小结果范围,您可以添加过滤器来指定操作系统、网络和实例类型。

命令:

--filters name=Platform,Values=Linux/ name=Network-Platform,Values=-name=instance-type,valu UNIX es= EC2 VPC

以下代码示例演示如何使用 describe-scheduled-instances

AWS CLI

描述您的计划实例

此示例描述了指定的计划实例。

命令:

aws ec2 describe-scheduled-instances --scheduled-instance-ids sci-1234-1234-1234-1234-123456789012

输出:

{ "ScheduledInstanceSet": [ { "AvailabilityZone": "us-west-2b", "ScheduledInstanceId": "sci-1234-1234-1234-1234-123456789012", "HourlyPrice": "0.095", "CreateDate": "2016-01-25T21:43:38.612Z", "Recurrence": { "OccurrenceDaySet": [ 1 ], "Interval": 1, "Frequency": "Weekly", "OccurrenceRelativeToEnd": false, "OccurrenceUnit": "" }, "Platform": "Linux/UNIX", "TermEndDate": "2017-01-31T09:00:00Z", "InstanceCount": 1, "SlotDurationInHours": 32, "TermStartDate": "2016-01-31T09:00:00Z", "NetworkPlatform": "EC2-VPC", "TotalScheduledInstanceHours": 1696, "NextSlotStartTime": "2016-01-31T09:00:00Z", "InstanceType": "c4.large" } ] }

此示例描述了您的所有计划实例。

命令:

aws ec2 describe-scheduled-instances

以下代码示例演示如何使用 describe-security-group-references

AWS CLI

描述安全组引用

此示例描述了的安全组引用sg-bbbb2222。响应表明中的安全组sg-bbbb2222正在引用安全组VPCvpc-aaaaaaaa

命令:

aws ec2 describe-security-group-references --group-id sg-bbbbb22222

输出:

{ "SecurityGroupsReferenceSet": [ { "ReferencingVpcId": "vpc-aaaaaaaa ", "GroupId": "sg-bbbbb22222", "VpcPeeringConnectionId": "pcx-b04deed9" } ] }

以下代码示例演示如何使用 describe-security-group-rules

AWS CLI

示例 1:描述安全组的安全组规则

以下describe-security-group-rules示例描述了指定安全组的安全组规则。使用filters选项将结果范围限定为特定的安全组。

aws ec2 describe-security-group-rules \ --filters Name="group-id",Values="sg-1234567890abcdef0"

输出:

{ "SecurityGroupRules": [ { "SecurityGroupRuleId": "sgr-abcdef01234567890", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "111122223333", "IsEgress": false, "IpProtocol": "-1", "FromPort": -1, "ToPort": -1, "ReferencedGroupInfo": { "GroupId": "sg-1234567890abcdef0", "UserId": "111122223333" }, "Tags": [] }, { "SecurityGroupRuleId": "sgr-bcdef01234567890a", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "111122223333", "IsEgress": true, "IpProtocol": "-1", "FromPort": -1, "ToPort": -1, "CidrIpv6": "::/0", "Tags": [] }, { "SecurityGroupRuleId": "sgr-cdef01234567890ab", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "111122223333", "IsEgress": true, "IpProtocol": "-1", "FromPort": -1, "ToPort": -1, "CidrIpv4": "0.0.0.0/0", "Tags": [] } ] }

示例 2:描述安全组规则

以下describe-security-group-rules示例描述了指定的安全组规则。

aws ec2 describe-security-group-rules \ --security-group-rule-ids sgr-cdef01234567890ab

输出:

{ "SecurityGroupRules": [ { "SecurityGroupRuleId": "sgr-cdef01234567890ab", "GroupId": "sg-1234567890abcdef0", "GroupOwnerId": "111122223333", "IsEgress": true, "IpProtocol": "-1", "FromPort": -1, "ToPort": -1, "CidrIpv4": "0.0.0.0/0", "Tags": [] } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的安全组规则

以下代码示例演示如何使用 describe-security-groups

AWS CLI

示例 1:描述安全组

以下 describe-security-groups 示例描述了指定的安全组。

aws ec2 describe-security-groups \ --group-ids sg-903004f8

输出:

{ "SecurityGroups": [ { "IpPermissionsEgress": [ { "IpProtocol": "-1", "IpRanges": [ { "CidrIp": "0.0.0.0/0" } ], "UserIdGroupPairs": [], "PrefixListIds": [] } ], "Description": "My security group", "Tags": [ { "Value": "SG1", "Key": "Name" } ], "IpPermissions": [ { "IpProtocol": "-1", "IpRanges": [], "UserIdGroupPairs": [ { "UserId": "123456789012", "GroupId": "sg-903004f8" } ], "PrefixListIds": [] }, { "PrefixListIds": [], "FromPort": 22, "IpRanges": [ { "Description": "Access from NY office", "CidrIp": "203.0.113.0/24" } ], "ToPort": 22, "IpProtocol": "tcp", "UserIdGroupPairs": [] } ], "GroupName": "MySecurityGroup", "VpcId": "vpc-1a2b3c4d", "OwnerId": "123456789012", "GroupId": "sg-903004f8", } ] }

示例 2:描述具有特定规则的安全组

以下describe-security-groups示例使用过滤器将结果范围限定为具有允许SSH流量的规则(端口 22)和允许来自所有地址的流量的规则(0.0.0.0/0)的安全组。示例使用 --query 参数仅显示安全组的名称。安全组必须匹配要在结果中返回的所有筛选条件;但是,单个规则不必匹配所有筛选条件。例如,输出返回一个安全组,其规则允许来自特定 IP 地址的SSH流量,另一个规则允许来自所有地址的HTTP流量。

aws ec2 describe-security-groups \ --filters Name=ip-permission.from-port,Values=22 Name=ip-permission.to-port,Values=22 Name=ip-permission.cidr,Values='0.0.0.0/0' \ --query "SecurityGroups[*].[GroupName]" \ --output text

输出:

default my-security-group web-servers launch-wizard-1

示例 3:根据标签描述安全组

以下 describe-security-groups 示例使用筛选器,将结果范围限定为安全组名称中包含 test 且带有标签 Test=To-delete 的安全组。该示例使用--query参数仅显示安全组IDs的名称和名称。

aws ec2 describe-security-groups \ --filters Name=group-name,Values=*test* Name=tag:Test,Values=To-delete \ --query "SecurityGroups[*].{Name:GroupName,ID:GroupId}"

输出:

[ { "Name": "testfornewinstance", "ID": "sg-33bb22aa" }, { "Name": "newgrouptest", "ID": "sg-1a2b3c4d" } ]

有关使用标签筛选条件的其他示例,请参阅 Amazon EC2 用户指南中的使用标签

以下代码示例演示如何使用 describe-snapshot-attribute

AWS CLI

描述快照的快照属性

以下describe-snapshot-attribute示例列出了共享快照的账户。

aws ec2 describe-snapshot-attribute \ --snapshot-id snap-01234567890abcedf \ --attribute createVolumePermission

输出:

{ "SnapshotId": "snap-01234567890abcedf", "CreateVolumePermissions": [ { "UserId": "123456789012" } ] }

有关更多信息,请参阅亚马逊弹性计算云用户指南中的共享亚马逊EBS快照

以下代码示例演示如何使用 describe-snapshot-tier-status

AWS CLI

查看有关存档快照的存档信息

以下describe-snapshot-tier-status示例提供了有关已存档快照的存档信息。

aws ec2 describe-snapshot-tier-status \ --filters "Name=snapshot-id, Values=snap-01234567890abcedf"

输出:

{ "SnapshotTierStatuses": [ { "Status": "completed", "ArchivalCompleteTime": "2021-09-15T17:33:16.147Z", "LastTieringProgress": 100, "Tags": [], "VolumeId": "vol-01234567890abcedf", "LastTieringOperationState": "archival-completed", "StorageTier": "archive", "OwnerId": "123456789012", "SnapshotId": "snap-01234567890abcedf", "LastTieringStartTime": "2021-09-15T16:44:37.574Z" } ] }

有关更多信息,请参阅《Amazon Elastic Compute Cloud 用户指南》中的查看已存档快照

以下代码示例演示如何使用 describe-snapshots

AWS CLI

示例 1:描述快照

以下 describe-snapshots 示例描述了指定的快照。

aws ec2 describe-snapshots \ --snapshot-ids snap-1234567890abcdef0

输出:

{ "Snapshots": [ { "Description": "This is my snapshot", "Encrypted": false, "VolumeId": "vol-049df61146c4d7901", "State": "completed", "VolumeSize": 8, "StartTime": "2019-02-28T21:28:32.000Z", "Progress": "100%", "OwnerId": "012345678910", "SnapshotId": "snap-01234567890abcdef", "Tags": [ { "Key": "Stack", "Value": "test" } ] } ] }

有关更多信息,请参阅《亚马逊EC2用户指南》中的亚马逊EBS快照

示例 2:描述基于筛选器的快照

以下describe-snapshots示例使用筛选条件将结果范围限定为您的 AWS 账户拥有的处于该pending状态的快照。该示例使用--query参数仅显示快照IDs和快照的启动时间。

aws ec2 describe-snapshots \ --owner-ids self \ --filters Name=status,Values=pending \ --query "Snapshots[*].{ID:SnapshotId,Time:StartTime}"

输出:

[ { "ID": "snap-1234567890abcdef0", "Time": "2019-08-04T12:48:18.000Z" }, { "ID": "snap-066877671789bd71b", "Time": "2019-08-04T02:45:16.000Z }, ... ]

以下 describe-snapshots 示例使用筛选器,将结果范围限定为从指定卷创建的快照。该示例使用--query参数仅显示快照IDs。

aws ec2 describe-snapshots \ --filters Name=volume-id,Values=049df61146c4d7901 \ --query "Snapshots[*].[SnapshotId]" \ --output text

输出:

snap-1234567890abcdef0 snap-08637175a712c3fb9 ...

有关使用筛选条件的其他示例,请参阅 Amazon EC2 用户指南中的列出和筛选您的资源

示例 3:根据标签描述快照

以下 describe-snapshots 示例使用标签筛选器,将结果范围限定为带有标签 Stack=Prod 的快照。

aws ec2 describe-snapshots \ --filters Name=tag:Stack,Values=prod

有关 describe-snapshots 的输出示例,请参阅示例 1。

有关使用标签筛选条件的其他示例,请参阅 Amazon EC2 用户指南中的使用标签

示例 4:根据期限描述快照

以下describe-snapshots示例使用JMESPath表达式来描述您的 AWS 账户在指定日期之前创建的所有快照。它仅显示快照IDs。

aws ec2 describe-snapshots \ --owner-ids 012345678910 \ --query "Snapshots[?(StartTime<='2020-03-31')].[SnapshotId]"

有关使用筛选条件的其他示例,请参阅 Amazon EC2 用户指南中的列出和筛选您的资源

示例 5:仅查看存档的快照

以下 describe-snapshots 示例列出归档层中存储的快照。

aws ec2 describe-snapshots \ --filters "Name=storage-tier,Values=archive"

输出:

{ "Snapshots": [ { "Description": "Snap A", "Encrypted": false, "VolumeId": "vol-01234567890aaaaaa", "State": "completed", "VolumeSize": 8, "StartTime": "2021-09-07T21:00:00.000Z", "Progress": "100%", "OwnerId": "123456789012", "SnapshotId": "snap-01234567890aaaaaa", "StorageTier": "archive", "Tags": [] }, ] }

有关更多信息,请参阅《Amazon Elastic Compute Cloud 用户指南》中的查看已存档快照

以下代码示例演示如何使用 describe-spot-datafeed-subscription

AWS CLI

描述账户的竞价型实例数据源订阅

此示例命令描述了账户的数据馈送。

命令:

aws ec2 describe-spot-datafeed-subscription

输出:

{ "SpotDatafeedSubscription": { "OwnerId": "123456789012", "Prefix": "spotdata", "Bucket": "my-s3-bucket", "State": "Active" } }

以下代码示例演示如何使用 describe-spot-fleet-instances

AWS CLI

描述与竞价型队列关联的竞价型实例

此示例命令列出了与指定竞价型队列关联的竞价型实例。

命令:

aws ec2 describe-spot-fleet-instances --spot-fleet-request-id sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE

输出:

{ "ActiveInstances": [ { "InstanceId": "i-1234567890abcdef0", "InstanceType": "m3.medium", "SpotInstanceRequestId": "sir-08b93456" }, ... ], "SpotFleetRequestId": "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE" }

以下代码示例演示如何使用 describe-spot-fleet-request-history

AWS CLI

描述 Spot 舰队的历史

此示例命令返回从指定时间开始的指定 Spot 队列的历史记录。

命令:

aws ec2 describe-spot-fleet-request-history --spot-fleet-request-id sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE --start-time 2015-05-26T00:00:00Z

以下示例输出显示了竞价型队列的两个竞价型实例的成功启动。

输出:

{ "HistoryRecords": [ { "Timestamp": "2015-05-26T23:17:20.697Z", "EventInformation": { "EventSubType": "submitted" }, "EventType": "fleetRequestChange" }, { "Timestamp": "2015-05-26T23:17:20.873Z", "EventInformation": { "EventSubType": "active" }, "EventType": "fleetRequestChange" }, { "Timestamp": "2015-05-26T23:21:21.712Z", "EventInformation": { "InstanceId": "i-1234567890abcdef0", "EventSubType": "launched" }, "EventType": "instanceChange" }, { "Timestamp": "2015-05-26T23:21:21.816Z", "EventInformation": { "InstanceId": "i-1234567890abcdef1", "EventSubType": "launched" }, "EventType": "instanceChange" } ], "SpotFleetRequestId": "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE", "NextToken": "CpHNsscimcV5oH7bSbub03CI2Qms5+ypNpNm+53MNlR0YcXAkp0xFlfKf91yVxSExmbtma3awYxMFzNA663ZskT0AHtJ6TCb2Z8bQC2EnZgyELbymtWPfpZ1ZbauVg+P+TfGlWxWWB/Vr5dk5d4LfdgA/DRAHUrYgxzrEXAMPLE=", "StartTime": "2015-05-26T00:00:00Z" }

以下代码示例演示如何使用 describe-spot-fleet-requests

AWS CLI

描述您的 Spot 队列请求

此示例描述了您的所有 Spot 队列请求。

命令:

aws ec2 describe-spot-fleet-requests

输出:

{ "SpotFleetRequestConfigs": [ { "SpotFleetRequestId": "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE", "SpotFleetRequestConfig": { "TargetCapacity": 20, "LaunchSpecifications": [ { "EbsOptimized": false, "NetworkInterfaces": [ { "SubnetId": "subnet-a61dafcf", "DeviceIndex": 0, "DeleteOnTermination": false, "AssociatePublicIpAddress": true, "SecondaryPrivateIpAddressCount": 0 } ], "InstanceType": "cc2.8xlarge", "ImageId": "ami-1a2b3c4d" }, { "EbsOptimized": false, "NetworkInterfaces": [ { "SubnetId": "subnet-a61dafcf", "DeviceIndex": 0, "DeleteOnTermination": false, "AssociatePublicIpAddress": true, "SecondaryPrivateIpAddressCount": 0 } ], "InstanceType": "r3.8xlarge", "ImageId": "ami-1a2b3c4d" } ], "SpotPrice": "0.05", "IamFleetRole": "arn:aws:iam::123456789012:role/my-spot-fleet-role" }, "SpotFleetRequestState": "active" }, { "SpotFleetRequestId": "sfr-306341ed-9739-402e-881b-ce47bEXAMPLE", "SpotFleetRequestConfig": { "TargetCapacity": 20, "LaunchSpecifications": [ { "EbsOptimized": false, "NetworkInterfaces": [ { "SubnetId": "subnet-6e7f829e", "DeviceIndex": 0, "DeleteOnTermination": false, "AssociatePublicIpAddress": true, "SecondaryPrivateIpAddressCount": 0 } ], "InstanceType": "m3.medium", "ImageId": "ami-1a2b3c4d" } ], "SpotPrice": "0.05", "IamFleetRole": "arn:aws:iam::123456789012:role/my-spot-fleet-role" }, "SpotFleetRequestState": "active" } ] }

描述 Spot 队列请求

此示例描述了指定的 Spot 队列请求。

命令:

aws ec2 describe-spot-fleet-requests --spot-fleet-request-ids sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE

输出:

{ "SpotFleetRequestConfigs": [ { "SpotFleetRequestId": "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE", "SpotFleetRequestConfig": { "TargetCapacity": 20, "LaunchSpecifications": [ { "EbsOptimized": false, "NetworkInterfaces": [ { "SubnetId": "subnet-a61dafcf", "DeviceIndex": 0, "DeleteOnTermination": false, "AssociatePublicIpAddress": true, "SecondaryPrivateIpAddressCount": 0 } ], "InstanceType": "cc2.8xlarge", "ImageId": "ami-1a2b3c4d" }, { "EbsOptimized": false, "NetworkInterfaces": [ { "SubnetId": "subnet-a61dafcf", "DeviceIndex": 0, "DeleteOnTermination": false, "AssociatePublicIpAddress": true, "SecondaryPrivateIpAddressCount": 0 } ], "InstanceType": "r3.8xlarge", "ImageId": "ami-1a2b3c4d" } ], "SpotPrice": "0.05", "IamFleetRole": "arn:aws:iam::123456789012:role/my-spot-fleet-role" }, "SpotFleetRequestState": "active" } ] }

以下代码示例演示如何使用 describe-spot-instance-requests

AWS CLI

示例 1:描述竞价型实例请求

以下describe-spot-instance-requests示例描述了指定的竞价型实例请求。

aws ec2 describe-spot-instance-requests \ --spot-instance-request-ids sir-08b93456

输出:

{ "SpotInstanceRequests": [ { "CreateTime": "2018-04-30T18:14:55.000Z", "InstanceId": "i-1234567890abcdef1", "LaunchSpecification": { "InstanceType": "t2.micro", "ImageId": "ami-003634241a8fcdec0", "KeyName": "my-key-pair", "SecurityGroups": [ { "GroupName": "default", "GroupId": "sg-e38f24a7" } ], "BlockDeviceMappings": [ { "DeviceName": "/dev/sda1", "Ebs": { "DeleteOnTermination": true, "SnapshotId": "snap-0e54a519c999adbbd", "VolumeSize": 8, "VolumeType": "standard", "Encrypted": false } } ], "NetworkInterfaces": [ { "DeleteOnTermination": true, "DeviceIndex": 0, "SubnetId": "subnet-049df61146c4d7901" } ], "Placement": { "AvailabilityZone": "us-east-2b", "Tenancy": "default" }, "Monitoring": { "Enabled": false } }, "LaunchedAvailabilityZone": "us-east-2b", "ProductDescription": "Linux/UNIX", "SpotInstanceRequestId": "sir-08b93456", "SpotPrice": "0.010000" "State": "active", "Status": { "Code": "fulfilled", "Message": "Your Spot request is fulfilled.", "UpdateTime": "2018-04-30T18:16:21.000Z" }, "Tags": [], "Type": "one-time", "InstanceInterruptionBehavior": "terminate" } ] }

示例 2:描述基于筛选条件的竞价型实例请求

以下describe-spot-instance-requests示例使用筛选条件将结果限定为指定可用区内具有指定实例类型的竞价型实例请求。该示例使用--query参数仅显示实例IDs。

aws ec2 describe-spot-instance-requests \ --filters Name=launch.instance-type,Values=m3.medium Name=launched-availability-zone,Values=us-east-2a \ --query "SpotInstanceRequests[*].[InstanceId]" \ --output text

输出:

i-057750d42936e468a i-001efd250faaa6ffa i-027552a73f021f3bd ...

有关使用筛选条件的其他示例,请参阅《亚马逊弹性计算云用户指南》中的列出和筛选您的资源

示例 3:描述基于标签的竞价型实例请求

以下describe-spot-instance-requests示例使用标签筛选器将结果范围限定为带有该标签的竞价型实例请求cost-center=cc123

aws ec2 describe-spot-instance-requests \ --filters Name=tag:cost-center,Values=cc123

有关 describe-spot-instance-requests 的输出示例,请参阅示例 1。

有关使用标签筛选条件的其他示例,请参阅 Amazon EC2 用户指南中的使用标签

以下代码示例演示如何使用 describe-spot-price-history

AWS CLI

描述现货价格历史记录

此示例命令返回 m1.xlarge 实例在一月份特定日期的竞价价格历史记录。

命令:

aws ec2 describe-spot-price-history --instance-types m1.xlarge --start-time 2014-01-06T07:08:09 --end-time 2014-01-06T08:09:10

输出:

{ "SpotPriceHistory": [ { "Timestamp": "2014-01-06T07:10:55.000Z", "ProductDescription": "SUSE Linux", "InstanceType": "m1.xlarge", "SpotPrice": "0.087000", "AvailabilityZone": "us-west-1b" }, { "Timestamp": "2014-01-06T07:10:55.000Z", "ProductDescription": "SUSE Linux", "InstanceType": "m1.xlarge", "SpotPrice": "0.087000", "AvailabilityZone": "us-west-1c" }, { "Timestamp": "2014-01-06T05:42:36.000Z", "ProductDescription": "SUSE Linux (Amazon VPC)", "InstanceType": "m1.xlarge", "SpotPrice": "0.087000", "AvailabilityZone": "us-west-1a" }, ... }

描述 Linux UNIX /Amazon 的现货价格历史记录 VPC

此示例命令返回 m1.xlarge、Linux/A UNIX mazon VPC 实例在一月份特定日期的现货价格历史记录。

命令:

aws ec2 describe-spot-price-history --instance-types m1.xlarge --product-description "Linux/UNIX (Amazon VPC)" --start-time 2014-01-06T07:08:09 --end-time 2014-01-06T08:09:10

输出:

{ "SpotPriceHistory": [ { "Timestamp": "2014-01-06T04:32:53.000Z", "ProductDescription": "Linux/UNIX (Amazon VPC)", "InstanceType": "m1.xlarge", "SpotPrice": "0.080000", "AvailabilityZone": "us-west-1a" }, { "Timestamp": "2014-01-05T11:28:26.000Z", "ProductDescription": "Linux/UNIX (Amazon VPC)", "InstanceType": "m1.xlarge", "SpotPrice": "0.080000", "AvailabilityZone": "us-west-1c" } ] }

以下代码示例演示如何使用 describe-stale-security-groups

AWS CLI

描述陈旧的安全组

此示例描述了的过时安全组规则。vpc-11223344响应显示,您的账户中的 sg-5fa68d3a 有一条过时的入口SSH规则,该规则在对等体sg-279ab042中引用,而您的账户中有一条在对等体VPCsg-fe6fba9a中引用的过时出站规则。SSH sg-ef6fba8b VPC

命令:

aws ec2 describe-stale-security-groups --vpc-id vpc-11223344

输出:

{ "StaleSecurityGroupSet": [ { "VpcId": "vpc-11223344", "StaleIpPermissionsEgress": [ { "ToPort": 22, "FromPort": 22, "UserIdGroupPairs": [ { "VpcId": "vpc-7a20e51f", "GroupId": "sg-ef6fba8b", "VpcPeeringConnectionId": "pcx-b04deed9", "PeeringStatus": "active" } ], "IpProtocol": "tcp" } ], "GroupName": "MySG1", "StaleIpPermissions": [], "GroupId": "sg-fe6fba9a", "Description": MySG1" }, { "VpcId": "vpc-11223344", "StaleIpPermissionsEgress": [], "GroupName": "MySG2", "StaleIpPermissions": [ { "ToPort": 22, "FromPort": 22, "UserIdGroupPairs": [ { "VpcId": "vpc-7a20e51f", "GroupId": "sg-279ab042", "Description": "Access from pcx-b04deed9", "VpcPeeringConnectionId": "pcx-b04deed9", "PeeringStatus": "active" } ], "IpProtocol": "tcp" } ], "GroupId": "sg-5fa68d3a", "Description": "MySG2" } ] }

以下代码示例演示如何使用 describe-store-image-tasks

AWS CLI

描述AMI商店任务的进度

以下describe-store-image-tasks示例描述了AMI存储任务的进度。

aws ec2 describe-store-image-tasks

输出:

{ "StoreImageTaskResults": [ { "AmiId": "ami-1234567890abcdef0", "Bucket": "my-ami-bucket", "ProgressPercentage": 17, "S3objectKey": "ami-1234567890abcdef0.bin", "StoreTaskState": "InProgress", "StoreTaskFailureReason": null, "TaskStartTime": "2022-01-01T01:01:01.001Z" } ] }

有关使用 S3 存储和恢复的更多信息,请参阅《亚马逊用户指南》中的AMI使用 S3 <https://docs.aws.amazon.com/AWS EC2/latest/UserGuide/ami-store-restore.html> 存储和恢复。AMI EC2

以下代码示例演示如何使用 describe-subnets

AWS CLI

示例 1:描述所有子网

以下 describe-subnets 示例显示子网的详细信息。

aws ec2 describe-subnets

输出:

{ "Subnets": [ { "AvailabilityZone": "us-east-1d", "AvailabilityZoneId": "use1-az2", "AvailableIpAddressCount": 4089, "CidrBlock": "172.31.80.0/20", "DefaultForAz": true, "MapPublicIpOnLaunch": false, "MapCustomerOwnedIpOnLaunch": true, "State": "available", "SubnetId": "subnet-0bb1c79de3EXAMPLE", "VpcId": "vpc-0ee975135dEXAMPLE", "OwnerId": "111122223333", "AssignIpv6AddressOnCreation": false, "Ipv6CidrBlockAssociationSet": [], "CustomerOwnedIpv4Pool:": 'pool-2EXAMPLE', "SubnetArn": "arn:aws:ec2:us-east-2:111122223333:subnet/subnet-0bb1c79de3EXAMPLE", "EnableDns64": false, "Ipv6Native": false, "PrivateDnsNameOptionsOnLaunch": { "HostnameType": "ip-name", "EnableResourceNameDnsARecord": false, "EnableResourceNameDnsAAAARecord": false } }, { "AvailabilityZone": "us-east-1d", "AvailabilityZoneId": "use1-az2", "AvailableIpAddressCount": 4089, "CidrBlock": "172.31.80.0/20", "DefaultForAz": true, "MapPublicIpOnLaunch": true, "MapCustomerOwnedIpOnLaunch": false, "State": "available", "SubnetId": "subnet-8EXAMPLE", "VpcId": "vpc-3EXAMPLE", "OwnerId": "1111222233333", "AssignIpv6AddressOnCreation": false, "Ipv6CidrBlockAssociationSet": [], "Tags": [ { "Key": "Name", "Value": "MySubnet" } ], "SubnetArn": "arn:aws:ec2:us-east-1:111122223333:subnet/subnet-8EXAMPLE", "EnableDns64": false, "Ipv6Native": false, "PrivateDnsNameOptionsOnLaunch": { "HostnameType": "ip-name", "EnableResourceNameDnsARecord": false, "EnableResourceNameDnsAAAARecord": false } } ] }

有关更多信息,请参阅《AWS VPC用户指南》中的使用VPCs和子网

示例 2:描述特定子网 VPC

以下describe-subnets示例使用过滤器检索指定VPC子网的详细信息。

aws ec2 describe-subnets \ --filters "Name=vpc-id,Values=vpc-3EXAMPLE"

输出:

{ "Subnets": [ { "AvailabilityZone": "us-east-1d", "AvailabilityZoneId": "use1-az2", "AvailableIpAddressCount": 4089, "CidrBlock": "172.31.80.0/20", "DefaultForAz": true, "MapPublicIpOnLaunch": true, "MapCustomerOwnedIpOnLaunch": false, "State": "available", "SubnetId": "subnet-8EXAMPLE", "VpcId": "vpc-3EXAMPLE", "OwnerId": "1111222233333", "AssignIpv6AddressOnCreation": false, "Ipv6CidrBlockAssociationSet": [], "Tags": [ { "Key": "Name", "Value": "MySubnet" } ], "SubnetArn": "arn:aws:ec2:us-east-1:111122223333:subnet/subnet-8EXAMPLE", "EnableDns64": false, "Ipv6Native": false, "PrivateDnsNameOptionsOnLaunch": { "HostnameType": "ip-name", "EnableResourceNameDnsARecord": false, "EnableResourceNameDnsAAAARecord": false } } ] }

有关更多信息,请参阅《AWS VPC用户指南》中的使用VPCs和子网

示例 3:描述带有特定标签的子网

以下describe-subnets示例使用过滤器检索带有标签的子网的详细信息,CostCenter=123并使用--query参数来显示带有此标签IDs的子网的子网。

aws ec2 describe-subnets \ --filters "Name=tag:CostCenter,Values=123" \ --query "Subnets[*].SubnetId" \ --output text

输出:

subnet-0987a87c8b37348ef subnet-02a95061c45f372ee subnet-03f720e7de2788d73

有关更多信息,请参阅 Amazon VPC 用户指南中的使用VPCs和子网

以下代码示例演示如何使用 describe-tags

AWS CLI

示例 1:描述单个资源的所有标签

以下describe-tags示例描述了指定实例的标签。

aws ec2 describe-tags \ --filters "Name=resource-id,Values=i-1234567890abcdef8"

输出:

{ "Tags": [ { "ResourceType": "instance", "ResourceId": "i-1234567890abcdef8", "Value": "Test", "Key": "Stack" }, { "ResourceType": "instance", "ResourceId": "i-1234567890abcdef8", "Value": "Beta Server", "Key": "Name" } ] }

示例 2:描述资源类型的所有标签

以下describe-tags示例描述了您的卷的标签。

aws ec2 describe-tags \ --filters "Name=resource-type,Values=volume"

输出:

{ "Tags": [ { "ResourceType": "volume", "ResourceId": "vol-1234567890abcdef0", "Value": "Project1", "Key": "Purpose" }, { "ResourceType": "volume", "ResourceId": "vol-049df61146c4d7901", "Value": "Logs", "Key": "Purpose" } ] }

示例 3:描述您的所有标签

以下describe-tags示例描述了您的所有资源的标签。

aws ec2 describe-tags

示例 4:根据标签密钥描述资源的标签

以下describe-tags示例描述了带有密钥标签的资源的标签Stack

aws ec2 describe-tags \ --filters Name=key,Values=Stack

输出:

{ "Tags": [ { "ResourceType": "volume", "ResourceId": "vol-027552a73f021f3b", "Value": "Production", "Key": "Stack" }, { "ResourceType": "instance", "ResourceId": "i-1234567890abcdef8", "Value": "Test", "Key": "Stack" } ] }

示例 5:根据标签键和标签值描述资源的标签

以下describe-tags示例描述了带有该标签的资源的标签Stack=Test

aws ec2 describe-tags \ --filters Name=key,Values=Stack Name=value,Values=Test

输出:

{ "Tags": [ { "ResourceType": "image", "ResourceId": "ami-3ac336533f021f3bd", "Value": "Test", "Key": "Stack" }, { "ResourceType": "instance", "ResourceId": "i-1234567890abcdef8", "Value": "Test", "Key": "Stack" } ] }

以下describe-tags示例使用替代语法来描述带有标签的资源Stack=Test

aws ec2 describe-tags \ --filters "Name=tag:Stack,Values=Test"

以下describe-tags示例描述了所有带有密钥但没有值的标签的实例Purpose的标签。

aws ec2 describe-tags \ --filters "Name=resource-type,Values=instance" "Name=key,Values=Purpose" "Name=value,Values="

输出:

{ "Tags": [ { "ResourceType": "instance", "ResourceId": "i-1234567890abcdef5", "Value": null, "Key": "Purpose" } ] }

以下代码示例演示如何使用 describe-traffic-mirror-filters

AWS CLI

查看您的交通镜像过滤器

以下describe-traffic-mirror-filters示例显示了所有流量镜像过滤器的详细信息。

aws ec2 describe-traffic-mirror-filters

输出:

{ "TrafficMirrorFilters": [ { "TrafficMirrorFilterId": "tmf-0293f26e86EXAMPLE", "IngressFilterRules": [ { "TrafficMirrorFilterRuleId": "tmfr-0ca76e0e08EXAMPLE", "TrafficMirrorFilterId": "tmf-0293f26e86EXAMPLE", "TrafficDirection": "ingress", "RuleNumber": 100, "RuleAction": "accept", "Protocol": 6, "DestinationCidrBlock": "10.0.0.0/24", "SourceCidrBlock": "10.0.0.0/24", "Description": "TCP Rule" } ], "EgressFilterRules": [], "NetworkServices": [], "Description": "Example filter", "Tags": [] } ] }

有关更多信息,请参阅《流量镜像指南》中的 “查看您的流量镜像过滤器”。

以下代码示例演示如何使用 describe-traffic-mirror-sessions

AWS CLI

描述流量镜像会话

以下describe-traffic-mirror-sessions示例显示了您的流量镜像会话的详细信息。

aws ec2 describe-traffic-mirror-sessions

输出:

{ "TrafficMirrorSessions": [ { "Tags": [], "VirtualNetworkId": 42, "OwnerId": "111122223333", "Description": "TCP Session", "NetworkInterfaceId": "eni-0a471a5cf3EXAMPLE", "TrafficMirrorTargetId": "tmt-0dabe9b0a6EXAMPLE", "TrafficMirrorFilterId": "tmf-083e18f985EXAMPLE", "PacketLength": 20, "SessionNumber": 1, "TrafficMirrorSessionId": "tms-0567a4c684EXAMPLE" }, { "Tags": [ { "Key": "Name", "Value": "tag test" } ], "VirtualNetworkId": 13314501, "OwnerId": "111122223333", "Description": "TCP Session", "NetworkInterfaceId": "eni-0a471a5cf3EXAMPLE", "TrafficMirrorTargetId": "tmt-03665551cbEXAMPLE", "TrafficMirrorFilterId": "tmf-06c787846cEXAMPLE", "SessionNumber": 2, "TrafficMirrorSessionId": "tms-0060101cf8EXAMPLE" } ] }

有关更多信息,请参阅《流量镜像指南》中的 “查看AWS 流量镜像会话详细信息”。

以下代码示例演示如何使用 describe-traffic-mirror-targets

AWS CLI

描述流量镜像目标

以下describe-traffic-mirror-targets示例显示有关指定流量镜像目标的信息。

aws ec2 describe-traffic-mirror-targets \ --traffic-mirror-target-ids tmt-0dabe9b0a6EXAMPLE

输出:

{ "TrafficMirrorTargets": [ { "TrafficMirrorTargetId": "tmt-0dabe9b0a6EXAMPLE", "NetworkLoadBalancerArn": "arn:aws:elasticloadbalancing:us-east-1:111122223333:loadbalancer/net/NLB/7cdec873fEXAMPLE", "Type": "network-load-balancer", "Description": "Example Network Load Balancer target", "OwnerId": "111122223333", "Tags": [] } ] }

有关更多信息,请参阅 Amazon 流量镜像指南中的VPC流量镜像目标

以下代码示例演示如何使用 describe-transit-gateway-attachments

AWS CLI

查看您的公交网关附件

以下describe-transit-gateway-attachments示例显示您的公交网关附件的详细信息。

aws ec2 describe-transit-gateway-attachments

输出:

{ "TransitGatewayAttachments": [ { "TransitGatewayAttachmentId": "tgw-attach-01f8100bc7EXAMPLE", "TransitGatewayId": "tgw-02f776b1a7EXAMPLE", "TransitGatewayOwnerId": "123456789012", "ResourceOwnerId": "123456789012", "ResourceType": "vpc", "ResourceId": "vpc-3EXAMPLE", "State": "available", "Association": { "TransitGatewayRouteTableId": "tgw-rtb-002573ed1eEXAMPLE", "State": "associated" }, "CreationTime": "2019-08-26T14:59:25.000Z", "Tags": [ { "Key": "Name", "Value": "Example" } ] }, { "TransitGatewayAttachmentId": "tgw-attach-0b5968d3b6EXAMPLE", "TransitGatewayId": "tgw-02f776b1a7EXAMPLE", "TransitGatewayOwnerId": "123456789012", "ResourceOwnerId": "123456789012", "ResourceType": "vpc", "ResourceId": "vpc-0065acced4EXAMPLE", "State": "available", "Association": { "TransitGatewayRouteTableId": "tgw-rtb-002573ed1eEXAMPLE", "State": "associated" }, "CreationTime": "2019-08-07T17:03:07.000Z", "Tags": [] }, { "TransitGatewayAttachmentId": "tgw-attach-08e0bc912cEXAMPLE", "TransitGatewayId": "tgw-02f776b1a7EXAMPLE", "TransitGatewayOwnerId": "123456789012", "ResourceOwnerId": "123456789012", "ResourceType": "direct-connect-gateway", "ResourceId": "11460968-4ac1-4fd3-bdb2-00599EXAMPLE", "State": "available", "Association": { "TransitGatewayRouteTableId": "tgw-rtb-002573ed1eEXAMPLE", "State": "associated" }, "CreationTime": "2019-08-14T20:27:44.000Z", "Tags": [] }, { "TransitGatewayAttachmentId": "tgw-attach-0a89069f57EXAMPLE", "TransitGatewayId": "tgw-02f776b1a7EXAMPLE", "TransitGatewayOwnerId": "123456789012", "ResourceOwnerId": "123456789012", "ResourceType": "direct-connect-gateway", "ResourceId": "8384da05-13ce-4a91-aada-5a1baEXAMPLE", "State": "available", "Association": { "TransitGatewayRouteTableId": "tgw-rtb-002573ed1eEXAMPLE", "State": "associated" }, "CreationTime": "2019-08-14T20:33:02.000Z", "Tags": [] } ] }

有关更多信息,请参阅《公交网关指南》中的使用中转网关

以下代码示例演示如何使用 describe-transit-gateway-connect-peers

AWS CLI

描述 Transit Gateway Connect 对等方

以下describe-transit-gateway-connect-peers示例描述了指定的 Connect 对等体。

aws ec2 describe-transit-gateway-connect-peers \ --transit-gateway-connect-peer-ids tgw-connect-peer-0666adbac4EXAMPLE

输出:

{ "TransitGatewayConnectPeers": [ { "TransitGatewayAttachmentId": "tgw-attach-0f0927767cEXAMPLE", "TransitGatewayConnectPeerId": "tgw-connect-peer-0666adbac4EXAMPLE", "State": "available", "CreationTime": "2021-10-13T03:35:17.000Z", "ConnectPeerConfiguration": { "TransitGatewayAddress": "10.0.0.234", "PeerAddress": "172.31.1.11", "InsideCidrBlocks": [ "169.254.6.0/29" ], "Protocol": "gre", "BgpConfigurations": [ { "TransitGatewayAsn": 64512, "PeerAsn": 64512, "TransitGatewayAddress": "169.254.6.2", "PeerAddress": "169.254.6.1", "BgpStatus": "down" }, { "TransitGatewayAsn": 64512, "PeerAsn": 64512, "TransitGatewayAddress": "169.254.6.3", "PeerAddress": "169.254.6.1", "BgpStatus": "down" } ] }, "Tags": [] } ] }

有关更多信息,请参阅《公交网关指南》中的公交网关 Connect 附件和 Transit Gateway Connect 对等体

以下代码示例演示如何使用 describe-transit-gateway-connects

AWS CLI

描述公交网关 Connect 附件

以下describe-transit-gateway-connects示例描述了指定的 Connect 附件。

aws ec2 describe-transit-gateway-connects \ --transit-gateway-attachment-ids tgw-attach-037012e5dcEXAMPLE

输出:

{ "TransitGatewayConnects": [ { "TransitGatewayAttachmentId": "tgw-attach-037012e5dcEXAMPLE", "TransportTransitGatewayAttachmentId": "tgw-attach-0a89069f57EXAMPLE", "TransitGatewayId": "tgw-02f776b1a7EXAMPLE", "State": "available", "CreationTime": "2021-03-09T19:59:17+00:00", "Options": { "Protocol": "gre" }, "Tags": [] } ] }

有关更多信息,请参阅《公交网关指南》中的公交网关 Connect 附件和 Transit Gateway Connect 对等体

以下代码示例演示如何使用 describe-transit-gateway-multicast-domains

AWS CLI

描述您的传输网关多播域

以下describe-transit-gateway-multicast-domains示例显示了您的所有传输网关组播域的详细信息。

aws ec2 describe-transit-gateway-multicast-domains

输出:

{ "TransitGatewayMulticastDomains": [ { "TransitGatewayMulticastDomainId": "tgw-mcast-domain-000fb24d04EXAMPLE", "TransitGatewayId": "tgw-0bf0bffefaEXAMPLE", "TransitGatewayMulticastDomainArn": "arn:aws:ec2:us-east-1:123456789012:transit-gateway-multicast-domain/tgw-mcast-domain-000fb24d04EXAMPLE", "OwnerId": "123456789012", "Options": { "Igmpv2Support": "disable", "StaticSourcesSupport": "enable", "AutoAcceptSharedAssociations": "disable" }, "State": "available", "CreationTime": "2019-12-10T18:32:50+00:00", "Tags": [ { "Key": "Name", "Value": "mc1" } ] } ] }

有关更多信息,请参阅《传输网关指南》中的管理多播域

以下代码示例演示如何使用 describe-transit-gateway-peering-attachments

AWS CLI

描述您的公交网关对等连接附件

以下describe-transit-gateway-peering-attachments示例显示了所有公交网关对等连接附件的详细信息。

aws ec2 describe-transit-gateway-peering-attachments

输出:

{ "TransitGatewayPeeringAttachments": [ { "TransitGatewayAttachmentId": "tgw-attach-4455667788aabbccd", "RequesterTgwInfo": { "TransitGatewayId": "tgw-123abc05e04123abc", "OwnerId": "123456789012", "Region": "us-west-2" }, "AccepterTgwInfo": { "TransitGatewayId": "tgw-11223344aabbcc112", "OwnerId": "123456789012", "Region": "us-east-2" }, "State": "pendingAcceptance", "CreationTime": "2019-12-09T11:38:05.000Z", "Tags": [] } ] }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 对等连接附件

以下代码示例演示如何使用 describe-transit-gateway-policy-tables

AWS CLI

描述传输网关策略表

以下describe-transit-gateway-policy-tables示例描述了指定的传输网关策略表。

aws ec2 describe-transit-gateway-policy-tables \ --transit-gateway-policy-table-ids tgw-ptb-0a16f134b78668a81

输出:

{ "TransitGatewayPolicyTables": [ { "TransitGatewayPolicyTableId": "tgw-ptb-0a16f134b78668a81", "TransitGatewayId": "tgw-067f8505c18f0bd6e", "State": "available", "CreationTime": "2023-11-28T16:36:43+00:00", "Tags": [] } ] }

有关更多信息,请参阅 T ransit Gatewa y 用户指南中的公交网关策略表

以下代码示例演示如何使用 describe-transit-gateway-route-tables

AWS CLI

描述您的公交网关路由表

以下describe-transit-gateway-route-tables示例显示您的公交网关路由表的详细信息。

aws ec2 describe-transit-gateway-route-tables

输出:

{ "TransitGatewayRouteTables": [ { "TransitGatewayRouteTableId": "tgw-rtb-0ca78a549EXAMPLE", "TransitGatewayId": "tgw-0bc994abffEXAMPLE", "State": "available", "DefaultAssociationRouteTable": true, "DefaultPropagationRouteTable": true, "CreationTime": "2018-11-28T14:24:49.000Z", "Tags": [] }, { "TransitGatewayRouteTableId": "tgw-rtb-0e8f48f148EXAMPLE", "TransitGatewayId": "tgw-0043d72bb4EXAMPLE", "State": "available", "DefaultAssociationRouteTable": true, "DefaultPropagationRouteTable": true, "CreationTime": "2018-11-28T14:24:00.000Z", "Tags": [] } ] }

有关更多信息,请参阅《公交网关指南》中的查看公交网关路由表

以下代码示例演示如何使用 describe-transit-gateway-vpc-attachments

AWS CLI

描述您的公交网关VPC附件

以下describe-transit-gateway-vpc-attachments示例显示您的公交网关VPC附件的详细信息。

aws ec2 describe-transit-gateway-vpc-attachments

输出:

{ "TransitGatewayVpcAttachments": [ { "TransitGatewayAttachmentId": "tgw-attach-0a08e88308EXAMPLE", "TransitGatewayId": "tgw-0043d72bb4EXAMPLE", "VpcId": "vpc-0f501f7ee8EXAMPLE", "VpcOwnerId": "111122223333", "State": "available", "SubnetIds": [ "subnet-045d586432EXAMPLE", "subnet-0a0ad478a6EXAMPLE" ], "CreationTime": "2019-02-13T11:04:02.000Z", "Options": { "DnsSupport": "enable", "Ipv6Support": "disable" }, "Tags": [ { "Key": "Name", "Value": "attachment name" } ] } ] }

有关更多信息,请参阅 T ransit Gateways 指南中的查看您的VPC附件

以下代码示例演示如何使用 describe-transit-gateways

AWS CLI

描述您的中转网关

以下describe-transit-gateways示例检索有关您的中转网关的详细信息。

aws ec2 describe-transit-gateways

输出:

{ "TransitGateways": [ { "TransitGatewayId": "tgw-0262a0e521EXAMPLE", "TransitGatewayArn": "arn:aws:ec2:us-east-2:111122223333:transit-gateway/tgw-0262a0e521EXAMPLE", "State": "available", "OwnerId": "111122223333", "Description": "MyTGW", "CreationTime": "2019-07-10T14:02:12.000Z", "Options": { "AmazonSideAsn": 64516, "AutoAcceptSharedAttachments": "enable", "DefaultRouteTableAssociation": "enable", "AssociationDefaultRouteTableId": "tgw-rtb-018774adf3EXAMPLE", "DefaultRouteTablePropagation": "enable", "PropagationDefaultRouteTableId": "tgw-rtb-018774adf3EXAMPLE", "VpnEcmpSupport": "enable", "DnsSupport": "enable" }, "Tags": [] }, { "TransitGatewayId": "tgw-0fb8421e2dEXAMPLE", "TransitGatewayArn": "arn:aws:ec2:us-east-2:111122223333:transit-gateway/tgw-0fb8421e2da853bf3", "State": "available", "OwnerId": "111122223333", "CreationTime": "2019-03-15T22:57:33.000Z", "Options": { "AmazonSideAsn": 65412, "AutoAcceptSharedAttachments": "disable", "DefaultRouteTableAssociation": "enable", "AssociationDefaultRouteTableId": "tgw-rtb-06a241a3d8EXAMPLE", "DefaultRouteTablePropagation": "enable", "PropagationDefaultRouteTableId": "tgw-rtb-06a241a3d8EXAMPLE", "VpnEcmpSupport": "enable", "DnsSupport": "enable" }, "Tags": [ { "Key": "Name", "Value": "TGW1" } ] } ] }

以下代码示例演示如何使用 describe-verified-access-endpoints

AWS CLI

描述已验证访问终端节点

以下delete-verified-access-endpoints示例描述了指定的已验证访问终端节点。

aws ec2 describe-verified-access-endpoints \ --verified-access-endpoint-ids vae-066fac616d4d546f2

输出:

{ "VerifiedAccessEndpoints": [ { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "VerifiedAccessGroupId": "vagr-0dbe967baf14b7235", "VerifiedAccessEndpointId": "vae-066fac616d4d546f2", "ApplicationDomain": "example.com", "EndpointType": "network-interface", "AttachmentType": "vpc", "DomainCertificateArn": "arn:aws:acm:us-east-2:123456789012:certificate/eb065ea0-26f9-4e75-a6ce-0a1a7EXAMPLE", "EndpointDomain": "my-ava-app.edge-00c3372d53b1540bb.vai-0ce000c0b7643abea.prod.verified-access.us-east-2.amazonaws.com", "SecurityGroupIds": [ "sg-004915970c4c8f13a" ], "NetworkInterfaceOptions": { "NetworkInterfaceId": "eni-0aec70418c8d87a0f", "Protocol": "https", "Port": 443 }, "Status": { "Code": "active" }, "Description": "", "CreationTime": "2023-08-25T20:54:43", "LastUpdatedTime": "2023-08-25T22:17:26", "Tags": [ { "Key": "Name", "Value": "my-va-endpoint" } ] } ] }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问终端节点

以下代码示例演示如何使用 describe-verified-access-groups

AWS CLI

描述已验证访问权限组

以下describe-verified-access-groups示例描述了指定的已验证访问权限组。

aws ec2 describe-verified-access-groups \ --verified-access-group-ids vagr-0dbe967baf14b7235

输出:

{ "VerifiedAccessGroups": [ { "VerifiedAccessGroupId": "vagr-0dbe967baf14b7235", "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "Description": "Testing Verified Access", "Owner": "123456789012", "VerifiedAccessGroupArn": "arn:aws:ec2:us-east-2:123456789012:verified-access-group/vagr-0dbe967baf14b7235", "CreationTime": "2023-08-25T19:55:19", "LastUpdatedTime": "2023-08-25T22:17:25", "Tags": [ { "Key": "Name", "Value": "my-va-group" } ] } ] }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问

以下代码示例演示如何使用 describe-verified-access-instance-logging-configurations

AWS CLI

描述已验证访问权限实例的日志配置

以下describe-verified-access-instance-logging-configurations示例描述了指定的 Verified Access 实例的日志配置。

aws ec2 describe-verified-access-instance-logging-configurations \ --verified-access-instance-ids vai-0ce000c0b7643abea

输出:

{ "LoggingConfigurations": [ { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "AccessLogs": { "S3": { "Enabled": false }, "CloudWatchLogs": { "Enabled": true, "DeliveryStatus": { "Code": "success" }, "LogGroup": "my-log-group" }, "KinesisDataFirehose": { "Enabled": false }, "LogVersion": "ocsf-1.0.0-rc.2", "IncludeTrustContext": false } } ] }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问日志

以下代码示例演示如何使用 describe-verified-access-instances

AWS CLI

描述已验证的访问权限实例

以下describe-verified-access-instances示例描述了指定的已验证访问实例。

aws ec2 describe-verified-access-instances \ --verified-access-instance-ids vai-0ce000c0b7643abea

输出:

{ "VerifiedAccessInstances": [ { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "Description": "Testing Verified Access", "VerifiedAccessTrustProviders": [ { "VerifiedAccessTrustProviderId": "vatp-0bb32de759a3e19e7", "TrustProviderType": "user", "UserTrustProviderType": "iam-identity-center" } ], "CreationTime": "2023-08-25T18:27:56", "LastUpdatedTime": "2023-08-25T19:03:32", "Tags": [ { "Key": "Name", "Value": "my-ava-instance" } ] } ] }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问实例

以下代码示例演示如何使用 describe-verified-access-trust-providers

AWS CLI

描述已验证访问信任提供商

以下describe-verified-access-trust-providers示例描述了指定的已验证访问信任提供商。

aws ec2 describe-verified-access-trust-providers \ --verified-access-trust-provider-ids vatp-0bb32de759a3e19e7

输出:

{ "VerifiedAccessTrustProviders": [ { "VerifiedAccessTrustProviderId": "vatp-0bb32de759a3e19e7", "Description": "Testing Verified Access", "TrustProviderType": "user", "UserTrustProviderType": "iam-identity-center", "PolicyReferenceName": "idc", "CreationTime": "2023-08-25T19:00:38", "LastUpdatedTime": "2023-08-25T19:03:32", "Tags": [ { "Key": "Name", "Value": "my-va-trust-provider" } ] } ] }

有关更多信息,请参阅《已验证访问用户指南》中的 “AWS 验证访问权限的信任提供商”。

以下代码示例演示如何使用 describe-volume-attribute

AWS CLI

描述音量属性

此示例命令描述带有 ID 的卷的autoEnableIo属性vol-049df61146c4d7901

命令:

aws ec2 describe-volume-attribute --volume-id vol-049df61146c4d7901 --attribute autoEnableIO

输出:

{ "AutoEnableIO": { "Value": false }, "VolumeId": "vol-049df61146c4d7901" }

以下代码示例演示如何使用 describe-volume-status

AWS CLI

描述单个卷的状态

此示例命令描述了卷的状态vol-1234567890abcdef0

命令:

aws ec2 describe-volume-status --volume-ids vol-1234567890abcdef0

输出:

{ "VolumeStatuses": [ { "VolumeStatus": { "Status": "ok", "Details": [ { "Status": "passed", "Name": "io-enabled" }, { "Status": "not-applicable", "Name": "io-performance" } ] }, "AvailabilityZone": "us-east-1a", "VolumeId": "vol-1234567890abcdef0", "Actions": [], "Events": [] } ] }

描述受损卷的状态

此示例命令描述了所有受损卷的状态。在此示例输出中,没有受损的音量。

命令:

aws ec2 describe-volume-status --filters Name=volume-status.status,Values=impaired

输出:

{ "VolumeStatuses": [] }

如果您的卷状态检查失败(状态为受损),请参阅 Amazon EC2 用户指南中的处理受损卷。

以下代码示例演示如何使用 describe-volumes-modifications

AWS CLI

描述卷的修改状态

以下describe-volumes-modifications示例描述了指定卷的卷修改状态。

aws ec2 describe-volumes-modifications \ --volume-ids vol-1234567890abcdef0

输出:

{ "VolumeModification": { "TargetSize": 150, "TargetVolumeType": "io1", "ModificationState": "optimizing", "VolumeId": " vol-1234567890abcdef0", "TargetIops": 100, "StartTime": "2019-05-17T11:27:19.000Z", "Progress": 70, "OriginalVolumeType": "io1", "OriginalIops": 100, "OriginalSize": 100 } }

以下代码示例演示如何使用 describe-volumes

AWS CLI

示例 1:描述卷

以下describe-volumes示例描述了当前区域中的指定卷。

aws ec2 describe-volumes \ --volume-ids vol-049df61146c4d7901 vol-1234567890abcdef0

输出:

{ "Volumes": [ { "AvailabilityZone": "us-east-1a", "Attachments": [ { "AttachTime": "2013-12-18T22:35:00.000Z", "InstanceId": "i-1234567890abcdef0", "VolumeId": "vol-049df61146c4d7901", "State": "attached", "DeleteOnTermination": true, "Device": "/dev/sda1" } ], "Encrypted": true, "KmsKeyId": "arn:aws:kms:us-east-2a:123456789012:key/8c5b2c63-b9bc-45a3-a87a-5513eEXAMPLE, "VolumeType": "gp2", "VolumeId": "vol-049df61146c4d7901", "State": "in-use", "Iops": 100, "SnapshotId": "snap-1234567890abcdef0", "CreateTime": "2019-12-18T22:35:00.084Z", "Size": 8 }, { "AvailabilityZone": "us-east-1a", "Attachments": [], "Encrypted": false, "VolumeType": "gp2", "VolumeId": "vol-1234567890abcdef0", "State": "available", "Iops": 300, "SnapshotId": "", "CreateTime": "2020-02-27T00:02:41.791Z", "Size": 100 } ] }

示例 2:描述连接到特定实例的卷

以下describe-volumes示例描述了所有既连接到指定实例又设置为在实例终止时删除的卷。

aws ec2 describe-volumes \ --region us-east-1 \ --filters Name=attachment.instance-id,Values=i-1234567890abcdef0 Name=attachment.delete-on-termination,Values=true

有关 describe-volumes 的输出示例,请参阅示例 1。

示例 3:描述特定可用区中的可用卷

以下describe-volumes示例描述了状态为available且位于指定可用区的所有卷。

aws ec2 describe-volumes \ --filters Name=status,Values=available Name=availability-zone,Values=us-east-1a

有关 describe-volumes 的输出示例,请参阅示例 1。

示例 4:根据标签描述卷

以下describe-volumes示例描述了所有具有标签键Name和以开头的值的卷Test。然后,使用仅显示标签和卷的查询对输出IDs进行过滤。

aws ec2 describe-volumes \ --filters Name=tag:Name,Values=Test* \ --query "Volumes[*].{ID:VolumeId,Tag:Tags}"

输出:

[ { "Tag": [ { "Value": "Test2", "Key": "Name" } ], "ID": "vol-1234567890abcdef0" }, { "Tag": [ { "Value": "Test1", "Key": "Name" } ], "ID": "vol-049df61146c4d7901" } ]

有关使用标签筛选条件的其他示例,请参阅 Amazon EC2 用户指南中的使用标签

以下代码示例演示如何使用 describe-vpc-attribute

AWS CLI

描述该 enableDnsSupport 属性

此示例描述了该enableDnsSupport属性。此属性表示是否为启用DNS分辨率VPC。如果此属性为true,则 Amazon DNS 服务器会将您的实例DNS的主机名解析为相应的 IP 地址;否则,不会。

命令:

aws ec2 describe-vpc-attribute --vpc-id vpc-a01106c2 --attribute enableDnsSupport

输出:

{ "VpcId": "vpc-a01106c2", "EnableDnsSupport": { "Value": true } }

描述该 enableDnsHostnames 属性

此示例描述了该enableDnsHostnames属性。此属性表示实例是否在VPC获取DNS主机名中启动。如果此属性为true,则中的实例会VPC获取DNS主机名;否则,它们不会。

命令:

aws ec2 describe-vpc-attribute --vpc-id vpc-a01106c2 --attribute enableDnsHostnames

输出:

{ "VpcId": "vpc-a01106c2", "EnableDnsHostnames": { "Value": true } }

以下代码示例演示如何使用 describe-vpc-classic-link-dns-support

AWS CLI

描述对您的 ClassicLink DNS支持 VPCs

此示例描述了您的所有人的 ClassicLink DNS支持状态VPCs。

命令:

aws ec2 describe-vpc-classic-link-dns-support

输出:

{ "Vpcs": [ { "VpcId": "vpc-88888888", "ClassicLinkDnsSupported": true }, { "VpcId": "vpc-1a2b3c4d", "ClassicLinkDnsSupported": false } ] }

以下代码示例演示如何使用 describe-vpc-classic-link

AWS CLI

描述您的 ClassicLink 状态 VPCs

此示例列出了 vpc- ClassicLink 88888888 的状态。

命令:

aws ec2 describe-vpc-classic-link --vpc-id vpc-88888888

输出:

{ "Vpcs": [ { "ClassicLinkEnabled": true, "VpcId": "vpc-88888888", "Tags": [ { "Value": "classiclinkvpc", "Key": "Name" } ] } ] }

此示例仅VPCs列出已启用 Classiclink 的选项(的筛选器值设置is-classic-link-enabledtrue)。

命令:

aws ec2 describe-vpc-classic-link --filter "Name=is-classic-link-enabled,Values=true"

以下代码示例演示如何使用 describe-vpc-endpoint-connection-notifications

AWS CLI

描述端点连接通知

以下describe-vpc-endpoint-connection-notifications示例描述了您的所有终端节点连接通知。

aws ec2 describe-vpc-endpoint-connection-notifications

输出:

{ "ConnectionNotificationSet": [ { "ConnectionNotificationState": "Enabled", "ConnectionNotificationType": "Topic", "ConnectionEvents": [ "Accept", "Reject", "Delete", "Connect" ], "ConnectionNotificationId": "vpce-nfn-04bcb952bc8af7abc", "ConnectionNotificationArn": "arn:aws:sns:us-east-1:123456789012:VpceNotification", "VpcEndpointId": "vpce-0324151a02f327123" } ] }

以下代码示例演示如何使用 describe-vpc-endpoint-connections

AWS CLI

描述VPC端点连接

此示例描述了与您的终端节点服务的接口端点连接,并筛选结果以显示终端节点PendingAcceptance

命令:

aws ec2 describe-vpc-endpoint-connections --filters Name=vpc-endpoint-state,Values=pendingAcceptance

输出:

{ "VpcEndpointConnections": [ { "VpcEndpointId": "vpce-0abed31004e618123", "ServiceId": "vpce-svc-0abced088d20def56", "CreationTimestamp": "2017-11-30T10:00:24.350Z", "VpcEndpointState": "pendingAcceptance", "VpcEndpointOwner": "123456789012" } ] }

以下代码示例演示如何使用 describe-vpc-endpoint-service-configurations

AWS CLI

描述终端节点服务配置

以下describe-vpc-endpoint-service-configurations示例描述了您的终端节点服务配置。

aws ec2 describe-vpc-endpoint-service-configurations

输出:

{ "ServiceConfigurations": [ { "ServiceType": [ { "ServiceType": "GatewayLoadBalancer" } ], "ServiceId": "vpce-svc-012d33a1c4321cabc", "ServiceName": "com.amazonaws.vpce.us-east-1.vpce-svc-012d33a1c4321cabc", "ServiceState": "Available", "AvailabilityZones": [ "us-east-1d" ], "AcceptanceRequired": false, "ManagesVpcEndpoints": false, "GatewayLoadBalancerArns": [ "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/gwy/GWLBService/123210844e429123" ], "Tags": [] }, { "ServiceType": [ { "ServiceType": "Interface" } ], "ServiceId": "vpce-svc-123cabc125efa123", "ServiceName": "com.amazonaws.vpce.us-east-1.vpce-svc-123cabc125efa123", "ServiceState": "Available", "AvailabilityZones": [ "us-east-1a" ], "AcceptanceRequired": true, "ManagesVpcEndpoints": false, "NetworkLoadBalancerArns": [ "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/NLBforService/1238753950b25123" ], "BaseEndpointDnsNames": [ "vpce-svc-123cabc125efa123.us-east-1.vpce.amazonaws.com" ], "PrivateDnsName": "example.com", "PrivateDnsNameConfiguration": { "State": "failed", "Type": "TXT", "Value": "vpce:qUAth3FdeABCApUiXabc", "Name": "_1d367jvbg34znqvyefrj" }, "Tags": [] } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的VPC终端节点服务

以下代码示例演示如何使用 describe-vpc-endpoint-service-permissions

AWS CLI

描述终端节点服务权限

此示例描述了指定终端节点服务的权限。

命令:

aws ec2 describe-vpc-endpoint-service-permissions --service-id vpce-svc-03d5ebb7d9579a2b3

输出:

{ "AllowedPrincipals": [ { "PrincipalType": "Account", "Principal": "arn:aws:iam::123456789012:root" } ] }

以下代码示例演示如何使用 describe-vpc-endpoint-services

AWS CLI

示例 1:描述所有VPC终端节点服务

以下 “describe-vpc-endpoint-services” 示例列出了某个 AWS 区域的所有VPC终端节点服务。

aws ec2 describe-vpc-endpoint-services

输出:

{ "ServiceDetails": [ { "ServiceType": [ { "ServiceType": "Gateway" } ], "AcceptanceRequired": false, "ServiceName": "com.amazonaws.us-east-1.dynamodb", "VpcEndpointPolicySupported": true, "Owner": "amazon", "AvailabilityZones": [ "us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d", "us-east-1e", "us-east-1f" ], "BaseEndpointDnsNames": [ "dynamodb.us-east-1.amazonaws.com" ] }, { "ServiceType": [ { "ServiceType": "Interface" } ], "PrivateDnsName": "ec2.us-east-1.amazonaws.com", "ServiceName": "com.amazonaws.us-east-1.ec2", "VpcEndpointPolicySupported": false, "Owner": "amazon", "AvailabilityZones": [ "us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d", "us-east-1e", "us-east-1f" ], "AcceptanceRequired": false, "BaseEndpointDnsNames": [ "ec2.us-east-1.vpce.amazonaws.com" ] }, { "ServiceType": [ { "ServiceType": "Interface" } ], "PrivateDnsName": "ssm.us-east-1.amazonaws.com", "ServiceName": "com.amazonaws.us-east-1.ssm", "VpcEndpointPolicySupported": true, "Owner": "amazon", "AvailabilityZones": [ "us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d", "us-east-1e" ], "AcceptanceRequired": false, "BaseEndpointDnsNames": [ "ssm.us-east-1.vpce.amazonaws.com" ] } ], "ServiceNames": [ "com.amazonaws.us-east-1.dynamodb", "com.amazonaws.us-east-1.ec2", "com.amazonaws.us-east-1.ec2messages", "com.amazonaws.us-east-1.elasticloadbalancing", "com.amazonaws.us-east-1.kinesis-streams", "com.amazonaws.us-east-1.s3", "com.amazonaws.us-east-1.ssm" ] }

有关更多信息,请参阅《用户指南》中的查看可用 AWS 服务名称 AWS PrivateLink。

示例 2:描述终端节点服务的详细信息

以下 “describe-vpc-endpoint-services” 示例列出了 Amazon S3 接口终端节点服务的详细信息

aws ec2 describe-vpc-endpoint-services \ --filter "Name=service-type,Values=Interface" Name=service-name,Values=com.amazonaws.us-east-1.s3

输出:

{ "ServiceDetails": [ { "ServiceName": "com.amazonaws.us-east-1.s3", "ServiceId": "vpce-svc-081d84efcdEXAMPLE", "ServiceType": [ { "ServiceType": "Interface" } ], "AvailabilityZones": [ "us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d", "us-east-1e", "us-east-1f" ], "Owner": "amazon", "BaseEndpointDnsNames": [ "s3.us-east-1.vpce.amazonaws.com" ], "VpcEndpointPolicySupported": true, "AcceptanceRequired": false, "ManagesVpcEndpoints": false, "Tags": [] } ], "ServiceNames": [ "com.amazonaws.us-east-1.s3" ] }

有关更多信息,请参阅《用户指南》中的查看可用 AWS 服务名称 AWS PrivateLink。

以下代码示例演示如何使用 describe-vpc-endpoints

AWS CLI

描述您的VPC终端节点

以下describe-vpc-endpoints示例显示了所有终VPC端节点的详细信息。

aws ec2 describe-vpc-endpoints

输出:

{ "VpcEndpoints": [ { "PolicyDocument": "{\"Version\":\"2008-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"*\",\"Resource\":\"*\"}]}", "VpcId": "vpc-aabb1122", "NetworkInterfaceIds": [], "SubnetIds": [], "PrivateDnsEnabled": true, "State": "available", "ServiceName": "com.amazonaws.us-east-1.dynamodb", "RouteTableIds": [ "rtb-3d560345" ], "Groups": [], "VpcEndpointId": "vpce-032a826a", "VpcEndpointType": "Gateway", "CreationTimestamp": "2017-09-05T20:41:28Z", "DnsEntries": [], "OwnerId": "123456789012" }, { "PolicyDocument": "{\n \"Statement\": [\n {\n \"Action\": \"*\", \n \"Effect\": \"Allow\", \n \"Principal\": \"*\", \n \"Resource\": \"*\"\n }\n ]\n}", "VpcId": "vpc-1a2b3c4d", "NetworkInterfaceIds": [ "eni-2ec2b084", "eni-1b4a65cf" ], "SubnetIds": [ "subnet-d6fcaa8d", "subnet-7b16de0c" ], "PrivateDnsEnabled": false, "State": "available", "ServiceName": "com.amazonaws.us-east-1.elasticloadbalancing", "RouteTableIds": [], "Groups": [ { "GroupName": "default", "GroupId": "sg-54e8bf31" } ], "VpcEndpointId": "vpce-0f89a33420c1931d7", "VpcEndpointType": "Interface", "CreationTimestamp": "2017-09-05T17:55:27.583Z", "DnsEntries": [ { "HostedZoneId": "Z7HUB22UULQXV", "DnsName": "vpce-0f89a33420c1931d7-bluzidnv.elasticloadbalancing.us-east-1.vpce.amazonaws.com" }, { "HostedZoneId": "Z7HUB22UULQXV", "DnsName": "vpce-0f89a33420c1931d7-bluzidnv-us-east-1b.elasticloadbalancing.us-east-1.vpce.amazonaws.com" }, { "HostedZoneId": "Z7HUB22UULQXV", "DnsName": "vpce-0f89a33420c1931d7-bluzidnv-us-east-1a.elasticloadbalancing.us-east-1.vpce.amazonaws.com" } ], "OwnerId": "123456789012" }, { "VpcEndpointId": "vpce-aabbaabbaabbaabba", "VpcEndpointType": "GatewayLoadBalancer", "VpcId": "vpc-111122223333aabbc", "ServiceName": "com.amazonaws.vpce.us-east-1.vpce-svc-123123a1c43abc123", "State": "available", "SubnetIds": [ "subnet-0011aabbcc2233445" ], "RequesterManaged": false, "NetworkInterfaceIds": [ "eni-01010120203030405" ], "CreationTimestamp": "2020-11-11T08:06:03.522Z", "Tags": [], "OwnerId": "123456789012" } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的VPC终端节点

以下代码示例演示如何使用 describe-vpc-peering-connections

AWS CLI

描述您的对VPC等连接

此示例描述了您的所有对VPC等连接。

命令:

aws ec2 describe-vpc-peering-connections

输出:

{ "VpcPeeringConnections": [ { "Status": { "Message": "Active", "Code": "active" }, "Tags": [ { "Value": "Peering-1", "Key": "Name" } ], "AccepterVpcInfo": { "OwnerId": "111122223333", "VpcId": "vpc-1a2b3c4d", "CidrBlock": "10.0.1.0/28" }, "VpcPeeringConnectionId": "pcx-11122233", "RequesterVpcInfo": { "PeeringOptions": { "AllowEgressFromLocalVpcToRemoteClassicLink": false, "AllowEgressFromLocalClassicLinkToRemoteVpc": false }, "OwnerId": "444455556666", "VpcId": "vpc-123abc45", "CidrBlock": "192.168.0.0/16" } }, { "Status": { "Message": "Pending Acceptance by 444455556666", "Code": "pending-acceptance" }, "Tags": [], "RequesterVpcInfo": { "PeeringOptions": { "AllowEgressFromLocalVpcToRemoteClassicLink": false, "AllowEgressFromLocalClassicLinkToRemoteVpc": false }, "OwnerId": "444455556666", "VpcId": "vpc-11aa22bb", "CidrBlock": "10.0.0.0/28" }, "VpcPeeringConnectionId": "pcx-abababab", "ExpirationTime": "2014-04-03T09:12:43.000Z", "AccepterVpcInfo": { "OwnerId": "444455556666", "VpcId": "vpc-33cc44dd" } } ] }

描述VPC特定的对等连接

此示例描述了所有处于 VPC “待接受” 状态的对等连接。

命令:

aws ec2 describe-vpc-peering-connections --filters Name=status-code,Values=pending-acceptance

此示例描述了所有VPC标有 Owner=Finance 标签的对等连接。

命令:

aws ec2 describe-vpc-peering-connections --filters Name=tag:Owner,Values=Finance

此示例描述了您为指定的 v VPC pc-1a2b3c4d 请求的所有对VPC等连接。

命令:

aws ec2 describe-vpc-peering-connections --filters Name=requester-vpc-info.vpc-id,Values=vpc-1a2b3c4d

以下代码示例演示如何使用 describe-vpcs

AWS CLI

示例 1:描述您的所有内容 VPCs

以下describe-vpcs示例检索有关您的VPCs详细信息。

aws ec2 describe-vpcs

输出:

{ "Vpcs": [ { "CidrBlock": "30.1.0.0/16", "DhcpOptionsId": "dopt-19edf471", "State": "available", "VpcId": "vpc-0e9801d129EXAMPLE", "OwnerId": "111122223333", "InstanceTenancy": "default", "CidrBlockAssociationSet": [ { "AssociationId": "vpc-cidr-assoc-062c64cfafEXAMPLE", "CidrBlock": "30.1.0.0/16", "CidrBlockState": { "State": "associated" } } ], "IsDefault": false, "Tags": [ { "Key": "Name", "Value": "Not Shared" } ] }, { "CidrBlock": "10.0.0.0/16", "DhcpOptionsId": "dopt-19edf471", "State": "available", "VpcId": "vpc-06e4ab6c6cEXAMPLE", "OwnerId": "222222222222", "InstanceTenancy": "default", "CidrBlockAssociationSet": [ { "AssociationId": "vpc-cidr-assoc-00b17b4eddEXAMPLE", "CidrBlock": "10.0.0.0/16", "CidrBlockState": { "State": "associated" } } ], "IsDefault": false, "Tags": [ { "Key": "Name", "Value": "Shared VPC" } ] } ] }

示例 2:描述指定的 VPC

以下describe-vpcs示例检索指定VPC项的详细信息。

aws ec2 describe-vpcs \ --vpc-ids vpc-06e4ab6c6cEXAMPLE

输出:

{ "Vpcs": [ { "CidrBlock": "10.0.0.0/16", "DhcpOptionsId": "dopt-19edf471", "State": "available", "VpcId": "vpc-06e4ab6c6cEXAMPLE", "OwnerId": "111122223333", "InstanceTenancy": "default", "CidrBlockAssociationSet": [ { "AssociationId": "vpc-cidr-assoc-00b17b4eddEXAMPLE", "CidrBlock": "10.0.0.0/16", "CidrBlockState": { "State": "associated" } } ], "IsDefault": false, "Tags": [ { "Key": "Name", "Value": "Shared VPC" } ] } ] }

以下代码示例演示如何使用 describe-vpn-connections

AWS CLI

示例 1:描述您的VPN连接

以下describe-vpn-connections示例描述了您的所有 Site-to-SiteVPN连接。

aws ec2 describe-vpn-connections

输出:

{ "VpnConnections": [ { "CustomerGatewayConfiguration": "...configuration information...", "CustomerGatewayId": "cgw-01234567abcde1234", "Category": "VPN", "State": "available", "Type": "ipsec.1", "VpnConnectionId": "vpn-1122334455aabbccd", "TransitGatewayId": "tgw-00112233445566aab", "Options": { "EnableAcceleration": false, "StaticRoutesOnly": true, "LocalIpv4NetworkCidr": "0.0.0.0/0", "RemoteIpv4NetworkCidr": "0.0.0.0/0", "TunnelInsideIpVersion": "ipv4" }, "Routes": [], "Tags": [ { "Key": "Name", "Value": "CanadaVPN" } ], "VgwTelemetry": [ { "AcceptedRouteCount": 0, "LastStatusChange": "2020-07-29T10:35:11.000Z", "OutsideIpAddress": "203.0.113.3", "Status": "DOWN", "StatusMessage": "" }, { "AcceptedRouteCount": 0, "LastStatusChange": "2020-09-02T09:09:33.000Z", "OutsideIpAddress": "203.0.113.5", "Status": "UP", "StatusMessage": "" } ] } ] }

有关更多信息,请参阅《AWS Site-to-Site VPN用户指南》中的 AWS Site-to-Site VPN工作原理

示例 2:描述您的可用VPN连接

以下describe-vpn-connections示例描述了状态为的 Site-to-SiteVPN连接available

aws ec2 describe-vpn-connections \ --filters "Name=state,Values=available"

有关更多信息,请参阅《AWS Site-to-Site VPN用户指南》中的 AWS Site-to-Site VPN工作原理

以下代码示例演示如何使用 describe-vpn-gateways

AWS CLI

描述您的虚拟专用网关

此示例描述您的虚拟专用网关。

命令:

aws ec2 describe-vpn-gateways

输出:

{ "VpnGateways": [ { "State": "available", "Type": "ipsec.1", "VpnGatewayId": "vgw-f211f09b", "VpcAttachments": [ { "State": "attached", "VpcId": "vpc-98eb5ef5" } ] }, { "State": "available", "Type": "ipsec.1", "VpnGatewayId": "vgw-9a4cacf3", "VpcAttachments": [ { "State": "attaching", "VpcId": "vpc-a01106c2" } ] } ] }

以下代码示例演示如何使用 detach-classic-link-vpc

AWS CLI

取消关联(分离)EC2-Classic 实例与 VPC

此示例取消了实例 i-0598c7d356eba48d7 与 vpc-88888888 的链接。VPC

命令:

aws ec2 detach-classic-link-vpc --instance-id i-0598c7d356eba48d7 --vpc-id vpc-88888888

输出:

{ "Return": true }

以下代码示例演示如何使用 detach-internet-gateway

AWS CLI

要断开互联网网关与您的连接 VPC

以下detach-internet-gateway示例将指定的互联网网关与特定VPC网关分离。

aws ec2 detach-internet-gateway \ --internet-gateway-id igw-0d0fb496b3EXAMPLE \ --vpc-id vpc-0a60eb65b4EXAMPLE

此命令不生成任何输出。

有关更多信息,请参阅 Amazon VPC 用户指南中的互联网网关

以下代码示例演示如何使用 detach-network-interface

AWS CLI

将网络接口与您的实例分离

此示例将指定的网络接口与指定实例分离。如果命令成功,则不返回任何输出。

命令:

aws ec2 detach-network-interface --attachment-id eni-attach-66c4350a

以下代码示例演示如何使用 detach-verified-access-trust-provider

AWS CLI

将信任提供者与实例分离

以下detach-verified-access-trust-provider示例将指定的已验证访问信任提供者与指定的已验证访问权限实例分离。

aws ec2 detach-verified-access-trust-provider \ --verified-access-instance-id vai-0ce000c0b7643abea \ --verified-access-trust-provider-id vatp-0bb32de759a3e19e7

输出:

{ "VerifiedAccessTrustProvider": { "VerifiedAccessTrustProviderId": "vatp-0bb32de759a3e19e7", "Description": "Testing Verified Access", "TrustProviderType": "user", "UserTrustProviderType": "iam-identity-center", "PolicyReferenceName": "idc", "CreationTime": "2023-08-25T19:00:38", "LastUpdatedTime": "2023-08-25T19:00:38" }, "VerifiedAccessInstance": { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "Description": "Testing Verified Access", "VerifiedAccessTrustProviders": [], "CreationTime": "2023-08-25T18:27:56", "LastUpdatedTime": "2023-08-25T18:27:56" } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问实例

以下代码示例演示如何使用 detach-volume

AWS CLI

将卷与实例分离

此示例命令将卷 (vol-049df61146c4d7901) 与其连接的实例分离。

命令:

aws ec2 detach-volume --volume-id vol-1234567890abcdef0

输出:

{ "AttachTime": "2014-02-27T19:23:06.000Z", "InstanceId": "i-1234567890abcdef0", "VolumeId": "vol-049df61146c4d7901", "State": "detaching", "Device": "/dev/sdb" }

以下代码示例演示如何使用 detach-vpn-gateway

AWS CLI

要将虚拟专用网关与您的网关分离 VPC

此示例将指定的虚拟专用网关与指定的虚拟专用网关分离。VPC如果命令成功,则不返回任何输出。

命令:

aws ec2 detach-vpn-gateway --vpn-gateway-id vgw-9a4cacf3 --vpc-id vpc-a01106c2

以下代码示例演示如何使用 disable-address-transfer

AWS CLI

禁用弹性 IP 地址传输

以下disable-address-transfer示例禁用了指定弹性 IP 地址的弹性 IP 地址传输。

aws ec2 disable-address-transfer \ --allocation-id eipalloc-09ad461b0d03f6aaf

输出:

{ "AddressTransfer": { "PublicIp": "100.21.184.216", "AllocationId": "eipalloc-09ad461b0d03f6aaf", "AddressTransferStatus": "disabled" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的传输弹性 IP 地址

以下代码示例演示如何使用 disable-aws-network-performance-metric-subscription

AWS CLI

禁用指标订阅

以下disable-aws-network-performance-metric-subscription示例禁用了对指定源区域和目标区域之间聚合网络延迟的监控。

aws ec2 disable-aws-network-performance-metric-subscription \ --source us-east-1 \ --destination eu-west-1 \ --metric aggregate-latency \ --statistic p50

输出:

{ "Output": true }

有关更多信息,请参阅《基础架构性能用户指南》中的管理订阅

以下代码示例演示如何使用 disable-ebs-encryption-by-default

AWS CLI

默认情况下禁用EBS加密

以下disable-ebs-encryption-by-default示例默认禁用当前区域中您的 AWS 账户的EBS加密。

aws ec2 disable-ebs-encryption-by-default

输出:

{ "EbsEncryptionByDefault": false }

以下代码示例演示如何使用 disable-fast-launch

AWS CLI

停止快速启动图像

以下disable-fast-launch示例停止在指定的快照上快速启动AMI,并清理现有的预配置快照。

aws ec2 disable-fast-launch \ --image-id ami-01234567890abcedf

输出:

{ "ImageId": "ami-01234567890abcedf", "ResourceType": "snapshot", "SnapshotConfiguration": {}, "LaunchTemplate": { "LaunchTemplateId": "lt-01234567890abcedf", "LaunchTemplateName": "EC2FastLaunchDefaultResourceCreation-a8c6215d-94e6-441b-9272-dbd1f87b07e2", "Version": "1" }, "MaxParallelLaunches": 6, "OwnerId": "0123456789123", "State": "disabling", "StateTransitionReason": "Client.UserInitiated", "StateTransitionTime": "2022-01-27T22:47:29.265000+00:00" }

有关配置 Windows 以加快启动速度AMI的更多信息,请参阅 Amazon EC2 用户指南中的配置您的AMI以加快启动速度

以下代码示例演示如何使用 disable-fast-snapshot-restores

AWS CLI

禁用快速快照恢复

以下disable-fast-snapshot-restores示例禁用指定可用区中指定快照的快速快照恢复。

aws ec2 disable-fast-snapshot-restores \ --availability-zones us-east-2a \ --source-snapshot-ids snap-1234567890abcdef0

输出:

{ "Successful": [ { "SnapshotId": "snap-1234567890abcdef0" "AvailabilityZone": "us-east-2a", "State": "disabling", "StateTransitionReason": "Client.UserInitiated", "OwnerId": "123456789012", "EnablingTime": "2020-01-25T23:57:49.602Z" } ], "Unsuccessful": [] }

以下代码示例演示如何使用 disable-image-block-public-access

AWS CLI

在指定区域禁用封锁公共访问权限 AMIs

以下disable-image-block-public-access示例AMIs在指定区域的账户级别禁用封锁公共访问权限。

aws ec2 disable-image-block-public-access \ --region us-east-1

输出:

{ "ImageBlockPublicAccessState": "unblocked" }

有关更多信息,请参阅《Amazon EC2 用户指南》AMIs中的阻止公众访问您的。

以下代码示例演示如何使用 disable-image-deprecation

AWS CLI

取消弃用 AMI

以下disable-image-deprecation示例取消了对的弃用AMI,从而将该DeprecationTime字段从输出中删除。describe-images您必须是AMI所有者才能执行此过程。

aws ec2 disable-image-deprecation \ --image-id ami-1234567890abcdef0

输出:

{ "RequestID": "11aabb229-4eac-35bd-99ed-be587EXAMPLE", "Return": "true" }

有关更多信息,请参阅亚马逊EC2用户指南中的弃用 AMI <https://docs.aws.amazon.com/AWS EC2/latest/UserGuide/ami-deprecate.html #deprecate-ami>。

以下代码示例演示如何使用 disable-image

AWS CLI

要禁用 AMI

以下disable-image示例禁用了指定AMI的。

aws ec2 disable-image \ --image-id ami-1234567890abcdef0

输出:

{ "Return": "true" }

有关更多信息,请参阅 Amazon EC2 用户指南AMI中的禁用

以下代码示例演示如何使用 disable-ipam-organization-admin-account

AWS CLI

禁用委派的IPAM管理员

在某些情况下,您将IPAM与 Organizations AWS 集成。当你这样做时,Organizati AWS ons 管理账户会委托一个 Or AWS ganizations 成员账户作为IPAM管理员。

在此示例中,您是委托IPAM管理员帐户的 Organizations 管理账户,并且您想禁止该账户成为IPAM管理员。 AWS

在提出此请求--region时,您可以使用任何 AWS 区域。您不必使用最初委派管理员的区域、创建管理员的地区,也不必使用IPAM操作区域。IPAM如果您禁用了委托管理员帐户,则可以随时将其重新启用或委托新帐户为IPAM管理员。

以下disable-ipam-organization-admin-account示例禁用您 AWS 账户中的委托IPAM管理员。

aws ec2 disable-ipam-organization-admin-account \ --delegated-admin-account-id 320805250157 \ --region ap-south-1

输出:

{ "Success": true }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的IPAM与 AWS 组织中的账户集成

以下代码示例演示如何使用 disable-serial-console-access

AWS CLI

为您的账户禁用对EC2串行控制台的访问权限

以下disable-serial-console-access示例禁用了对串行控制台的账户访问权限。

aws ec2 disable-serial-console-access

输出:

{ "SerialConsoleAccessEnabled": false }

有关更多信息,请参阅 Amazon EC2 用户指南中的EC2串行控制台

以下代码示例演示如何使用 disable-snapshot-block-public-access

AWS CLI

禁用对快照的封锁公共访问权限

以下disable-snapshot-block-public-access示例禁止对快照进行公开访问以允许公开共享您的快照。

aws ec2 disable-snapshot-block-public-access

输出:

{ "State": "unblocked" }

有关更多信息,请参阅 Amazon EBS 用户指南中的阻止对快照的公开访问

以下代码示例演示如何使用 disable-transit-gateway-route-table-propagation

AWS CLI

禁用传输网关连接以将路由传播到指定的传播路由表

以下disable-transit-gateway-route-table-propagation示例禁止指定连接将路由传播到指定传播路由表。

aws ec2 disable-transit-gateway-route-table-propagation \ --transit-gateway-route-table-id tgw-rtb-0a823edbdeEXAMPLE \ --transit-gateway-attachment-id tgw-attach-09b52ccdb5EXAMPLE

输出:

{ "Propagation": { "TransitGatewayAttachmentId": "tgw-attach-09b52ccdb5EXAMPLE", "ResourceId": "vpc-4d7de228", "ResourceType": "vpc", "TransitGatewayRouteTableId": "tgw-rtb-0a823edbdeEXAMPLE", "State": "disabled" } }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 路由表

以下代码示例演示如何使用 disable-vgw-route-propagation

AWS CLI

禁用路由传播

此示例禁止指定的虚拟专用网关向指定路由表传播静态路由。如果命令成功,则不返回任何输出。

命令:

aws ec2 disable-vgw-route-propagation --route-table-id rtb-22574640 --gateway-id vgw-9a4cacf3

以下代码示例演示如何使用 disable-vpc-classic-link-dns-support

AWS CLI

禁用对的 ClassicLink DNS支持 VPC

此示例禁用了对的 ClassicLink DNS支持。vpc-88888888

命令:

aws ec2 disable-vpc-classic-link-dns-support --vpc-id vpc-88888888

输出:

{ "Return": true }

以下代码示例演示如何使用 disable-vpc-classic-link

AWS CLI

要为 a 禁 ClassicLink 用 VPC

此示例 ClassicLink 对于 vpc-8888888 禁用。

命令:

aws ec2 disable-vpc-classic-link --vpc-id vpc-88888888

输出:

{ "Return": true }

以下代码示例演示如何使用 disassociate-address

AWS CLI

在-Classic 中取消弹性 IP 地址的EC2关联

此示例在 EC2-Classic 中取消弹性 IP 地址与实例的关联。如果命令成功,则不返回任何输出。

命令:

aws ec2 disassociate-address --public-ip 198.51.100.0

要取消与弹性 IP 地址的EC2关联-VPC

此示例取消弹性 IP 地址与中实例的关联。VPC如果命令成功,则不返回任何输出。

命令:

aws ec2 disassociate-address --association-id eipassoc-2bebb745

以下代码示例演示如何使用 disassociate-client-vpn-target-network

AWS CLI

取消网络与客户端VPN终端节点的关联

以下disassociate-client-vpn-target-network示例取消与指定客户端VPN终端节点的关cvpn-assoc-12312312312312312联 ID 关联的目标网络。

aws ec2 disassociate-client-vpn-target-network \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde \ --association-id cvpn-assoc-12312312312312312

输出:

{ "AssociationId": "cvpn-assoc-12312312312312312", "Status": { "Code": "disassociating" } }

有关更多信息,请参阅《AWS 客户机VPN管理员指南》中的 “目标网络”。

以下代码示例演示如何使用 disassociate-iam-instance-profile

AWS CLI

取消关联IAM实例配置文件

此示例取消IAM实例配置文件与关联 ID 的关联。iip-assoc-05020b59952902f5f

命令:

aws ec2 disassociate-iam-instance-profile --association-id iip-assoc-05020b59952902f5f

输出:

{ "IamInstanceProfileAssociation": { "InstanceId": "i-123456789abcde123", "State": "disassociating", "AssociationId": "iip-assoc-05020b59952902f5f", "IamInstanceProfile": { "Id": "AIPAI5IVIHMFFYY2DKV5Y", "Arn": "arn:aws:iam::123456789012:instance-profile/admin-role" } } }

以下代码示例演示如何使用 disassociate-instance-event-window

AWS CLI

示例 1:取消一个或多个实例与事件窗口的关联

以下disassociate-instance-event-window示例取消一个或多个实例与事件窗口的关联。指定instance-event-window-id参数以指定事件窗口。要取消关联实例,请指定association-target参数,对于参数值,请指定一个或多个实例IDs。

aws ec2 disassociate-instance-event-window \ --region us-east-1 \ --instance-event-window-id iew-0abcdef1234567890 \ --association-target "InstanceIds=i-1234567890abcdef0,i-0598c7d356eba48d7"

输出:

{ "InstanceEventWindow": { "InstanceEventWindowId": "iew-0abcdef1234567890", "Name": "myEventWindowName", "CronExpression": "* 21-23 * * 2,3", "AssociationTarget": { "InstanceIds": [], "Tags": [], "DedicatedHostIds": [] }, "State": "creating" } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

示例 2:取消实例标签与事件窗口的关联

以下disassociate-instance-event-window示例取消实例标签与事件窗口的关联。指定instance-event-window-id参数以指定事件窗口。要取消关联实例标签,请指定 association-target 参数,并为参数值指定一个或多个标签。

aws ec2 disassociate-instance-event-window \ --region us-east-1 \ --instance-event-window-id iew-0abcdef1234567890 \ --association-target "InstanceTags=[{Key=k2,Value=v2},{Key=k1,Value=v1}]"

输出:

{ "InstanceEventWindow": { "InstanceEventWindowId": "iew-0abcdef1234567890", "Name": "myEventWindowName", "CronExpression": "* 21-23 * * 2,3", "AssociationTarget": { "InstanceIds": [], "Tags": [], "DedicatedHostIds": [] }, "State": "creating" } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

示例 3:取消专用主机与事件窗口的关联

以下disassociate-instance-event-window示例取消专用主机与事件窗口的关联。指定instance-event-window-id参数以指定事件窗口。要取消与专用主机的关联,请指定association-target参数,对于参数值,请指定一个或多个专用主机IDs。

aws ec2 disassociate-instance-event-window \ --region us-east-1 \ --instance-event-window-id iew-0abcdef1234567890 \ --association-target DedicatedHostIds=h-029fa35a02b99801d

输出:

{ "InstanceEventWindow": { "InstanceEventWindowId": "iew-0abcdef1234567890", "Name": "myEventWindowName", "CronExpression": "* 21-23 * * 2,3", "AssociationTarget": { "InstanceIds": [], "Tags": [], "DedicatedHostIds": [] }, "State": "creating" } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

以下代码示例演示如何使用 disassociate-ipam-resource-discovery

AWS CLI

取消资源发现与的关联 IPAM

在此示例中,您是IPAM委托管理员账户,想要取消IPAM资源发现与您的IPAM关联。你运行了 describe 命令"ResourceDiscoveryStatus": "not-found"并注意到你想解除它与你的关联,IPAM以便为其他关联腾出空间。

以下disassociate-ipam-resource-discovery示例取消关联您 AWS 账户中的IPAM资源发现。

aws ec2 disassociate-ipam-resource-discovery \ --ipam-resource-discovery-association-id ipam-res-disco-assoc-04382a6346357cf82 \ --region us-east-1

输出:

{ "IpamResourceDiscoveryAssociation": { "OwnerId": "320805250157", "IpamResourceDiscoveryAssociationId": "ipam-res-disco-assoc-04382a6346357cf82", "IpamResourceDiscoveryAssociationArn": "arn:aws:ec2::320805250157:ipam-resource-discovery-association/ipam-res-disco-assoc-04382a6346357cf82", "IpamResourceDiscoveryId": "ipam-res-disco-0365d2977fc1672fe", "IpamId": "ipam-005f921c17ebd5107", "IpamArn": "arn:aws:ec2::320805250157:ipam/ipam-005f921c17ebd5107", "IpamRegion": "us-east-1", "IsDefault": false, "ResourceDiscoveryStatus": "not-found", "State": "disassociate-in-progress" } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的IPAM与组织外部账户集成

以下代码示例演示如何使用 disassociate-nat-gateway-address

AWS CLI

取消弹性 IP 地址与公共NAT网关的关联

以下disassociate-nat-gateway-address示例取消指定弹性 IP 地址与指定公共NAT网关的关联。

aws ec2 disassociate-nat-gateway-address \ --nat-gateway-id nat-1234567890abcdef0 \ --association-ids eipassoc-0f96bdca17EXAMPLE

输出:

{ "NatGatewayId": "nat-1234567890abcdef0", "NatGatewayAddresses": [ { "AllocationId": "eipalloc-0be6ecac95EXAMPLE", "NetworkInterfaceId": "eni-09cc4b2558794f7f9", "PrivateIp": "10.0.0.74", "PublicIp": "3.211.231.218", "AssociationId": "eipassoc-0f96bdca17EXAMPLE", "IsPrimary": false, "Status": "disassociating" } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的NAT网关

以下代码示例演示如何使用 disassociate-route-table

AWS CLI

取消关联路由表

此示例取消指定路由表与指定子网的关联。如果命令成功,则不返回任何输出。

命令:

aws ec2 disassociate-route-table --association-id rtbassoc-781d0d1a

以下代码示例演示如何使用 disassociate-subnet-cidr-block

AWS CLI

取消IPv6CIDR区块与子网的关联

此示例使用IPv6CIDR区块的关联 ID 取消CIDR区块与子网的关联。

命令:

aws ec2 disassociate-subnet-cidr-block --association-id subnet-cidr-assoc-3aa54053

输出:

{ "SubnetId": "subnet-5f46ec3b", "Ipv6CidrBlockAssociation": { "Ipv6CidrBlock": "2001:db8:1234:1a00::/64", "AssociationId": "subnet-cidr-assoc-3aa54053", "Ipv6CidrBlockState": { "State": "disassociating" } } }

以下代码示例演示如何使用 disassociate-transit-gateway-multicast-domain

AWS CLI

取消子网与多播域的关联

以下disassociate-transit-gateway-multicast-domain示例取消子网与指定多播域的关联。

aws ec2 disassociate-transit-gateway-multicast-domain \ --transit-gateway-attachment-id tgw-attach-070e571cd1EXAMPLE \ --subnet-id subnet-000de86e3bEXAMPLE \ --transit-gateway-multicast-domain-id tgw-mcast-domain-0c4905cef7EXAMPLE

输出:

{ "Associations": { "TransitGatewayMulticastDomainId": "tgw-mcast-domain-0c4905cef7EXAMPLE", "TransitGatewayAttachmentId": "tgw-attach-070e571cd1EXAMPLE", "ResourceId": "vpc-7EXAMPLE", "ResourceType": "vpc", "Subnets": [ { "SubnetId": "subnet-000de86e3bEXAMPLE", "State": "disassociating" } ] } }

有关更多信息,请参阅《传输网关指南》中的 “使用组播”。

以下代码示例演示如何使用 disassociate-transit-gateway-route-table

AWS CLI

取消公交网关路由表与资源附件的关联

以下disassociate-transit-gateway-route-table示例取消指定附件与公交网关路由表的关联。

aws ec2 disassociate-transit-gateway-route-table \ --transit-gateway-route-table-id tgw-rtb-002573ed1eEXAMPLE \ --transit-gateway-attachment-id tgw-attach-08e0bc912cEXAMPLE

输出:

{ "Association": { "TransitGatewayRouteTableId": "tgw-rtb-002573ed1eEXAMPLE", "TransitGatewayAttachmentId": "tgw-attach-08e0bc912cEXAMPLE", "ResourceId": "11460968-4ac1-4fd3-bdb2-00599EXAMPLE", "ResourceType": "direct-connect-gateway", "State": "disassociating" } }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 路由表

以下代码示例演示如何使用 disassociate-vpc-cidr-block

AWS CLI

解除方块与IPv6CIDR区块的关联 VPC

此示例VPC使用IPv6CIDR区块的关联 ID 来解除区块与该CIDR区块的关联。

命令:

aws ec2 disassociate-vpc-cidr-block --association-id vpc-cidr-assoc-eca54085

输出:

{ "Ipv6CidrBlockAssociation": { "Ipv6CidrBlock": "2001:db8:1234:1a00::/56", "AssociationId": "vpc-cidr-assoc-eca54085", "Ipv6CidrBlockState": { "State": "disassociating" } }, "VpcId": "vpc-a034d6c4" }

解除方块与IPv4CIDR区块的关联 VPC

此示例将IPv4CIDR方块与 a VPC 断开关联。

命令:

aws ec2 disassociate-vpc-cidr-block --association-id vpc-cidr-assoc-0287ac6b

输出:

{ "CidrBlockAssociation": { "AssociationId": "vpc-cidr-assoc-0287ac6b", "CidrBlock": "172.18.0.0/16", "CidrBlockState": { "State": "disassociating" } }, "VpcId": "vpc-27621243" }

以下代码示例演示如何使用 enable-address-transfer

AWS CLI

启用弹性 IP 地址传输

以下enable-address-transfer示例启用了将指定弹性 IP 地址的弹性 IP 地址传输到指定账户。

aws ec2 enable-address-transfer \ --allocation-id eipalloc-09ad461b0d03f6aaf \ --transfer-account-id 123456789012

输出:

{ "AddressTransfer": { "PublicIp": "100.21.184.216", "AllocationId": "eipalloc-09ad461b0d03f6aaf", "TransferAccountId": "123456789012", "TransferOfferExpirationTimestamp": "2023-02-22T20:51:01.000Z", "AddressTransferStatus": "pending" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的传输弹性 IP 地址

以下代码示例演示如何使用 enable-aws-network-performance-metric-subscription

AWS CLI

启用指标订阅

以下enable-aws-network-performance-metric-subscription示例启用了对指定源区域和目标区域之间的聚合网络延迟的监控。

aws ec2 enable-aws-network-performance-metric-subscription \ --source us-east-1 \ --destination eu-west-1 \ --metric aggregate-latency \ --statistic p50

输出:

{ "Output": true }

有关更多信息,请参阅《基础架构性能用户指南》中的管理订阅

以下代码示例演示如何使用 enable-ebs-encryption-by-default

AWS CLI

要在默认情况下启用EBS加密

以下enable-ebs-encryption-by-default示例默认启用您当前区域中的 AWS 账户的EBS加密。

aws ec2 enable-ebs-encryption-by-default

输出:

{ "EbsEncryptionByDefault": true }

以下代码示例演示如何使用 enable-fast-launch

AWS CLI

开始快速启动图像

以下enable-fast-launch示例在指定的上开始快速启动,AMI并将要启动的最大并行实例数设置为 6。用于预置的资源类型设置AMI为snapshot,这也是默认值。

aws ec2 enable-fast-launch \ --image-id ami-01234567890abcedf \ --max-parallel-launches 6 \ --resource-type snapshot

输出:

{ "ImageId": "ami-01234567890abcedf", "ResourceType": "snapshot", "SnapshotConfiguration": { "TargetResourceCount": 10 }, "LaunchTemplate": {}, "MaxParallelLaunches": 6, "OwnerId": "0123456789123", "State": "enabling", "StateTransitionReason": "Client.UserInitiated", "StateTransitionTime": "2022-01-27T22:16:03.199000+00:00" }

有关配置 Windows 以加快启动速度AMI的更多信息,请参阅 Amazon EC2 用户指南中的配置您的AMI以加快启动速度

以下代码示例演示如何使用 enable-fast-snapshot-restores

AWS CLI

启用快速快照恢复

以下enable-fast-snapshot-restores示例为指定可用区中的指定快照启用快速快照恢复。

aws ec2 enable-fast-snapshot-restores \ --availability-zones us-east-2a us-east-2b \ --source-snapshot-ids snap-1234567890abcdef0

输出:

{ "Successful": [ { "SnapshotId": "snap-1234567890abcdef0" "AvailabilityZone": "us-east-2a", "State": "enabling", "StateTransitionReason": "Client.UserInitiated", "OwnerId": "123456789012", "EnablingTime": "2020-01-25T23:57:49.602Z" }, { "SnapshotId": "snap-1234567890abcdef0" "AvailabilityZone": "us-east-2b", "State": "enabling", "StateTransitionReason": "Client.UserInitiated", "OwnerId": "123456789012", "EnablingTime": "2020-01-25T23:57:49.596Z" } ], "Unsuccessful": [] }

以下代码示例演示如何使用 enable-image-block-public-access

AWS CLI

为指定区域启用封锁公共访问功能 AMIs

以下enable-image-block-public-access示例为AMIs指定区域的账户级别启用封锁公共访问权限。

aws ec2 enable-image-block-public-access \ --region us-east-1 \ --image-block-public-access-state block-new-sharing

输出:

{ "ImageBlockPublicAccessState": "block-new-sharing" }

有关更多信息,请参阅《Amazon EC2 用户指南》AMIs中的阻止公众访问您的。

以下代码示例演示如何使用 enable-image-deprecation

AWS CLI

示例 1:弃用 AMI

以下enable-image-deprecation示例在特定的日期和时间弃用了。AMI如果您为秒指定值,Amazon 会将秒EC2数四舍五入到最接近的分钟。您必须是AMI所有者才能执行此过程。

aws ec2 enable-image-deprecation \ --image-id ami-1234567890abcdef0 \ --deprecate-at "2022-10-15T13:17:12.000Z"

输出:

{ "RequestID": "59dbff89-35bd-4eac-99ed-be587EXAMPLE", "Return": "true" }

有关更多信息,请参阅亚马逊EC2用户指南中的弃用 AMI <https://docs.aws.amazon.com/AWS EC2/latest/UserGuide/ami-deprecate.html #deprecate-ami>。

以下代码示例演示如何使用 enable-image

AWS CLI

要启用 AMI

以下enable-image示例启用指定的AMI。

aws ec2 enable-image \ --image-id ami-1234567890abcdef0

输出:

{ "Return": "true" }

有关更多信息,请参阅 Amazon EC2 用户指南AMI中的禁用

以下代码示例演示如何使用 enable-ipam-organization-admin-account

AWS CLI

与 Organi AWS zations 集成并委托成员账户作为IPAM账户

以下enable-ipam-organization-admin-account示例IPAM与 Organiz AWS ations 集成,并委托一个成员账户作为IPAM账户。

aws ec2 enable-ipam-organization-admin-account \ --delegated-admin-account-id 320805250157

输出:

{ "Success": true }

有关更多信息,请参阅《亚马逊VPCIPAM用户指南》中的 “IPAM与 AWS 组织集成”。

以下代码示例演示如何使用 enable-reachability-analyzer-organization-sharing

AWS CLI

启用 Reachability Analyzer 的可信访问权限

以下enable-reachability-analyzer-organization-sharing示例为 Reachability Analyzer 启用可信访问。

aws ec2 enable-reachability-analyzer-organization-sharing

此命令不生成任何输出。

有关更多信息,请参阅 Reachability Analyzer 用户指南中的跨账户分析

以下代码示例演示如何使用 enable-serial-console-access

AWS CLI

为您的账户启用对串行控制台的访问权限

以下enable-serial-console-access示例启用了对串行控制台的账户访问权限。

aws ec2 enable-serial-console-access

输出:

{ "SerialConsoleAccessEnabled": true }

有关更多信息,请参阅 Amazon EC2 用户指南中的EC2串行控制台

以下代码示例演示如何使用 enable-snapshot-block-public-access

AWS CLI

启用对快照的封锁公共访问

以下enable-snapshot-block-public-access示例阻止所有公开共享您的快照。

aws ec2 enable-snapshot-block-public-access \ --state block-all-sharing

输出:

{ "State": "block-all-sharing" }

有关更多信息,请参阅 Amazon EBS 用户指南中的阻止对快照的公开访问

以下代码示例演示如何使用 enable-transit-gateway-route-table-propagation

AWS CLI

允许传输网关连接将路由传播到指定的传播路由表

以下enable-transit-gateway-route-table-propagation示例允许指定的连接将路由传播到指定的传播路由表。

aws ec2 enable-transit-gateway-route-table-propagation \ --transit-gateway-route-table-id tgw-rtb-0a823edbdeEXAMPLE \ --transit-gateway-attachment-id tgw-attach-09b52ccdb5EXAMPLE

输出:

{ "Propagation": { "TransitGatewayAttachmentId": "tgw-attach-09b52ccdb5EXAMPLE", "ResourceId": "vpc-4d7de228", "ResourceType": "vpc", "TransitGatewayRouteTableId": "tgw-rtb-0a823edbdeEXAMPLE", "State": "disabled" } }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 路由表

以下代码示例演示如何使用 enable-vgw-route-propagation

AWS CLI

启用路由传播

此示例允许指定的虚拟专用网关将静态路由传播到指定的路由表。如果命令成功,则不返回任何输出。

命令:

aws ec2 enable-vgw-route-propagation --route-table-id rtb-22574640 --gateway-id vgw-9a4cacf3

以下代码示例演示如何使用 enable-volume-io

AWS CLI

为卷启用 I/O

此示例在卷上启用 I/O vol-1234567890abcdef0

命令:

aws ec2 enable-volume-io --volume-id vol-1234567890abcdef0

输出:

{ "Return": true }

以下代码示例演示如何使用 enable-vpc-classic-link-dns-support

AWS CLI

启用对的 ClassicLink DNS支持 VPC

此示例启用了对的 ClassicLink DNS支持vpc-88888888

命令:

aws ec2 enable-vpc-classic-link-dns-support --vpc-id vpc-88888888

输出:

{ "Return": true }

以下代码示例演示如何使用 enable-vpc-classic-link

AWS CLI

启用 fo VPC r ClassicLink

此示例为启用了 vpc-8888888。 ClassicLink

命令:

aws ec2 enable-vpc-classic-link --vpc-id vpc-88888888

输出:

{ "Return": true }

以下代码示例演示如何使用 export-client-vpn-client-certificate-revocation-list

AWS CLI

导出客户证书吊销列表

以下export-client-vpn-client-certificate-revocation-list示例导出指定客户端VPN终端节点的客户端证书吊销列表。在此示例中,为了便于阅读,输出以文本格式返回。

aws ec2 export-client-vpn-client-certificate-revocation-list \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde \ --output text

输出:

-----BEGIN X509 CRL----- MIICiTCCAfICCQD6m7oRw0uXOjANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6 b24xFDASBgNVBAsTC0lBTSBDb25zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAd BgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jb20wHhcNMTEwNDI1MjA0NTIxWhcN MTIwNDI0MjA0NTIxWjCBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAwDgYD VQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDASBgNVBAsTC0lBTSBDb25z b2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAdBgkqhkiG9w0BCQEWEG5vb25lQGFt YXpvbi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMaK0dn+a4GmWIWJ 21uUSfwfEvySWtC2XADZ4nB+BLYgVIk60CpiwsZ3G93vUEIO3IyNoH/f0wYK8m9T rDHudUZg3qX4waLG5M43q7Wgc/MbQITxOUSQv7c7ugFFDzQGBzZswY6786m86gpE Ibb3OhjZnzcvQAaRHhdlQWIMm2nrAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAtCu4 nUhVVxYUntneD9+h8Mg9q6q+auNKyExzyLwaxlAoo7TJHidbtS4J5iNmZgXL0Fkb FFBjvSfpJIlJ00zbhNYS5f6GuoEDmFJl0ZxBHjJnyp378OD8uTs7fLvjx79LjSTb NYiytVbZPQUQ5Yaxu2jXnimvw3rrszlaEXAMPLE= -----END X509 CRL----- STATUS pending

有关更多信息,请参阅《客户机VPN管理员指南》中的 “AWS 客户证书吊销列表”。

以下代码示例演示如何使用 export-client-vpn-client-configuration

AWS CLI

导出客户机配置

以下export-client-vpn-client-configuration示例导出指定客户端VPN终端节点的客户端配置。在此示例中,为了便于阅读,输出以文本格式返回。

aws ec2 export-client-vpn-client-configuration \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde \ --output text

输出:

client dev tun proto udp remote cvpn-endpoint-123456789123abcde.prod.clientvpn.ap-south-1.amazonaws.com 443 remote-random-hostname resolv-retry infinite nobind persist-key persist-tun remote-cert-tls server cipher AES-256-GCM verb 3 <ca> -----BEGIN CERTIFICATE----- MIICiTCCAfICCQD6m7oRw0uXOjANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMC VVMxCzAJBgNVBAgTAldBMRAwDgYDVQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6 b24xFDASBgNVBAsTC0lBTSBDb25zb2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAd BgkqhkiG9w0BCQEWEG5vb25lQGFtYXpvbi5jb20wHhcNMTEwNDI1MjA0NTIxWhcN MTIwNDI0MjA0NTIxWjCBiDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAldBMRAwDgYD VQQHEwdTZWF0dGxlMQ8wDQYDVQQKEwZBbWF6b24xFDASBgNVBAsTC0lBTSBDb25z b2xlMRIwEAYDVQQDEwlUZXN0Q2lsYWMxHzAdBgkqhkiG9w0BCQEWEG5vb25lQGFt YXpvbi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMaK0dn+a4GmWIWJ 21uUSfwfEvySWtC2XADZ4nB+BLYgVIk60CpiwsZ3G93vUEIO3IyNoH/f0wYK8m9T rDHudUZg3qX4waLG5M43q7Wgc/MbQITxOUSQv7c7ugFFDzQGBzZswY6786m86gpE Ibb3OhjZnzcvQAaRHhdlQWIMm2nrAgMBAAEwDQYJKoZIhvcNAQEFBQADgYEAtCu4 nUhVVxYUntneD9+h8Mg9q6q+auNKyExzyLwaxlAoo7TJHidbtS4J5iNmZgXL0Fkb FFBjvSfpJIlJ00zbhNYS5f6GuoEDmFJl0ZxBHjJnyp378OD8uTs7fLvjx79LjSTb NYiytVbZPQUQ5Yaxu2jXnimvw3rrszlaEXAMPLE= -----END CERTIFICATE----- </ca> reneg-sec 0

有关更多信息,请参阅《客户机VPN管理员指南》中的AWS 客户端VPN端点

以下代码示例演示如何使用 export-image

AWS CLI

从中导出虚拟机 AMI

以下export-image示例以指定格式将指定的内容导出AMI到指定的存储桶。

aws ec2 export-image \ --image-id ami-1234567890abcdef0 \ --disk-image-format VMDK \ --s3-export-location S3Bucket=my-export-bucket,S3Prefix=exports/

输出:

{ "DiskImageFormat": "vmdk", "ExportImageTaskId": "export-ami-1234567890abcdef0" "ImageId": "ami-1234567890abcdef0", "RoleName": "vmimport", "Progress": "0", "S3ExportLocation": { "S3Bucket": "my-export-bucket", "S3Prefix": "exports/" }, "Status": "active", "StatusMessage": "validating" }

以下代码示例演示如何使用 get-associated-ipv6-pool-cidrs

AWS CLI

获取IPv6地址池的关联

以下get-associated-ipv6-pool-cidrs示例获取指定IPv6地址池的关联。

aws ec2 get-associated-ipv6-pool-cidrs \ --pool-id ipv6pool-ec2-012345abc12345abc

输出:

{ "Ipv6CidrAssociations": [ { "Ipv6Cidr": "2001:db8:1234:1a00::/56", "AssociatedResource": "vpc-111111222222333ab" } ] }
  • 有关API详细信息,请参阅PoolCidrs《AWS CLI 命令参考》中的 GetAssociatedIpv6

以下代码示例演示如何使用 get-aws-network-performance-data

AWS CLI

获取网络性能数据

以下get-aws-network-performance-data示例检索指定时间段内指定区域之间的网络性能数据。

aws ec2 get-aws-network-performance-data \ --start-time 2022-10-26T12:00:00.000Z \ --end-time 2022-10-26T12:30:00.000Z \ --data-queries Id=my-query,Source=us-east-1,Destination=eu-west-1,Metric=aggregate-latency,Statistic=p50,Period=five-minutes

输出:

{ "DataResponses": [ { "Id": "my-query", "Source": "us-east-1", "Destination": "eu-west-1", "Metric": "aggregate-latency", "Statistic": "p50", "Period": "five-minutes", "MetricPoints": [ { "StartDate": "2022-10-26T12:00:00+00:00", "EndDate": "2022-10-26T12:05:00+00:00", "Value": 62.44349, "Status": "OK" }, { "StartDate": "2022-10-26T12:05:00+00:00", "EndDate": "2022-10-26T12:10:00+00:00", "Value": 62.483498, "Status": "OK" }, { "StartDate": "2022-10-26T12:10:00+00:00", "EndDate": "2022-10-26T12:15:00+00:00", "Value": 62.51248, "Status": "OK" }, { "StartDate": "2022-10-26T12:15:00+00:00", "EndDate": "2022-10-26T12:20:00+00:00", "Value": 62.635475, "Status": "OK" }, { "StartDate": "2022-10-26T12:20:00+00:00", "EndDate": "2022-10-26T12:25:00+00:00", "Value": 62.733974, "Status": "OK" }, { "StartDate": "2022-10-26T12:25:00+00:00", "EndDate": "2022-10-26T12:30:00+00:00", "Value": 62.773975, "Status": "OK" }, { "StartDate": "2022-10-26T12:30:00+00:00", "EndDate": "2022-10-26T12:35:00+00:00", "Value": 62.75349, "Status": "OK" } ] } ] }

有关更多信息,请参阅《基础架构性能用户指南》中的监控网络性能

以下代码示例演示如何使用 get-capacity-reservation-usage

AWS CLI

查看各 AWS 账户的容量预留使用情况

以下get-capacity-reservation-usage示例显示了指定容量预留的使用信息。

aws ec2 get-capacity-reservation-usage \ --capacity-reservation-id cr-1234abcd56EXAMPLE

输出:

{ "CapacityReservationId": "cr-1234abcd56EXAMPLE ", "InstanceUsages": [ { "UsedInstanceCount": 1, "AccountId": "123456789012" } ], "AvailableInstanceCount": 4, "TotalInstanceCount": 5, "State": "active", "InstanceType": "t2.medium" }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的查看共享容量预留使用情况

以下代码示例演示如何使用 get-coip-pool-usage

AWS CLI

获取客户自有的 IP 地址池使用情况

以下get-coip-pool-usage示例获取指定客户拥有的 IP 地址池的使用详情。

aws ec2 get-coip-pool-usage \ --pool-id ipv4pool-coip-123a45678bEXAMPLE

输出:

{ "CoipPoolId": "ipv4pool-coip-123a45678bEXAMPLE", "CoipAddressUsages": [ { "CoIp": "0.0.0.0" }, { "AllocationId": "eipalloc-123ab45c6dEXAMPLE", "AwsAccountId": "123456789012", "CoIp": "0.0.0.0" }, { "AllocationId": "eipalloc-123ab45c6dEXAMPLE", "AwsAccountId": "123456789111", "CoIp": "0.0.0.0" } ], "LocalGatewayRouteTableId": "lgw-rtb-059615ef7dEXAMPLE" }

有关更多信息,请参阅《AWS Outposts 用户指南》中的客户拥有的 IP 地址

以下代码示例演示如何使用 get-console-output

AWS CLI

示例 1:获取控制台输出

以下get-console-output示例获取指定 Linux 实例的控制台输出。

aws ec2 get-console-output \ --instance-id i-1234567890abcdef0

输出:

{ "InstanceId": "i-1234567890abcdef0", "Timestamp": "2013-07-25T21:23:53.000Z", "Output": "..." }

有关更多信息,请参阅 Amazon EC2 用户指南中的实例控制台输出

示例 2:获取最新的控制台输出

以下get-console-output示例获取指定 Linux 实例的最新控制台输出。

aws ec2 get-console-output \ --instance-id i-1234567890abcdef0 \ --latest \ --output text

输出:

i-1234567890abcdef0 [ 0.000000] Command line: root=LABEL=/ console=tty1 console=ttyS0 selinux=0 nvme_core.io_timeout=4294967295 [ 0.000000] x86/fpu: Supporting XSAVE feature 0x001: 'x87 floating point registers' [ 0.000000] x86/fpu: Supporting XSAVE feature 0x002: 'SSE registers' [ 0.000000] x86/fpu: Supporting XSAVE feature 0x004: 'AVX registers' ... Cloud-init v. 0.7.6 finished at Wed, 09 May 2018 19:01:13 +0000. Datasource DataSourceEc2. Up 21.50 seconds Amazon Linux AMI release 2018.03 Kernel 4.14.26-46.32.amzn1.x

有关更多信息,请参阅 Amazon EC2 用户指南中的实例控制台输出

以下代码示例演示如何使用 get-console-screenshot

AWS CLI

检索正在运行的实例的屏幕截图

以下get-console-screenshot示例以.jpg 格式检索指定实例的屏幕截图。屏幕截图以 Base64 编码的字符串形式返回。

aws ec2 get-console-screenshot \ --instance-id i-1234567890abcdef0

输出:

{ "ImageData": "997987/8kgj49ikjhewkwwe0008084EXAMPLE", "InstanceId": "i-1234567890abcdef0" }

以下代码示例演示如何使用 get-default-credit-specification

AWS CLI

描述默认积分选项

以下get-default-credit-specification示例描述了 T2 实例的默认积分选项。

aws ec2 get-default-credit-specification \ --instance-family t2

输出:

{ "InstanceFamilyCreditSpecification": { "InstanceFamily": "t2", "CpuCredits": "standard" } }

以下代码示例演示如何使用 get-ebs-default-kms-key-id

AWS CLI

描述您的默认CMKEBS加密方式

以下get-ebs-default-kms-key-id示例描述了您的 AWS 账户CMK的默认EBS加密方式。

aws ec2 get-ebs-default-kms-key-id

输出显示EBS加密CMK的默认值,即使用别名CMK进行 AWS 托管alias/aws/ebs

{ "KmsKeyId": "alias/aws/ebs" }

以下输出显示了CMK用于EBS加密的自定义内容。

{ "KmsKeyId": "arn:aws:kms:us-west-2:123456789012:key/0ea3fef3-80a7-4778-9d8c-1c0c6EXAMPLE" }

以下代码示例演示如何使用 get-ebs-encryption-by-default

AWS CLI

描述默认情况下是否启用EBS加密

以下get-ebs-encryption-by-default示例说明当前区域中您的 AWS 账户是否默认启用了EBS加密。

aws ec2 get-ebs-encryption-by-default

以下输出表明默认情况下EBS加密处于禁用状态。

{ "EbsEncryptionByDefault": false }

以下输出表明默认情况下EBS加密处于启用状态。

{ "EbsEncryptionByDefault": true }

以下代码示例演示如何使用 get-flow-logs-integration-template

AWS CLI

创建 CloudFormation 模板以自动将VPC流日志与 Amazon Athena 集成

以下get-flow-logs-integration-template示例创建了一个 CloudFormation 模板,用于自动将VPC流日志与 Amazon Athena 集成。

Linux:

aws ec2 get-flow-logs-integration-template \ --flow-log-id fl-1234567890abcdef0 \ --config-delivery-s3-destination-arn arn:aws:s3:::DOC-EXAMPLE-BUCKET \ --integrate-services AthenaIntegrations='[{IntegrationResultS3DestinationArn=arn:aws:s3:::DOC-EXAMPLE-BUCKET,PartitionLoadFrequency=none,PartitionStartDate=2021-07-21T00:40:00,PartitionEndDate=2021-07-21T00:42:00},{IntegrationResultS3DestinationArn=arn:aws:s3:::DOC-EXAMPLE-BUCKET,PartitionLoadFrequency=none,PartitionStartDate=2021-07-21T00:40:00,PartitionEndDate=2021-07-21T00:42:00}]'

Windows:

aws ec2 get-flow-logs-integration-template ^ --flow-log-id fl-1234567890abcdef0 ^ --config-delivery-s3-destination-arn arn:aws:s3:::DOC-EXAMPLE-BUCKET ^ --integrate-services AthenaIntegrations=[{IntegrationResultS3DestinationArn=arn:aws:s3:::DOC-EXAMPLE-BUCKET,PartitionLoadFrequency=none,PartitionStartDate=2021-07-21T00:40:00,PartitionEndDate=2021-07-21T00:42:00},{IntegrationResultS3DestinationArn=arn:aws:s3:::DOC-EXAMPLE-BUCKET,PartitionLoadFrequency=none,PartitionStartDate=2021-07-21T00:40:00,PartitionEndDate=2021-07-21T00:42:00}]

输出:

{ "Result": "https://DOC-EXAMPLE-BUCKET.s3.us-east-2.amazonaws.com/VPCFlowLogsIntegrationTemplate_fl-1234567890abcdef0_Wed%20Jul%2021%2000%3A57%3A56%20UTC%202021.yml" }

有关使用 CloudFormation 模板的信息,请参阅《AWS CloudFormation 用户指南》中的使用 AWS CloudFormation 模板

有关使用 Amazon Athena 和流日志的信息,请参阅亚马逊虚拟有云用户指南中的使用亚马逊 Athena 查询流日志。

以下代码示例演示如何使用 get-groups-for-capacity-reservation

AWS CLI

列出具有容量预留的资源组

以下get-groups-for-capacity-reservation示例列出了向其添加了指定容量预留的资源组。

aws ec2 get-groups-for-capacity-reservation \ --capacity-reservation-id cr-1234abcd56EXAMPLE

输出:

{ "CapacityReservationsGroup": [ { "GroupArn": "arn:aws:resource-groups:us-west-2:123456789012:group/my-resource-group", "OwnerId": "123456789012" } ] }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的使用容量预留

以下代码示例演示如何使用 get-host-reservation-purchase-preview

AWS CLI

获取专用主机预留的购买预览

此示例预览了您账户中指定专用主机的指定专用主机预留费用。

命令:

aws ec2 get-host-reservation-purchase-preview --offering-id hro-03f707bf363b6b324 --host-id-set h-013abcd2a00cbd123

输出:

{ "TotalHourlyPrice": "1.499", "Purchase": [ { "HourlyPrice": "1.499", "InstanceFamily": "m4", "PaymentOption": "NoUpfront", "HostIdSet": [ "h-013abcd2a00cbd123" ], "UpfrontPrice": "0.000", "Duration": 31536000 } ], "TotalUpfrontPrice": "0.000" }

以下代码示例演示如何使用 get-image-block-public-access-state

AWS CLI

获取指定区域的封锁公共访问状态 AMIs

以下get-image-block-public-access-state示例获取指定区域中账户AMIs级别的封锁公共访问状态。

aws ec2 get-image-block-public-access-state \ --region us-east-1

输出:

{ "ImageBlockPublicAccessState": "block-new-sharing" }

有关更多信息,请参阅《Amazon EC2 用户指南》AMIs中的阻止公众访问您的。

以下代码示例演示如何使用 get-instance-types-from-instance-requirements

AWS CLI

预览与指定属性匹配的实例类型

以下get-instance-types-from-instance-requirements示例首先生成一个列表,其中包含可以使用--generate-cli-skeleton参数指定的所有可能的属性,然后将列表保存到JSON文件中。然后,该JSON文件用于自定义属性以预览匹配的实例类型。

要生成所有可能的属性并将输出直接保存到JSON文件中,请使用以下命令。

aws ec2 get-instance-types-from-instance-requirements \ --region us-east-1 \ --generate-cli-skeleton input > attributes.json

输出:

{ "DryRun": true, "ArchitectureTypes": [ "x86_64_mac" ], "VirtualizationTypes": [ "paravirtual" ], "InstanceRequirements": { "VCpuCount": { "Min": 0, "Max": 0 }, "MemoryMiB": { "Min": 0, "Max": 0 }, "CpuManufacturers": [ "intel" ], "MemoryGiBPerVCpu": { "Min": 0.0, "Max": 0.0 }, "ExcludedInstanceTypes": [ "" ], "InstanceGenerations": [ "current" ], "SpotMaxPricePercentageOverLowestPrice": 0, "OnDemandMaxPricePercentageOverLowestPrice": 0, "BareMetal": "included", "BurstablePerformance": "excluded", "RequireHibernateSupport": true, "NetworkInterfaceCount": { "Min": 0, "Max": 0 }, "LocalStorage": "required", "LocalStorageTypes": [ "hdd" ], "TotalLocalStorageGB": { "Min": 0.0, "Max": 0.0 }, "BaselineEbsBandwidthMbps": { "Min": 0, "Max": 0 }, "AcceleratorTypes": [ "inference" ], "AcceleratorCount": { "Min": 0, "Max": 0 }, "AcceleratorManufacturers": [ "xilinx" ], "AcceleratorNames": [ "t4" ], "AcceleratorTotalMemoryMiB": { "Min": 0, "Max": 0 } }, "MaxResults": 0, "NextToken": "" }

配置 JSON 文件。您必须提供 ArchitectureTypesVirtualizationTypesVCpuCountMemoryMiB 的值。您可以省略其他属性。省略时,将使用默认值。有关每个属性及其默认值的描述,请参阅 get-instance-types-from-instance-requirements.html> https://docs.aws.amazon.com/cli/ latest/reference/ec2/get。instance-types-from-instance

预览具有中指定属性的实例类型attributes.json。使用--cli-input-json参数指定JSON文件的名称和路径。在以下请求中,输出格式化为表格。

aws ec2 get-instance-types-from-instance-requirements \ --cli-input-json file://attributes.json \ --output table

attributes.json 文件的内容:

{ "ArchitectureTypes": [ "x86_64" ], "VirtualizationTypes": [ "hvm" ], "InstanceRequirements": { "VCpuCount": { "Min": 4, "Max": 6 }, "MemoryMiB": { "Min": 2048 }, "InstanceGenerations": [ "current" ] } }

输出:

------------------------------------------ |GetInstanceTypesFromInstanceRequirements| +----------------------------------------+ || InstanceTypes || |+--------------------------------------+| || InstanceType || |+--------------------------------------+| || c4.xlarge || || c5.xlarge || || c5a.xlarge || || c5ad.xlarge || || c5d.xlarge || || c5n.xlarge || || d2.xlarge || ...

有关基于属性的实例类型选择的更多信息,请参阅 Amazon 用户指南中的基于属性的实例类型选择的工作原理。EC2

以下代码示例演示如何使用 get-instance-uefi-data

AWS CLI

从实例检索UEFI数据

以下get-instance-uefi-data示例从实例检索UEFI数据。如果输出为空,则实例不包含UEFI数据。

aws ec2 get-instance-uefi-data \ --instance-id i-0123456789example

输出:

{ "InstanceId": "i-0123456789example", "UefiData": "QU1aTlVFRkkf+uLXAAAAAHj5a7fZ9+3dBzxXb/. <snipped> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD4L/J/AODshho=" }

有关更多信息,请参阅 Amazon EC2 用户指南中的UEFI安全启动

以下代码示例演示如何使用 get-ipam-address-history

AWS CLI

要获取 a 的历史 CIDR

以下get-ipam-address-history示例获取 a 的历史记录CIDR。

(Linux):

aws ec2 get-ipam-address-history \ --cidr 10.0.0.0/16 \ --ipam-scope-id ipam-scope-02fc38cd4c48e7d38 \ --start-time 2021-12-08T01:00:00.000Z \ --end-time 2021-12-10T01:00:00.000Z

(视窗):

aws ec2 get-ipam-address-history ^ --cidr 10.0.0.0/16 ^ --ipam-scope-id ipam-scope-02fc38cd4c48e7d38 ^ --start-time 2021-12-08T01:00:00.000Z ^ --end-time 2021-12-10T01:00:00.000Z

输出:

{ "HistoryRecords": [ { "ResourceOwnerId": "123456789012", "ResourceRegion": "us-west-1", "ResourceType": "vpc", "ResourceId": "vpc-06cbefa9ee907e1c0", "ResourceCidr": "10.0.0.0/16", "ResourceName": "Demo", "ResourceComplianceStatus": "unmanaged", "ResourceOverlapStatus": "overlapping", "VpcId": "vpc-06cbefa9ee907e1c0", "SampledStartTime": "2021-12-08T19:54:57.675000+00:00" }, { "ResourceOwnerId": "123456789012", "ResourceRegion": "us-east-2", "ResourceType": "vpc", "ResourceId": "vpc-042702f474812c9ad", "ResourceCidr": "10.0.0.0/16", "ResourceName": "test", "ResourceComplianceStatus": "unmanaged", "ResourceOverlapStatus": "overlapping", "VpcId": "vpc-042702f474812c9ad", "SampledStartTime": "2021-12-08T19:54:59.019000+00:00" }, { "ResourceOwnerId": "123456789012", "ResourceRegion": "us-east-2", "ResourceType": "vpc", "ResourceId": "vpc-042b8a44f64267d67", "ResourceCidr": "10.0.0.0/16", "ResourceName": "tester", "ResourceComplianceStatus": "unmanaged", "ResourceOverlapStatus": "overlapping", "VpcId": "vpc-042b8a44f64267d67", "SampledStartTime": "2021-12-08T19:54:59.019000+00:00" } ] }

有关更多信息,请参阅Amazon VPC IPAM 用户指南》中的 “查看 IP 地址历史记录”。

以下代码示例演示如何使用 get-ipam-discovered-accounts

AWS CLI

查看某人发现的账户 IPAM

在这种情况下,您是IPAM委托管理员,想要查看拥有IPAM正在发现的资源的 AWS 账户。

--discovery-region是您要查看受监控账户状态的IPAM操作区域。例如,如果您有三个IPAM运营区域,则可能需要发出三次此请求,以查看每个特定区域中与发现相关的时间戳。

以下get-ipam-discovered-accounts示例列出了拥有IPAM正在发现的资源的 AWS 账户。

aws ec2 get-ipam-discovered-accounts \ --ipam-resource-discovery-id ipam-res-disco-0365d2977fc1672fe \ --discovery-region us-east-1

输出:

{ "IpamDiscoveredAccounts": [ { "AccountId": "149977607591", "DiscoveryRegion": "us-east-1", "LastAttemptedDiscoveryTime": "2024-02-09T19:04:31.379000+00:00", "LastSuccessfulDiscoveryTime": "2024-02-09T19:04:31.379000+00:00" } ] }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的IPAM与组织外部账户集成

以下代码示例演示如何使用 get-ipam-discovered-public-addresses

AWS CLI

查看发现的公有 IP 地址

在此示例中,您是IPAM委托管理员,想要查看由发现的资源的 IP 地址IPAM。您可以通过获取资源发现 ID describe-ipam-resource-discoveries

以下get-ipam-discovered-public-addresses示例显示了为资源发现而发现的公有 IP 地址。

aws ec2 get-ipam-discovered-public-addresses \ --ipam-resource-discovery-id ipam-res-disco-0f4ef577a9f37a162 \ --address-region us-east-1 \ --region us-east-1

输出:

{ "IpamDiscoveredPublicAddresses": [ { "IpamResourceDiscoveryId": "ipam-res-disco-0f4ef577a9f37a162", "AddressRegion": "us-east-1", "Address": "54.208.155.7", "AddressOwnerId": "320805250157", "AssociationStatus": "associated", "AddressType": "ec2-public-ip", "VpcId": "vpc-073b294916198ce49", "SubnetId": "subnet-0b6c8a8839e9a4f15", "NetworkInterfaceId": "eni-081c446b5284a5e06", "NetworkInterfaceDescription": "", "InstanceId": "i-07459a6fca5b35823", "Tags": {}, "NetworkBorderGroup": "us-east-1c", "SecurityGroups": [ { "GroupName": "launch-wizard-2", "GroupId": "sg-0a489dd6a65c244ce" } ], "SampleTime": "2024-04-05T15:13:59.228000+00:00" }, { "IpamResourceDiscoveryId": "ipam-res-disco-0f4ef577a9f37a162", "AddressRegion": "us-east-1", "Address": "44.201.251.218", "AddressOwnerId": "470889052923", "AssociationStatus": "associated", "AddressType": "ec2-public-ip", "VpcId": "vpc-6c31a611", "SubnetId": "subnet-062f47608b99834b1", "NetworkInterfaceId": "eni-024845359c2c3ae9b", "NetworkInterfaceDescription": "", "InstanceId": "i-04ef786d9c4e03f41", "Tags": {}, "NetworkBorderGroup": "us-east-1a", "SecurityGroups": [ { "GroupName": "launch-wizard-32", "GroupId": "sg-0ed1a426e96a68374" } ], "SampleTime": "2024-04-05T15:13:59.145000+00:00" } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的查看公共 IP 见解

以下代码示例演示如何使用 get-ipam-discovered-resource-cidrs

AWS CLI

查看CIDRs发现的 IP 地址 IPAM

在此示例中,您是一名IPAM授权管理员,想要查看与IPAM正在发现CIDRs的资源的 IP 地址相关的详细信息。

要完成此请求,请执行以下操作:

您选择的资源发现必须与IPAM。--resource-region这是创建资源的 AWS 区域。

以下get-ipam-discovered-resource-cidrs示例列出了IPAM正在发现的资源的 IP 地址。

aws ec2 get-ipam-discovered-resource-cidrs \ --ipam-resource-discovery-id ipam-res-disco-0365d2977fc1672fe \ --resource-region us-east-1

输出:

{ { "IpamDiscoveredResourceCidrs": [ { "IpamResourceDiscoveryId": "ipam-res-disco-0365d2977fc1672fe", "ResourceRegion": "us-east-1", "ResourceId": "vpc-0c974c95ca7ceef4a", "ResourceOwnerId": "149977607591", "ResourceCidr": "172.31.0.0/16", "ResourceType": "vpc", "ResourceTags": [], "IpUsage": 0.375, "VpcId": "vpc-0c974c95ca7ceef4a", "SampleTime": "2024-02-09T19:15:16.529000+00:00" }, { "IpamResourceDiscoveryId": "ipam-res-disco-0365d2977fc1672fe", "ResourceRegion": "us-east-1", "ResourceId": "subnet-07fe028119082a8c1", "ResourceOwnerId": "149977607591", "ResourceCidr": "172.31.0.0/20", "ResourceType": "subnet", "ResourceTags": [], "IpUsage": 0.0012, "VpcId": "vpc-0c974c95ca7ceef4a", "SampleTime": "2024-02-09T19:15:16.529000+00:00" }, { "IpamResourceDiscoveryId": "ipam-res-disco-0365d2977fc1672fe", "ResourceRegion": "us-east-1", "ResourceId": "subnet-0a96893763984cc4e", "ResourceOwnerId": "149977607591", "ResourceCidr": "172.31.64.0/20", "ResourceType": "subnet", "ResourceTags": [], "IpUsage": 0.0012, "VpcId": "vpc-0c974c95ca7ceef4a", "SampleTime": "2024-02-09T19:15:16.529000+00:00" } } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的按资源监控CIDR使用情况

以下代码示例演示如何使用 get-ipam-pool-allocations

AWS CLI

从IPAM池中获取CIDRs分配

以下get-ipam-pool-allocations示例从IPAM池中获取CIDRs分配的。

(Linux):

aws ec2 get-ipam-pool-allocations \ --ipam-pool-id ipam-pool-0533048da7d823723 \ --filters Name=ipam-pool-allocation-id,Values=ipam-pool-alloc-0e6186d73999e47389266a5d6991e6220

(视窗):

aws ec2 get-ipam-pool-allocations ^ --ipam-pool-id ipam-pool-0533048da7d823723 ^ --filters Name=ipam-pool-allocation-id,Values=ipam-pool-alloc-0e6186d73999e47389266a5d6991e6220

输出:

{ "IpamPoolAllocations": [ { "Cidr": "10.0.0.0/16", "IpamPoolAllocationId": "ipam-pool-alloc-0e6186d73999e47389266a5d6991e6220", "ResourceType": "custom", "ResourceOwner": "123456789012" } ] }

以下代码示例演示如何使用 get-ipam-pool-cidrs

AWS CLI

将CIDRs资源调配到池中 IPAM

以下get-ipam-pool-cidrs示例获取已CIDRs配置到IPAM池中。

(Linux):

aws ec2 get-ipam-pool-cidrs \ --ipam-pool-id ipam-pool-0533048da7d823723 \ --filters 'Name=cidr,Values=10.*'

(视窗):

aws ec2 get-ipam-pool-cidrs ^ --ipam-pool-id ipam-pool-0533048da7d823723 ^ --filters Name=cidr,Values=10.*

输出:

{ "IpamPoolCidr": { "Cidr": "10.0.0.0/24", "State": "provisioned" } }

以下代码示例演示如何使用 get-ipam-resource-cidrs

AWS CLI

获取CIDRs分配给资源的

以下get-ipam-resource-cidrs示例获取CIDRs分配给资源的。

(Linux):

aws ec2 get-ipam-resource-cidrs \ --ipam-scope-id ipam-scope-02fc38cd4c48e7d38 \ --filters Name=management-state,Values=unmanaged

(视窗):

aws ec2 get-ipam-resource-cidrs ^ --ipam-scope-id ipam-scope-02fc38cd4c48e7d38 ^ --filters Name=management-state,Values=unmanaged

输出:

{ "IpamResourceCidrs": [ { "IpamId": "ipam-08440e7a3acde3908", "IpamScopeId": "ipam-scope-02fc38cd4c48e7d38", "ResourceRegion": "us-east-2", "ResourceOwnerId": "123456789012", "ResourceId": "vpc-621b8709", "ResourceName": "Default AWS VPC", "ResourceCidr": "172.33.0.0/16", "ResourceType": "vpc", "ResourceTags": [ { "Key": "Environment", "Value": "Test" }, { "Key": "Name", "Value": "Default AWS VPC" } ], "IpUsage": 0.0039, "ComplianceStatus": "unmanaged", "ManagementState": "unmanaged", "OverlapStatus": "nonoverlapping", "VpcId": "vpc-621b8709" } ] }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的按资源监控CIDR使用情况

以下代码示例演示如何使用 get-launch-template-data

AWS CLI

获取启动模板的实例数据

此示例获取有关指定实例的数据,并使用--query选项返回中的内容LaunchTemplateData。您可以将输出作为基础以创建新的启动模板或启动模板版本。

命令:

aws ec2 get-launch-template-data --instance-id i-0123d646e8048babc --query 'LaunchTemplateData'

输出:

{ "Monitoring": {}, "ImageId": "ami-8c1be5f6", "BlockDeviceMappings": [ { "DeviceName": "/dev/xvda", "Ebs": { "DeleteOnTermination": true } } ], "EbsOptimized": false, "Placement": { "Tenancy": "default", "GroupName": "", "AvailabilityZone": "us-east-1a" }, "InstanceType": "t2.micro", "NetworkInterfaces": [ { "Description": "", "NetworkInterfaceId": "eni-35306abc", "PrivateIpAddresses": [ { "Primary": true, "PrivateIpAddress": "10.0.0.72" } ], "SubnetId": "subnet-7b16de0c", "Groups": [ "sg-7c227019" ], "Ipv6Addresses": [ { "Ipv6Address": "2001:db8:1234:1a00::123" } ], "PrivateIpAddress": "10.0.0.72" } ] }

以下代码示例演示如何使用 get-managed-prefix-list-associations

AWS CLI

获取前缀列表关联

以下get-managed-prefix-list-associations示例获取与指定前缀列表关联的资源。

aws ec2 get-managed-prefix-list-associations \ --prefix-list-id pl-0123456abcabcabc1

输出:

{ "PrefixListAssociations": [ { "ResourceId": "sg-0abc123456abc12345", "ResourceOwner": "123456789012" } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的托管前缀列表

以下代码示例演示如何使用 get-managed-prefix-list-entries

AWS CLI

获取前缀列表的条目

以下get-managed-prefix-list-entries是指定前缀列表的条目。

aws ec2 get-managed-prefix-list-entries \ --prefix-list-id pl-0123456abcabcabc1

输出:

{ "Entries": [ { "Cidr": "10.0.0.0/16", "Description": "vpc-a" }, { "Cidr": "10.2.0.0/16", "Description": "vpc-b" } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的托管前缀列表

以下代码示例演示如何使用 get-network-insights-access-scope-analysis-findings

AWS CLI

获取 Network Insights 访问范围分析的结果

以下get-network-insights-access-scope-analysis-findings示例获取您 AWS 账户中选定的范围分析结果。

aws ec2 get-network-insights-access-scope-analysis-findings \ --region us-east-1 \ --network-insights-access-scope-analysis-id nis \ --nis-123456789111

输出:

{ "NetworkInsightsAccessScopeAnalysisId": "nisa-123456789222", "AnalysisFindings": [ { "NetworkInsightsAccessScopeAnalysisId": "nisa-123456789222", "NetworkInsightsAccessScopeId": "nis-123456789111", "FindingComponents": [ { "SequenceNumber": 1, "Component": { "Id": "eni-02e3d42d5cceca67d", "Arn": "arn:aws:ec2:us-east-1:936459623503:network-interface/eni-02e3d32d9cceca17d" }, "OutboundHeader": { "DestinationAddresses": [ "0.0.0.0/5", "11.0.0.0/8", "12.0.0.0/6", "128.0.0.0/3", "16.0.0.0/4", "160.0.0.0/5", "168.0.0.0/6", "172.0.0.0/12" "8.0.0.0/7" ], "DestinationPortRanges": [ { "From": 0, "To": 65535 } ], "Protocol": "6", "SourceAddresses": [ "10.0.2.253/32" ], "SourcePortRanges": [ { "From": 0, "To": 65535 } ] }, [etc] ] } } ] }

有关更多信息,请参阅《网络访问分析器指南》 AWS CLI中的 “网络访问分析器入”。

以下代码示例演示如何使用 get-network-insights-access-scope-content

AWS CLI

要获取 “网络见解”,请访问范围内容

以下get-network-insights-access-scope-content示例获取您 AWS 账户中选定范围分析 ID 的内容。

aws ec2 get-network-insights-access-scope-content \ --region us-east-1 \ --network-insights-access-scope-id nis-123456789222

输出:

{ "NetworkInsightsAccessScopeContent": { "NetworkInsightsAccessScopeId": "nis-123456789222", "MatchPaths": [ { "Source": { "ResourceStatement": { "ResourceTypes": [ "AWS::EC2::NetworkInterface" ] } }, "Destination": { "ResourceStatement": { "ResourceTypes": [ "AWS::EC2::InternetGateway" ] } } } ] } }

有关更多信息,请参阅《网络访问分析器指南》 AWS CLI中的 “网络访问分析器入”。

以下代码示例演示如何使用 get-password-data

AWS CLI

获取加密的密码

此示例获取加密的密码。

命令:

aws ec2 get-password-data --instance-id i-1234567890abcdef0

输出:

{ "InstanceId": "i-1234567890abcdef0", "Timestamp": "2013-08-07T22:18:38.000Z", "PasswordData": "gSlJFq+VpcZXqy+iktxMF6NyxQ4qCrT4+gaOuNOenX1MmgXPTj7XEXAMPLE UQ+YeFfb+L1U4C4AKv652Ux1iRB3CPTYP7WmU3TUnhsuBd+p6LVk7T2lKUml6OXbk6WPW1VYYm/TRPB1 e1DQ7PY4an/DgZT4mwcpRFigzhniQgDDeO1InvSDcwoUTwNs0Y1S8ouri2W4n5GNlriM3Q0AnNVelVz/ 53TkDtxbNoU606M1gK9zUWSxqEgwvbV2j8c5rP0WCuaMWSFl4ziDu4bd7q+4RSyi8NUsVWnKZ4aEZffu DPGzKrF5yLlf3etP2L4ZR6CvG7K1hx7VKOQVN32Dajw==" }

获取解密后的密码

此示例获取解密后的密码。

命令:

aws ec2 get-password-data --instance-id i-1234567890abcdef0 --priv-launch-key C:\Keys\MyKeyPair.pem

输出:

{ "InstanceId": "i-1234567890abcdef0", "Timestamp": "2013-08-30T23:18:05.000Z", "PasswordData": "&ViJ652e*u" }

以下代码示例演示如何使用 get-reserved-instances-exchange-quote

AWS CLI

获取交换可转换预留实例的报价

此示例获取指定可转换预留实例的交换信息。

命令:

aws ec2 get-reserved-instances-exchange-quote --reserved-instance-ids 7b8750c3-397e-4da4-bbcb-a45ebexample --target-configurations OfferingId=6fea5434-b379-434c-b07b-a7abexample

输出:

{ "CurrencyCode": "USD", "ReservedInstanceValueSet": [ { "ReservedInstanceId": "7b8750c3-397e-4da4-bbcb-a45ebexample", "ReservationValue": { "RemainingUpfrontValue": "0.000000", "HourlyPrice": "0.027800", "RemainingTotalValue": "730.556200" } } ], "PaymentDue": "424.983828", "TargetConfigurationValueSet": [ { "TargetConfiguration": { "InstanceCount": 5, "OfferingId": "6fea5434-b379-434c-b07b-a7abexample" }, "ReservationValue": { "RemainingUpfrontValue": "424.983828", "HourlyPrice": "0.016000", "RemainingTotalValue": "845.447828" } } ], "IsValidExchange": true, "OutputReservedInstancesWillExpireAt": "2020-10-01T13:03:39Z", "ReservedInstanceValueRollup": { "RemainingUpfrontValue": "0.000000", "HourlyPrice": "0.027800", "RemainingTotalValue": "730.556200" }, "TargetConfigurationValueRollup": { "RemainingUpfrontValue": "424.983828", "HourlyPrice": "0.016000", "RemainingTotalValue": "845.447828" } }

以下代码示例演示如何使用 get-security-groups-for-vpc

AWS CLI

查看可与指定网络接口关联的安全组VPC。

以下get-security-groups-for-vpc示例显示了可以与中的网络接口关联的安全组VPC。

aws ec2 get-security-groups-for-vpc \ --vpc-id vpc-6c31a611 \ --region us-east-1

输出:

{ "SecurityGroupForVpcs": [ { "Description": "launch-wizard-36 created 2022-08-29T15:59:35.338Z", "GroupName": "launch-wizard-36", "OwnerId": "470889052923", "GroupId": "sg-007e0c3027ee885f5", "Tags": [], "PrimaryVpcId": "vpc-6c31a611" }, { "Description": "launch-wizard-18 created 2024-01-19T20:22:27.527Z", "GroupName": "launch-wizard-18", "OwnerId": "470889052923", "GroupId": "sg-0147193bef51c9eef", "Tags": [], "PrimaryVpcId": "vpc-6c31a611" } }

以下代码示例演示如何使用 get-serial-console-access-status

AWS CLI

查看账户访问串行控制台的状态

以下get-serial-console-access-status示例确定您的账户是否启用串行控制台访问权限。

aws ec2 get-serial-console-access-status

输出:

{ "SerialConsoleAccessEnabled": true }

有关更多信息,请参阅 Amazon EC2 用户指南中的EC2串行控制台

以下代码示例演示如何使用 get-snapshot-block-public-access-state

AWS CLI

获取快照的封锁公共访问的当前状态

以下get-snapshot-block-public-access-state示例获取了禁止对快照进行公开访问的当前状态。

aws ec2 get-snapshot-block-public-access-state

输出:

{ "State": "block-all-sharing" }

有关更多信息,请参阅 Amazon EBS 用户指南中的阻止对快照的公开访问

以下代码示例演示如何使用 get-spot-placement-scores

AWS CLI

计算指定要求的 Spot 投放分数

以下get-spot-placement-scores示例首先生成一个列表,其中包含可使用参数为竞价投放分数配置指定的所有可能--generate-cli-skeleton参数,然后将该列表保存到JSON文件中。然后,该JSON文件用于配置用于计算竞价投放分数的要求。

生成可以为 Spot 放置分数配置指定的所有可能参数,并将输出直接保存到JSON文件中。

aws ec2 get-spot-placement-scores \ --region us-east-1 \ --generate-cli-skeleton input > attributes.json

输出:

{ "InstanceTypes": [ "" ], "TargetCapacity": 0, "TargetCapacityUnitType": "vcpu", "SingleAvailabilityZone": true, "RegionNames": [ "" ], "InstanceRequirementsWithMetadata": { "ArchitectureTypes": [ "x86_64_mac" ], "VirtualizationTypes": [ "hvm" ], "InstanceRequirements": { "VCpuCount": { "Min": 0, "Max": 0 }, "MemoryMiB": { "Min": 0, "Max": 0 }, "CpuManufacturers": [ "amd" ], "MemoryGiBPerVCpu": { "Min": 0.0, "Max": 0.0 }, "ExcludedInstanceTypes": [ "" ], "InstanceGenerations": [ "previous" ], "SpotMaxPricePercentageOverLowestPrice": 0, "OnDemandMaxPricePercentageOverLowestPrice": 0, "BareMetal": "excluded", "BurstablePerformance": "excluded", "RequireHibernateSupport": true, "NetworkInterfaceCount": { "Min": 0, "Max": 0 }, "LocalStorage": "included", "LocalStorageTypes": [ "hdd" ], "TotalLocalStorageGB": { "Min": 0.0, "Max": 0.0 }, "BaselineEbsBandwidthMbps": { "Min": 0, "Max": 0 }, "AcceleratorTypes": [ "fpga" ], "AcceleratorCount": { "Min": 0, "Max": 0 }, "AcceleratorManufacturers": [ "amd" ], "AcceleratorNames": [ "vu9p" ], "AcceleratorTotalMemoryMiB": { "Min": 0, "Max": 0 } } }, "DryRun": true, "MaxResults": 0, "NextToken": "" }

配置 JSON 文件。您必须为 TargetCapacity 提供一个值。有关每个参数及其默认值的描述,请参阅计算竞价投放分数 (AWS CLI) <https://docs.aws.amazon.com/AWS EC2/latest/UserGuide/spot-placement-calculate-sps-cli score.html# >。

计算中指定要求的 Spot 投放分数attributes.json。使用--cli-input-json参数指定JSON文件的名称和路径。

aws ec2 get-spot-placement-scores \ --region us-east-1 \ --cli-input-json file://attributes.json

如果设置SingleAvailabilityZonefalse或省略则输出(如果省略,则默认为false)。返回区域的分数列表。

"Recommendation": [ { "Region": "us-east-1", "Score": 7 }, { "Region": "us-west-1", "Score": 5 }, ...

如果设置SingleAvailabilityZone为,则输出true。返回 SingleAvailability 区域的分数列表。

"Recommendation": [ { "Region": "us-east-1", "AvailabilityZoneId": "use1-az1" "Score": 8 }, { "Region": "us-east-1", "AvailabilityZoneId": "usw2-az3" "Score": 6 }, ...

有关计算竞价投放分数的更多信息,以及配置示例,请参阅 Amazon EC2 用户指南中的计算竞价投放分数

以下代码示例演示如何使用 get-subnet-cidr-reservations

AWS CLI

获取有关子网CIDR预留的信息

以下get-subnet-cidr-reservations示例显示有关指定子网CIDR预留的信息。

aws ec2 get-subnet-cidr-reservations \ --subnet-id subnet-03c51e2e6cEXAMPLE

输出:

{ "SubnetIpv4CidrReservations": [ { "SubnetCidrReservationId": "scr-044f977c4eEXAMPLE", "SubnetId": "subnet-03c51e2e6cEXAMPLE", "Cidr": "10.1.0.16/28", "ReservationType": "prefix", "OwnerId": "123456789012" } ], "SubnetIpv6CidrReservations": [] }

有关更多信息,请参阅 Amazon VPC 用户指南中的子网CIDR预留

以下代码示例演示如何使用 get-transit-gateway-attachment-propagations

AWS CLI

列出指定资源附件传播到的路由表

以下get-transit-gateway-attachment-propagations示例列出了指定资源附件将路由传播到的路由表。

aws ec2 get-transit-gateway-attachment-propagations \ --transit-gateway-attachment-id tgw-attach-09fbd47ddfEXAMPLE

输出:

{ "TransitGatewayAttachmentPropagations": [ { "TransitGatewayRouteTableId": "tgw-rtb-0882c61b97EXAMPLE", "State": "enabled" } ] }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 路由表

以下代码示例演示如何使用 get-transit-gateway-multicast-domain-associations

AWS CLI

查看有关传输网关组播域关联的信息

以下get-transit-gateway-multicast-domain-associations示例返回指定多播域的关联。

aws ec2 get-transit-gateway-multicast-domain-associations \ --transit-gateway-multicast-domain-id tgw-mcast-domain-0c4905cef7EXAMPLE

输出:

{ "MulticastDomainAssociations": [ { "TransitGatewayAttachmentId": "tgw-attach-028c1dd0f8EXAMPLE", "ResourceId": "vpc-01128d2c24EXAMPLE", "ResourceType": "vpc", "Subnet": { "SubnetId": "subnet-000de86e3bEXAMPLE", "State": "associated" } }, { "TransitGatewayAttachmentId": "tgw-attach-070e571cd1EXAMPLE", "ResourceId": "vpc-7EXAMPLE", "ResourceType": "vpc", "Subnet": { "SubnetId": "subnet-4EXAMPLE", "State": "associated" } }, { "TransitGatewayAttachmentId": "tgw-attach-070e571cd1EXAMPLE", "ResourceId": "vpc-7EXAMPLE", "ResourceType": "vpc", "Subnet": { "SubnetId": "subnet-5EXAMPLE", "State": "associated" } }, { "TransitGatewayAttachmentId": "tgw-attach-070e571cd1EXAMPLE", "ResourceId": "vpc-7EXAMPLE", "ResourceType": "vpc", "Subnet": { "SubnetId": "subnet-aEXAMPLE", "State": "associated" } }, { "TransitGatewayAttachmentId": "tgw-attach-070e571cd1EXAMPLE", "ResourceId": "vpc-7EXAMPLE", "ResourceType": "vpc", "Subnet": { "SubnetId": "subnet-fEXAMPLE", "State": "associated" } } ] }

有关更多信息,请参阅《传输网关指南》中的管理多播域

以下代码示例演示如何使用 get-transit-gateway-prefix-list-references

AWS CLI

在公交网关路由表中获取前缀列表引用

以下get-transit-gateway-prefix-list-references示例获取指定公交网关路由表的前缀列表引用,并按特定前缀列表的 ID 进行过滤。

aws ec2 get-transit-gateway-prefix-list-references \ --transit-gateway-route-table-id tgw-rtb-0123456789abcd123 \ --filters Name=prefix-list-id,Values=pl-11111122222222333

输出:

{ "TransitGatewayPrefixListReferences": [ { "TransitGatewayRouteTableId": "tgw-rtb-0123456789abcd123", "PrefixListId": "pl-11111122222222333", "PrefixListOwnerId": "123456789012", "State": "available", "Blackhole": false, "TransitGatewayAttachment": { "TransitGatewayAttachmentId": "tgw-attach-aabbccddaabbccaab", "ResourceType": "vpc", "ResourceId": "vpc-112233445566aabbc" } } ] }

有关更多信息,请参阅 T ransit Gateways 指南中的前缀列表参考

以下代码示例演示如何使用 get-transit-gateway-route-table-associations

AWS CLI

获取有关指定公交网关路由表关联的信息

以下get-transit-gateway-route-table-associations示例显示有关指定公交网关路由表的关联的信息。

aws ec2 get-transit-gateway-route-table-associations \ --transit-gateway-route-table-id tgw-rtb-0a823edbdeEXAMPLE

输出:

{ "Associations": [ { "TransitGatewayAttachmentId": "tgw-attach-09b52ccdb5EXAMPLE", "ResourceId": "vpc-4d7de228", "ResourceType": "vpc", "State": "associating" } ] }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 路由表

以下代码示例演示如何使用 get-transit-gateway-route-table-propagations

AWS CLI

显示有关指定公交网关路由表的路由表传播的信息

以下get-transit-gateway-route-table-propagations示例返回指定路由表的路由表传播。

aws ec2 get-transit-gateway-route-table-propagations \ --transit-gateway-route-table-id tgw-rtb-002573ed1eEXAMPLE

输出:

{ "TransitGatewayRouteTablePropagations": [ { "TransitGatewayAttachmentId": "tgw-attach-01f8100bc7EXAMPLE", "ResourceId": "vpc-3EXAMPLE", "ResourceType": "vpc", "State": "enabled" }, { "TransitGatewayAttachmentId": "tgw-attach-08e0bc912cEXAMPLE", "ResourceId": "11460968-4ac1-4fd3-bdb2-00599EXAMPLE", "ResourceType": "direct-connect-gateway", "State": "enabled" }, { "TransitGatewayAttachmentId": "tgw-attach-0a89069f57EXAMPLE", "ResourceId": "8384da05-13ce-4a91-aada-5a1baEXAMPLE", "ResourceType": "direct-connect-gateway", "State": "enabled" } ] }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 路由表

以下代码示例演示如何使用 get-verified-access-endpoint-policy

AWS CLI

获取终端节点的已验证访问策略

以下get-verified-access-endpoint-policy示例获取指定端点的已验证访问策略。

aws ec2 get-verified-access-endpoint-policy \ --verified-access-endpoint-id vae-066fac616d4d546f2

输出:

{ "PolicyEnabled": true, "PolicyDocument": "permit(principal,action,resource)\nwhen {\n context.identity.groups.contains(\"finance\") &&\n context.identity.email_verified == true\n};" }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问策略

以下代码示例演示如何使用 get-verified-access-group-policy

AWS CLI

获取群组的 “已验证访问权限” 策略

以下get-verified-access-group-policy示例获取指定组的 “已验证访问权限” 策略。

aws ec2 get-verified-access-group-policy \ --verified-access-group-id vagr-0dbe967baf14b7235

输出:

{ "PolicyEnabled": true, "PolicyDocument": "permit(principal,action,resource)\nwhen {\n context.identity.groups.contains(\"finance\") &&\n context.identity.email_verified == true\n};" }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问

以下代码示例演示如何使用 get-vpn-connection-device-sample-configuration

AWS CLI

下载示例配置文件

以下get-vpn-connection-device-sample-configuration示例下载指定的示例配置文件。要使用示例配置文件列出网关设备,请调用get-vpn-connection-device-types命令。

aws ec2 get-vpn-connection-device-sample-configuration \ --vpn-connection-id vpn-123456789abc01234 \ --vpn-connection-device-type-id 5fb390ba

输出:

{ "VpnConnectionDeviceSampleConfiguration": "contents-of-the-sample-configuration-file" }

有关更多信息,请参阅AWS Site-to-Site VPN用户指南》中的下载配置文件

以下代码示例演示如何使用 get-vpn-connection-device-types

AWS CLI

使用示例配置文件列出网关设备

以下get-vpn-connection-device-types示例列出了来自 Palo Alto Networks 的具有示例配置文件的网关设备。

aws ec2 get-vpn-connection-device-types \ --query "VpnConnectionDeviceTypes[?Vendor==`Palo Alto Networks`]"

输出:

[ { "VpnConnectionDeviceTypeId": "754a6372", "Vendor": "Palo Alto Networks", "Platform": "PA Series", "Software": "PANOS 4.1.2+" }, { "VpnConnectionDeviceTypeId": "9612cbed", "Vendor": "Palo Alto Networks", "Platform": "PA Series", "Software": "PANOS 4.1.2+ (GUI)" }, { "VpnConnectionDeviceTypeId": "5fb390ba", "Vendor": "Palo Alto Networks", "Platform": "PA Series", "Software": "PANOS 7.0+" } ]

有关更多信息,请参阅AWS Site-to-Site VPN用户指南中的下载配置文件

以下代码示例演示如何使用 import-client-vpn-client-certificate-revocation-list

AWS CLI

导入客户证书吊销列表

以下import-client-vpn-client-certificate-revocation-list示例通过指定文件在本地计算机上的位置将客户端证书吊销列表导入到客户端VPN端点。

aws ec2 import-client-vpn-client-certificate-revocation-list \ --certificate-revocation-list file:///path/to/crl.pem \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde

输出:

{ "Return": true }

有关更多信息,请参阅《客户机VPN管理员指南》中的 “AWS 客户证书吊销列表”。

以下代码示例演示如何使用 import-image

AWS CLI

将 VM 映像文件导入 AMI

以下import-image示例导入指定的OVA。

aws ec2 import-image \ --disk-containers Format=ova,UserBucket="{S3Bucket=my-import-bucket,S3Key=vms/my-server-vm.ova}"

输出:

{ "ImportTaskId": "import-ami-1234567890abcdef0", "Progress": "2", "SnapshotDetails": [ { "DiskImageSize": 0.0, "Format": "ova", "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.ova" } } ], "Status": "active", "StatusMessage": "pending" }

以下代码示例演示如何使用 import-key-pair

AWS CLI

导入公钥

首先,使用您选择的工具生成 key pair。例如,使用以下 ssh-keygen 命令:

命令:

ssh-keygen -t rsa -C "my-key" -f ~/.ssh/my-key

输出:

Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/ec2-user/.ssh/my-key. Your public key has been saved in /home/ec2-user/.ssh/my-key.pub. ...

此示例命令导入指定的公钥。

命令:

aws ec2 import-key-pair --key-name "my-key" --public-key-material fileb://~/.ssh/my-key.pub

输出:

{ "KeyName": "my-key", "KeyFingerprint": "1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca" }

以下代码示例演示如何使用 import-snapshot

AWS CLI

导入快照

以下import-snapshot示例将指定的磁盘作为快照导入。

aws ec2 import-snapshot \ --description "My server VMDK" \ --disk-container Format=VMDK,UserBucket={S3Bucket=my-import-bucket,S3Key=vms/my-server-vm.vmdk}

输出:

{ "Description": "My server VMDK", "ImportTaskId": "import-snap-1234567890abcdef0", "SnapshotTaskDetail": { "Description": "My server VMDK", "DiskImageSize": "0.0", "Format": "VMDK", "Progress": "3", "Status": "active", "StatusMessage": "pending" "UserBucket": { "S3Bucket": "my-import-bucket", "S3Key": "vms/my-server-vm.vmdk" } } }

以下代码示例演示如何使用 list-images-in-recycle-bin

AWS CLI

列出回收站中的图像

以下list-images-in-recycle-bin示例列出了当前保留在回收站中的所有图像。

aws ec2 list-images-in-recycle-bin

输出:

{ "Images": [ { "RecycleBinEnterTime": "2022-03-14T15:35:08.000Z", "Description": "Monthly AMI One", "RecycleBinExitTime": "2022-03-15T15:35:08.000Z", "Name": "AMI_01", "ImageId": "ami-0111222333444abcd" } ] }

有关更多信息,请参阅 Amazon 弹性计算云用户指南中的AMIs从回收站恢复

以下代码示例演示如何使用 list-snapshots-in-recycle-bin

AWS CLI

查看回收站中的快照

以下list-snapshots-in-recycle-bin示例列出了有关回收站中快照的信息,包括快照 ID、快照描述、创建快照的卷的 ID、删除快照并进入回收站的日期和时间,以及保留期到期的日期和时间。

aws ec2 list-snapshots-in-recycle-bin \ --snapshot-id snap-01234567890abcdef

输出:

{ "SnapshotRecycleBinInfo": [ { "Description": "Monthly data backup snapshot", "RecycleBinEnterTime": "2022-12-01T13:00:00.000Z", "RecycleBinExitTime": "2022-12-15T13:00:00.000Z", "VolumeId": "vol-abcdef09876543210", "SnapshotId": "snap-01234567890abcdef" } ] }

有关亚马逊回收站的更多信息EBS,请参阅亚马逊EC2用户指南》中的从回收站恢复快照

以下代码示例演示如何使用 lock-snapshot

AWS CLI

示例 1:在治理模式下锁定快照

以下lock-snapshot示例在治理模式下锁定指定的快照。

aws ec2 lock-snapshot \ --snapshot-id snap-0b5e733b4a8df6e0d \ --lock-mode governance \ --lock-duration 365

输出:

{ "SnapshotId": "snap-0b5e733b4a8df6e0d", "LockState": "governance", "LockDuration": 365, "LockCreatedOn": "2024-05-05T00:56:06.208000+00:00", "LockExpiresOn": "2025-05-05T00:56:06.208000+00:00", "LockDurationStartTime": "2024-05-05T00:56:06.208000+00:00" }

有关更多信息,请参阅 Amazon EBS 用户指南中的快照锁

示例 2:在合规模式下锁定快照

以下lock-snapshot示例在合规模式下锁定指定的快照。

aws ec2 lock-snapshot \ --snapshot-id snap-0163a8524c5b9901f \ --lock-mode compliance \ --cool-off-period 24 \ --lock-duration 365

输出:

{ "SnapshotId": "snap-0b5e733b4a8df6e0d", "LockState": "compliance-cooloff", "LockDuration": 365, "CoolOffPeriod": 24, "CoolOffPeriodExpiresOn": "2024-05-06T01:02:20.527000+00:00", "LockCreatedOn": "2024-05-05T01:02:20.527000+00:00", "LockExpiresOn": "2025-05-05T01:02:20.527000+00:00", "LockDurationStartTime": "2024-05-05T01:02:20.527000+00:00" }

有关更多信息,请参阅 Amazon EBS 用户指南中的快照锁

以下代码示例演示如何使用 modify-address-attribute

AWS CLI

修改与弹性 IP 地址关联的域名属性

以下modify-address-attribute示例修改弹性 IP 地址的域名属性。

Linux:

aws ec2 modify-address-attribute \ --allocation-id eipalloc-abcdef01234567890 \ --domain-name example.com

Windows:

aws ec2 modify-address-attribute ^ --allocation-id eipalloc-abcdef01234567890 ^ --domain-name example.com

输出:

{ "Addresses": [ { "PublicIp": "192.0.2.0", "AllocationId": "eipalloc-abcdef01234567890", "PtrRecord": "example.net." "PtrRecordUpdate": { "Value": "example.com.", "Status": "PENDING" } ] }

要监控待处理的更改并查看弹性 IP 地址的修改属性,请参阅《AWS CLI命令参考describe-addresses-attribute中的。

以下代码示例演示如何使用 modify-availability-zone-group

AWS CLI

启用区域组

以下modify-availability-zone-group示例启用了指定的区域组。

aws ec2 modify-availability-zone-group \ --group-name us-west-2-lax-1 \ --opt-in-status opted-in

输出:

{ "Return": true }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的区域和区域

以下代码示例演示如何使用 modify-capacity-reservation-fleet

AWS CLI

示例 1:修改容量预留队列的总目标容量

以下modify-capacity-reservation-fleet示例修改了指定容量预留队列的总目标容量。当您修改容量预留机群的总目标容量时,机群会自动创建新的容量预留,或者修改或取消机群中的现有容量预留以满足新的总目标容量。当机群处于 modifying 状态时,您无法尝试对其进行其他修改。

aws ec2 modify-capacity-reservation-fleet \ --capacity-reservation-fleet-id crf-01234567890abcedf \ --total-target-capacity 160

输出:

{ "Return": true }

示例 2:修改容量预留队列的结束日期

以下modify-capacity-reservation-fleet示例修改了指定容量预留队列的结束日期。当您修改机群的结束日期时,所有单个容量预留的结束日期都会相应更新。当机群处于 modifying 状态时,您无法尝试对其进行其他修改。

aws ec2 modify-capacity-reservation-fleet \ --capacity-reservation-fleet-id crf-01234567890abcedf \ --end-date 2022-07-04T23:59:59.000Z

输出:

{ "Return": true }

有关容量预留队列的更多信息,请参阅 A mazon EC2 用户指南中的容量预留队列。

以下代码示例演示如何使用 modify-capacity-reservation

AWS CLI

示例 1:更改现有容量预留的实例数量

以下modify-capacity-reservation示例更改了容量预留为其预留容量的实例数量。

aws ec2 modify-capacity-reservation \ --capacity-reservation-id cr-1234abcd56EXAMPLE \ --instance-count 5

输出:

{ "Return": true }

示例 2:更改现有容量预留的结束日期和时间

以下modify-capacity-reservation示例将现有容量预留修改为在指定的日期和时间结束。

aws ec2 modify-capacity-reservation \ --capacity-reservation-id cr-1234abcd56EXAMPLE \ --end-date-type limited \ --end-date 2019-08-31T23:59:59Z

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的修改容量预留

以下代码示例演示如何使用 modify-client-vpn-endpoint

AWS CLI

修改客户端VPN终端节点

以下modify-client-vpn-endpoint示例为指定的客户端VPN端点启用客户端连接日志记录。

aws ec2 modify-client-vpn-endpoint \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde \ --connection-log-options Enabled=true,CloudwatchLogGroup=ClientVPNLogs

输出:

{ "Return": true }

有关更多信息,请参阅《客户机VPN管理员指南》中的AWS 客户端VPN端点

以下代码示例演示如何使用 modify-default-credit-specification

AWS CLI

修改默认积分选项

以下modify-default-credit-specification示例修改了 T2 实例的默认积分选项。

aws ec2 modify-default-credit-specification \ --instance-family t2 \ --cpu-credits unlimited

输出:

{ "InstanceFamilyCreditSpecification": { "InstanceFamily": "t2", "CpuCredits": "unlimited" } }

以下代码示例演示如何使用 modify-ebs-default-kms-key-id

AWS CLI

设置EBS加密CMK的默认值

以下modify-ebs-default-kms-key-id示例将指定CMKCMK为当前区域中 AWS 账户EBS加密的默认值。

aws ec2 modify-ebs-default-kms-key-id \ --kms-key-id alias/my-cmk

输出:

{ "KmsKeyId": "arn:aws:kms:us-west-2:123456789012:key/0ea3fef3-80a7-4778-9d8c-1c0c6EXAMPLE" }

以下代码示例演示如何使用 modify-fleet

AWS CLI

扩大EC2舰队规模

以下modify-fleet示例修改了指定EC2舰队的目标容量。如果指定的值大于当前容量,则EC2队列会启动其他实例。如果指定值小于当前容量,EC2队列将取消所有未处理的请求;如果终止策略是terminate,则EC2队列将终止超过新目标容量的所有实例。

aws ec2 modify-fleet \ --fleet-ids fleet-12a34b55-67cd-8ef9-ba9b-9208dEXAMPLE \ --target-capacity-specification TotalTargetCapacity=5

输出:

{ "Return": true }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的管理EC2队列

以下代码示例演示如何使用 modify-fpga-image-attribute

AWS CLI

修改亚马逊FPGA图片的属性

此示例为指定的账户 ID 123456789012 添加加载权限AFI。

命令:

aws ec2 modify-fpga-image-attribute --attribute loadPermission --fpga-image-id afi-0d123e123bfc85abc --load-permission Add=[{UserId=123456789012}]

输出:

{ "FpgaImageAttribute": { "FpgaImageId": "afi-0d123e123bfc85abc", "LoadPermissions": [ { "UserId": "123456789012" } ] } }

以下代码示例演示如何使用 modify-hosts

AWS CLI

示例 1:为专用主机启用自动放置

以下modify-hosts示例为专用主机启用自动放置,以便它接受与其实例类型配置相匹配的任何非定向实例启动。

aws ec2 modify-hosts \ --host-id h-06c2f189b4EXAMPLE \ --auto-placement on

输出:

{ "Successful": [ "h-06c2f189b4EXAMPLE" ], "Unsuccessful": [] }

示例 2:为专用主机启用主机恢复

以下modify-hosts示例为指定的专用主机启用主机恢复。

aws ec2 modify-hosts \ --host-id h-06c2f189b4EXAMPLE \ --host-recovery on

输出:

{ "Successful": [ "h-06c2f189b4EXAMPLE" ], "Unsuccessful": [] }

有关更多信息,请参阅适用于 Linux 实例的 Amazon 弹性计算云用户指南中的修改专用主机的自动放置

以下代码示例演示如何使用 modify-id-format

AWS CLI

为资源启用加长 ID 格式

以下modify-id-format示例启用instance资源类型的加长 ID 格式。

aws ec2 modify-id-format \ --resource instance \ --use-long-ids

禁用资源的加长 ID 格式

以下modify-id-format示例禁用instance资源类型的加长 ID 格式。

aws ec2 modify-id-format \ --resource instance \ --no-use-long-ids

以下modify-id-format示例为所有处于选择加入期限内的受支持资源类型启用加长 ID 格式。

aws ec2 modify-id-format \ --resource all-current \ --use-long-ids

以下代码示例演示如何使用 modify-identity-id-format

AWS CLI

使IAM角色能够在资源上使用IDs更长的时间

以下modify-identity-id-format示例使您 AWS 账户EC2Role中的IAM角色能够对instance资源类型使用长 ID 格式。

aws ec2 modify-identity-id-format \ --principal-arn arn:aws:iam::123456789012:role/EC2Role \ --resource instance \ --use-long-ids

使用IAM户能够在资源上使用IDs更长的时间

以下modify-identity-id-format示例使您 AWS 账户AdminUser中的IAM用户能够对volume资源类型使用加长 ID 格式。

aws ec2 modify-identity-id-format \ --principal-arn arn:aws:iam::123456789012:user/AdminUser \ --resource volume \ --use-long-ids

以下modify-identity-id-format示例使您 AWS 账户AdminUser中的IAM用户能够对处于其选择加入期限内的所有支持的资源类型使用较长的 ID 格式。

aws ec2 modify-identity-id-format \ --principal-arn arn:aws:iam::123456789012:user/AdminUser \ --resource all-current \ --use-long-ids

以下代码示例演示如何使用 modify-image-attribute

AWS CLI

示例 1:AMI公开

以下modify-instance-attribute示例将指定的AMI公开。

aws ec2 modify-image-attribute \ --image-id ami-5731123e \ --launch-permission "Add=[{Group=all}]"

此命令不生成任何输出。

示例 2:设为AMI私有

以下modify-instance-attribute示例将指定的设置为AMI私有。

aws ec2 modify-image-attribute \ --image-id ami-5731123e \ --launch-permission "Remove=[{Group=all}]"

此命令不生成任何输出。

示例 3:向 AWS 账户授予启动权限

以下modify-instance-attribute示例向指定 AWS 账户授予启动权限。

aws ec2 modify-image-attribute \ --image-id ami-5731123e \ --launch-permission "Add=[{UserId=123456789012}]"

此命令不生成任何输出。

示例 4:移除 AWS 账户的启动权限

以下modify-instance-attribute示例删除了指定 AWS 账户的启动权限。

aws ec2 modify-image-attribute \ --image-id ami-5731123e \ --launch-permission "Remove=[{UserId=123456789012}]"

以下代码示例演示如何使用 modify-instance-attribute

AWS CLI

示例 1:修改实例类型

以下modify-instance-attribute示例修改了指定实例的实例类型。该实例必须处于 stopped 状态。

aws ec2 modify-instance-attribute \ --instance-id i-1234567890abcdef0 \ --instance-type "{\"Value\": \"m1.small\"}"

此命令不生成任何输出。

示例 2:在实例上启用增强联网

以下modify-instance-attribute示例为指定实例启用增强联网。该实例必须处于 stopped 状态。

aws ec2 modify-instance-attribute \ --instance-id i-1234567890abcdef0 \ --sriov-net-support simple

此命令不生成任何输出。

示例 3:修改 sourceDestCheck 属性

以下modify-instance-attribute示例将指定实例的sourceDestCheck属性设置为true。该实例必须位于VPC.

aws ec2 modify-instance-attribute --instance-id i-1234567890abcdef0 --source-dest-check "{\"Value\": true}"

此命令不生成任何输出。

示例 4:修改根卷的 deleteOnTermination 属性

以下modify-instance-attribute示例将由亚马逊EBS支持的指定实例的根卷的deleteOnTermination属性设置为。false默认情况下,此属性true适用于根卷。

命令:

aws ec2 modify-instance-attribute \ --instance-id i-1234567890abcdef0 \ --block-device-mappings "[{\"DeviceName\": \"/dev/sda1\",\"Ebs\":{\"DeleteOnTermination\":false}}]"

此命令不生成任何输出。

示例 5:修改附加到实例的用户数据

以下modify-instance-attribute示例将文件内容添加UserData.txt UserData 为指定实例。

原始文件的内容UserData.txt

#!/bin/bash yum update -y service httpd start chkconfig httpd on

该文件的内容必须采用 base64 编码。第一个命令将文本文件转换为 base64 并将其另存为新文件。

该命令的 Linux/macOS 版本:

base64 UserData.txt > UserData.base64.txt

此命令不生成任何输出。

该命令的 Windows 版本:

certutil -encode UserData.txt tmp.b64 && findstr /v /c:- tmp.b64 > UserData.base64.txt

输出:

Input Length = 67 Output Length = 152 CertUtil: -encode command completed successfully.

现在,你可以在下面的CLI命令中引用该文件:

aws ec2 modify-instance-attribute \ --instance-id=i-09b5a14dbca622e76 \ --attribute userData --value file://UserData.base64.txt

此命令不生成任何输出。

有关更多信息,请参阅用户数据和《EC2用户指南》 AWS CLI中的。

以下代码示例演示如何使用 modify-instance-capacity-reservation-attributes

AWS CLI

示例 1:修改实例的容量预留目标设置

以下modify-instance-capacity-reservation-attributes示例将已停止的实例修改为针对特定的容量预留。

aws ec2 modify-instance-capacity-reservation-attributes \ --instance-id i-EXAMPLE8765abcd4e \ --capacity-reservation-specification 'CapacityReservationTarget={CapacityReservationId= cr-1234abcd56EXAMPLE }'

输出:

{ "Return": true }

示例 2:修改实例的容量预留目标设置

以下modify-instance-capacity-reservation-attributes示例修改了以指定容量预留为目标的已停止实例,使其在具有匹配属性(实例类型、平台、可用区)且具有开放实例匹配标准的任何容量预留中启动。

aws ec2 modify-instance-capacity-reservation-attributes \ --instance-id i-EXAMPLE8765abcd4e \ --capacity-reservation-specification 'CapacityReservationPreference=open'

输出:

{ "Return": true }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的修改实例的容量预留设置

以下代码示例演示如何使用 modify-instance-credit-specification

AWS CLI

修改实例CPU使用积分选项

此示例将用于在指定区域CPU使用指定实例的积分选项修改为 “无限制”。有效的信用选项有 “标准” 和 “无限制”。

命令:

aws ec2 modify-instance-credit-specification --instance-credit-specification "InstanceId=i-1234567890abcdef0,CpuCredits=unlimited"

输出:

{ "SuccessfulInstanceCreditSpecifications": [ { "InstanceId": "i-1234567890abcdef0" } ], "UnsuccessfulInstanceCreditSpecifications": [] }

以下代码示例演示如何使用 modify-instance-event-start-time

AWS CLI

修改实例的事件开始时间

以下modify-instance-event-start-time命令显示如何修改指定实例的事件开始时间。使用--instance-event-id参数指定事件 ID。使用--not-before参数指定新的日期和时间。

aws ec2 modify-instance-event-start-time --instance-id i-1234567890abcdef0 --instance-event-id instance-event-0abcdef1234567890 --not-before 2019-03-25T10:00:00.000

输出:

"Event": { "InstanceEventId": "instance-event-0abcdef1234567890", "Code": "system-reboot", "Description": "scheduled reboot", "NotAfter": "2019-03-25T12:00:00.000Z", "NotBefore": "2019-03-25T10:00:00.000Z", "NotBeforeDeadline": "2019-04-22T21:00:00.000Z" }

有关更多信息,请参阅 Amazon 弹性计算云用户指南中的使用计划重启的实例

以下代码示例演示如何使用 modify-instance-event-window

AWS CLI

示例 1:修改事件窗口的时间范围

以下modify-instance-event-window示例修改了事件窗口的时间范围。指定 time-range 参数以修改时间范围。您不能同时指定 cron-expression 参数。

aws ec2 modify-instance-event-window \ --region us-east-1 \ --instance-event-window-id iew-0abcdef1234567890 --time-range StartWeekDay=monday,StartHour=2,EndWeekDay=wednesday,EndHour=8

输出:

{ "InstanceEventWindow": { "InstanceEventWindowId": "iew-0abcdef1234567890", "TimeRanges": [ { "StartWeekDay": "monday", "StartHour": 2, "EndWeekDay": "wednesday", "EndHour": 8 } ], "Name": "myEventWindowName", "AssociationTarget": { "InstanceIds": [ "i-0abcdef1234567890", "i-0be35f9acb8ba01f0" ], "Tags": [], "DedicatedHostIds": [] }, "State": "creating", "Tags": [ { "Key": "K1", "Value": "V1" } ] } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

示例 2:修改事件窗口的一组时间范围

以下modify-instance-event-window示例修改了事件窗口的时间范围。指定 time-range 参数以修改时间范围。您不能同时指定 cron-expression 参数。

aws ec2 modify-instance-event-window \ --region us-east-1 \ --instance-event-window-id iew-0abcdef1234567890 \ --time-range '[{"StartWeekDay": "monday", "StartHour": 2, "EndWeekDay": "wednesday", "EndHour": 8}, {"StartWeekDay": "thursday", "StartHour": 2, "EndWeekDay": "friday", "EndHour": 8}]'

输出:

{ "InstanceEventWindow": { "InstanceEventWindowId": "iew-0abcdef1234567890", "TimeRanges": [ { "StartWeekDay": "monday", "StartHour": 2, "EndWeekDay": "wednesday", "EndHour": 8 }, { "StartWeekDay": "thursday", "StartHour": 2, "EndWeekDay": "friday", "EndHour": 8 } ], "Name": "myEventWindowName", "AssociationTarget": { "InstanceIds": [ "i-0abcdef1234567890", "i-0be35f9acb8ba01f0" ], "Tags": [], "DedicatedHostIds": [] }, "State": "creating", "Tags": [ { "Key": "K1", "Value": "V1" } ] } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

示例 3:修改事件窗口的 cron 表达式

以下modify-instance-event-window示例修改了事件窗口的 cron 表达式。指定 cron-expression 参数以修改 Cron 表达式。您不能同时指定 time-range 参数。

aws ec2 modify-instance-event-window \ --region us-east-1 \ --instance-event-window-id iew-0abcdef1234567890 \ --cron-expression "* 21-23 * * 2,3"

输出:

{ "InstanceEventWindow": { "InstanceEventWindowId": "iew-0abcdef1234567890", "Name": "myEventWindowName", "CronExpression": "* 21-23 * * 2,3", "AssociationTarget": { "InstanceIds": [ "i-0abcdef1234567890", "i-0be35f9acb8ba01f0" ], "Tags": [], "DedicatedHostIds": [] }, "State": "creating", "Tags": [ { "Key": "K1", "Value": "V1" } ] } }

有关事件窗口限制的信息,请参阅《Amazon EC2 用户指南》的 “计划事件” 部分中的注意事项

以下代码示例演示如何使用 modify-instance-maintenance-options

AWS CLI

示例 1:禁用实例的恢复行为

以下modify-instance-maintenance-options示例禁用正在运行或已停止的实例的简化自动恢复。

aws ec2 modify-instance-maintenance-options \ --instance-id i-0abcdef1234567890 \ --auto-recovery disabled

输出:

{ "InstanceId": "i-0abcdef1234567890", "AutoRecovery": "disabled" }

有关更多信息,请参阅《Amazon Linux 实例EC2用户指南》中的恢复实例

示例 2:将实例的恢复行为设置为默认值

以下modify-instance-maintenance-options示例将自动恢复行为设置为默认值,这样可以简化支持的实例类型的自动恢复。

aws ec2 modify-instance-maintenance-options \ --instance-id i-0abcdef1234567890 \ --auto-recovery default

输出:

{ "InstanceId": "i-0abcdef1234567890", "AutoRecovery": "default" }

有关更多信息,请参阅《Amazon Linux 实例EC2用户指南》中的恢复实例

以下代码示例演示如何使用 modify-instance-metadata-options

AWS CLI

示例 1:启用 IMDSv2

以下modify-instance-metadata-options示例配置了在指定实例IMDSv2上的使用。

aws ec2 modify-instance-metadata-options \ --instance-id i-1234567898abcdef0 \ --http-tokens required \ --http-endpoint enabled

输出:

{ "InstanceId": "i-1234567898abcdef0", "InstanceMetadataOptions": { "State": "pending", "HttpTokens": "required", "HttpPutResponseHopLimit": 1, "HttpEndpoint": "enabled" } }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的实例元数据和用户数据。

示例 2:禁用实例元数据

以下modify-instance-metadata-options示例禁止在指定实例上使用所有版本的实例元数据。

aws ec2 modify-instance-metadata-options \ --instance-id i-1234567898abcdef0 \ --http-endpoint disabled

输出:

{ "InstanceId": "i-1234567898abcdef0", "InstanceMetadataOptions": { "State": "pending", "HttpTokens": "required", "HttpPutResponseHopLimit": 1, "HttpEndpoint": "disabled" } }

有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的实例元数据和用户数据。

示例 3:为您的实例启用实例元数据IPv6终端节点

以下modify-instance-metadata-options示例向您展示了如何为实例元数据服务开启IPv6终端节点。

aws ec2 modify-instance-metadata-options \ --instance-id i-1234567898abcdef0 \ --http-protocol-ipv6 enabled \ --http-endpoint enabled

输出:

{ "InstanceId": "i-1234567898abcdef0", "InstanceMetadataOptions": { "State": "pending", "HttpTokens": "required", "HttpPutResponseHopLimit": 1, "HttpEndpoint": "enabled", HttpProtocolIpv6": "enabled" } }

默认情况下,IPv6终端节点处于禁用状态。即使您已将实例启动到IPv6仅限子网中,也是如此。的IPv6终端节点只能IMDS在 Nitro 系统上构建的实例上访问。有关更多信息,请参阅《适用于 Linux 实例的 Amazon 弹性计算云用户指南》中的实例元数据和用户数据。

以下代码示例演示如何使用 modify-instance-placement

AWS CLI

示例 1:移除实例与专用主机的关联性

以下modify-instance-placement示例删除了实例与专用主机的关联性,使其能够在您的账户中支持其实例类型的任何可用专用主机上启动。

aws ec2 modify-instance-placement \ --instance-id i-0e6ddf6187EXAMPLE \ --affinity default

输出:

{ "Return": true }

示例 2:在实例和指定的专用主机之间建立关联

以下modify-instance-placement示例在实例和专用主机之间建立了启动关系。该实例只能在指定的专用主机上运行。

aws ec2 modify-instance-placement \ --instance-id i-0e6ddf6187EXAMPLE \ --affinity host \ --host-id i-0e6ddf6187EXAMPLE

输出:

{ "Return": true }

有关更多信息,请参阅适用于 Linux 实例的 Amazon 弹性计算云用户指南中的修改实例租期和关联性。

示例 3:将实例移至置放群组

以下modify-instance-placement示例将实例移至置放群组,停止该实例,修改实例放置位置,然后重启该实例。

aws ec2 stop-instances \ --instance-ids i-0123a456700123456 aws ec2 modify-instance-placement \ --instance-id i-0123a456700123456 \ --group-name MySpreadGroup aws ec2 start-instances \ --instance-ids i-0123a456700123456

有关更多信息,请参阅 Amazon Elastic Compute Cloud 用户指南中的更改实例的置放群组

示例 4:从置放群组中移除实例

以下modify-instance-placement示例通过停止实例、修改实例放置位置然后重启实例,将该实例从置放群组中移除。以下示例为置放群组名称指定了一个空字符串 (“”),以表示该实例不应位于置放群组中。

停止实例:

aws ec2 stop-instances \ --instance-ids i-0123a456700123456

修改放置位置(Windows 命令提示符、Linux 和 macOS):

aws ec2 modify-instance-placement \ --instance-id i-0123a456700123456 \ --group-name ""

修改放置位置 (Windows PowerShell):

aws ec2 modify-instance-placement ` --instance-id i-0123a456700123456 ` --group-name """"

重启实例:

aws ec2 start-instances \ --instance-ids i-0123a456700123456

输出:

{ "Return": true }

有关更多信息,请参阅适用于 Linux 实例的 Amazon 弹性计算云用户指南中的修改实例租期和关联性。

以下代码示例演示如何使用 modify-ipam-pool

AWS CLI

修改IPAM池

以下modify-ipam-pool示例修改了IPAM池。

(Linux):

aws ec2 modify-ipam-pool \ --ipam-pool-id ipam-pool-0533048da7d823723 \ --add-allocation-resource-tags "Key=Owner,Value=Build Team" \ --clear-allocation-default-netmask-length \ --allocation-min-netmask-length 14

(视窗):

aws ec2 modify-ipam-pool ^ --ipam-pool-id ipam-pool-0533048da7d823723 ^ --add-allocation-resource-tags "Key=Owner,Value=Build Team" ^ --clear-allocation-default-netmask-length ^ --allocation-min-netmask-length 14

输出:

{ "IpamPool": { "OwnerId": "123456789012", "IpamPoolId": "ipam-pool-0533048da7d823723", "IpamPoolArn": "arn:aws:ec2::123456789012:ipam-pool/ipam-pool-0533048da7d823723", "IpamScopeArn": "arn:aws:ec2::123456789012:ipam-scope/ipam-scope-02fc38cd4c48e7d38", "IpamScopeType": "private", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-08440e7a3acde3908", "IpamRegion": "us-east-1", "Locale": "None", "PoolDepth": 1, "State": "modify-complete", "AutoImport": true, "AddressFamily": "ipv4", "AllocationMinNetmaskLength": 14, "AllocationMaxNetmaskLength": 26, "AllocationResourceTags": [ { "Key": "Environment", "Value": "Preprod" }, { "Key": "Owner", "Value": "Build Team" } ] } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的编辑池

以下代码示例演示如何使用 modify-ipam-resource-cidr

AWS CLI

修改CIDR分配给资源的

以下modify-ipam-resource-cidr示例修改了资源CIDR。

(Linux):

aws ec2 modify-ipam-resource-cidr \ --current-ipam-scope-id ipam-scope-02fc38cd4c48e7d38 \ --destination-ipam-scope-id ipam-scope-0da34c61fd189a141 \ --resource-id vpc-010e1791024eb0af9 \ --resource-cidr 10.0.1.0/24 \ --resource-region us-east-1 \ --monitored

(视窗):

aws ec2 modify-ipam-resource-cidr ^ --current-ipam-scope-id ipam-scope-02fc38cd4c48e7d38 ^ --destination-ipam-scope-id ipam-scope-0da34c61fd189a141 ^ --resource-id vpc-010e1791024eb0af9 ^ --resource-cidr 10.0.1.0/24 ^ --resource-region us-east-1 ^ --monitored

输出:

{ "IpamResourceCidr": { "IpamId": "ipam-08440e7a3acde3908", "IpamScopeId": "ipam-scope-0da34c61fd189a141", "IpamPoolId": "ipam-pool-0533048da7d823723", "ResourceRegion": "us-east-1", "ResourceOwnerId": "123456789012", "ResourceId": "vpc-010e1791024eb0af9", "ResourceCidr": "10.0.1.0/24", "ResourceType": "vpc", "ResourceTags": [ { "Key": "Environment", "Value": "Preprod" }, { "Key": "Owner", "Value": "Build Team" } ], "IpUsage": 0.0, "ComplianceStatus": "noncompliant", "ManagementState": "managed", "OverlapStatus": "overlapping", "VpcId": "vpc-010e1791024eb0af9" } }

有关移动资源的更多信息,请参阅 Amazon VPC IPAM 用户指南中的在范围CIDRs之间移动资源

有关更改监控状态的更多信息,请参阅 Amazon VPC IPAM 用户指南CIDRs中的更改资源监控状态

以下代码示例演示如何使用 modify-ipam-resource-discovery

AWS CLI

修改资源发现的操作区域

在此示例中,您是一名IPAM授权管理员,想要修改资源发现的操作区域。

要完成此请求,请执行以下操作:

您无法修改默认资源发现,并且必须是资源发现的所有者。您需要资源发现 ID,您可以使用它获得。describe-ipam-resource-discoveries

以下modify-ipam-resource-discovery示例修改了您 AWS 账户中的非默认资源发现。

aws ec2 modify-ipam-resource-discovery \ --ipam-resource-discovery-id ipam-res-disco-0f4ef577a9f37a162 \ --add-operating-regions RegionName='us-west-1' \ --remove-operating-regions RegionName='us-east-2' \ --region us-east-1

输出:

{ "IpamResourceDiscovery": { "OwnerId": "149977607591", "IpamResourceDiscoveryId": "ipam-res-disco-0365d2977fc1672fe", "IpamResourceDiscoveryArn": "arn:aws:ec2::149977607591:ipam-resource-discovery/ipam-res-disco-0365d2977fc1672fe", "IpamResourceDiscoveryRegion": "us-east-1", "Description": "Example", "OperatingRegions": [ { "RegionName": "us-east-1" }, { "RegionName": "us-west-1" } ], "IsDefault": false, "State": "modify-in-progress" } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南中的使用资源发现

以下代码示例演示如何使用 modify-ipam-scope

AWS CLI

修改作用域的描述

在这种情况下,您是想要修改IPAM作用域描述的IPAM委托管理员。

要完成此请求,你需要范围 ID,你可以用它获得describe-ipam-scopes

以下modify-ipam-scope示例更新了作用域的描述。

aws ec2 modify-ipam-scope \ --ipam-scope-id ipam-scope-0d3539a30b57dcdd1 \ --description example \ --region us-east-1

输出:

{ "IpamScope": { "OwnerId": "320805250157", "IpamScopeId": "ipam-scope-0d3539a30b57dcdd1", "IpamScopeArn": "arn:aws:ec2::320805250157:ipam-scope/ipam-scope-0d3539a30b57dcdd1", "IpamArn": "arn:aws:ec2::320805250157:ipam/ipam-005f921c17ebd5107", "IpamRegion": "us-east-1", "IpamScopeType": "public", "IsDefault": true, "Description": "example", "PoolCount": 1, "State": "modify-in-progress" } }

有关范围的更多信息,请参阅 Amazon VPC IPAM 用户指南中的IPAM工作原理

以下代码示例演示如何使用 modify-ipam

AWS CLI

要修改 IPAM

以下modify-ipam示例IPAM通过添加操作区域来修改。

(Linux):

aws ec2 modify-ipam \ --ipam-id ipam-08440e7a3acde3908 \ --add-operating-regions RegionName=us-west-2

(视窗):

aws ec2 modify-ipam ^ --ipam-id ipam-08440e7a3acde3908 ^ --add-operating-regions RegionName=us-west-2

输出:

{ "Ipam": { "OwnerId": "123456789012", "IpamId": "ipam-08440e7a3acde3908", "IpamArn": "arn:aws:ec2::123456789012:ipam/ipam-08440e7a3acde3908", "IpamRegion": "us-east-1", "PublicDefaultScopeId": "ipam-scope-0b9eed026396dbc16", "PrivateDefaultScopeId": "ipam-scope-02fc38cd4c48e7d38", "ScopeCount": 3, "OperatingRegions": [ { "RegionName": "us-east-1" }, { "RegionName": "us-east-2" }, { "RegionName": "us-west-1" }, { "RegionName": "us-west-2" } ], "State": "modify-in-progress" } }

以下代码示例演示如何使用 modify-launch-template

AWS CLI

更改默认启动模板版本

此示例将指定启动模板的版本 2 指定为默认版本。

命令:

aws ec2 modify-launch-template --launch-template-id lt-0abcd290751193123 --default-version 2

输出:

{ "LaunchTemplate": { "LatestVersionNumber": 2, "LaunchTemplateId": "lt-0abcd290751193123", "LaunchTemplateName": "WebServers", "DefaultVersionNumber": 2, "CreatedBy": "arn:aws:iam::123456789012:root", "CreateTime": "2017-12-01T13:35:46.000Z" } }

以下代码示例演示如何使用 modify-managed-prefix-list

AWS CLI

修改前缀列表

以下modify-managed-prefix-list示例向指定的前缀列表中添加一个条目。

aws ec2 modify-managed-prefix-list \ --prefix-list-id pl-0123456abcabcabc1 \ --add-entries Cidr=10.1.0.0/16,Description=vpc-c \ --current-version 1

输出:

{ "PrefixList": { "PrefixListId": "pl-0123456abcabcabc1", "AddressFamily": "IPv4", "State": "modify-in-progress", "PrefixListArn": "arn:aws:ec2:us-west-2:123456789012:prefix-list/pl-0123456abcabcabc1", "PrefixListName": "vpc-cidrs", "MaxEntries": 10, "Version": 1, "OwnerId": "123456789012" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的托管前缀列表

以下代码示例演示如何使用 modify-network-interface-attribute

AWS CLI

修改网络接口的连接属性

此示例命令修改指定网络接口的attachment属性。

命令:

aws ec2 modify-network-interface-attribute --network-interface-id eni-686ea200 --attachment AttachmentId=eni-attach-43348162,DeleteOnTermination=false

修改网络接口的描述属性

此示例命令修改指定网络接口的description属性。

命令:

aws ec2 modify-network-interface-attribute --network-interface-id eni-686ea200 --description "My description"

修改网络接口的 groupSet 属性

此示例命令修改指定网络接口的groupSet属性。

命令:

aws ec2 modify-network-interface-attribute --network-interface-id eni-686ea200 --groups sg-903004f8 sg-1a2b3c4d

修改网络接口的 sourceDestCheck 属性

此示例命令修改指定网络接口的sourceDestCheck属性。

命令:

aws ec2 modify-network-interface-attribute --network-interface-id eni-686ea200 --no-source-dest-check

以下代码示例演示如何使用 modify-private-dns-name-options

AWS CLI

修改实例主机名的选项

以下modify-private-dns-name-options示例禁用了响应带有 DNS A 记录的主机名的DNS查询的选项。

aws ec2 modify-private-dns-name-options \ --instance-id i-1234567890abcdef0 \ --no-enable-resource-name-dns-a-record

输出:

{ "Return": true }

有关更多信息,请参阅亚马逊EC2用户指南中的亚马逊EC2实例主机名类型

以下代码示例演示如何使用 modify-reserved-instances

AWS CLI

修改预留实例

此示例命令将预留实例移动到同一地区的另一个可用区。

命令:

aws ec2 modify-reserved-instances --reserved-instances-ids b847fa93-e282-4f55-b59a-1342f5bd7c02 --target-configurations AvailabilityZone=us-west-1c,Platform=EC2-Classic,InstanceCount=10

输出:

{ "ReservedInstancesModificationId": "rimod-d3ed4335-b1d3-4de6-ab31-0f13aaf46687" }

修改预留实例的网络平台

此示例命令将 EC2-Classic 预留实例转换为 EC2-VPC。

命令:

aws ec2 modify-reserved-instances --reserved-instances-ids f127bd27-edb7-44c9-a0eb-0d7e09259af0 --target-configurations AvailabilityZone=us-west-1c,Platform=EC2-VPC,InstanceCount=5

输出:

{ "ReservedInstancesModificationId": "rimod-82fa9020-668f-4fb6-945d-61537009d291" }

有关更多信息,请参阅 Amazon EC2 用户指南中的修改您的预留实例。

修改预留实例的实例大小

此示例命令修改在 us-west-1c 中拥有 10 个 m1.small Linux/ 实例的预留实例,这样 8 个 m1.small UNIX 实例变成 2 个 m1.large 实例,剩下的 2 个 m1.small 变成 1 个 m1.medium 实例,位于同一可用区中。命令:

aws ec2 modify-reserved-instances --reserved-instances-ids 1ba8e2e3-3556-4264-949e-63ee671405a9 --target-configurations AvailabilityZone=us-west-1c,Platform=EC2-Classic,InstanceCount=2,InstanceType=m1.large AvailabilityZone=us-west-1c,Platform=EC2-Classic,InstanceCount=1,InstanceType=m1.medium

输出:

{ "ReservedInstancesModificationId": "rimod-acc5f240-080d-4717-b3e3-1c6b11fa00b6" }

有关更多信息,请参阅 Amazon EC2 用户指南中的修改预留实例大小。

以下代码示例演示如何使用 modify-security-group-rules

AWS CLI

修改安全组规则以更新规则描述、IP 协议和 CidrIpv 4 地址范围

以下modify-security-group-rules示例更新了指定安全组规则的描述、IP 协议和IPV4CIDR范围。使用security-group-rules参数输入指定安全组规则的更新。 -1指定所有协议。

aws ec2 modify-security-group-rules \ --group-id sg-1234567890abcdef0 \ --security-group-rules SecurityGroupRuleId=sgr-abcdef01234567890,SecurityGroupRule='{Description=test,IpProtocol=-1,CidrIpv4=0.0.0.0/0}'

输出:

{ "Return": true }

有关安全组规则的更多信息,请参阅 Amazon EC2 用户指南中的安全组规则

以下代码示例演示如何使用 modify-snapshot-attribute

AWS CLI

示例 1:修改快照属性

以下modify-snapshot-attribute示例更新了指定快照的createVolumePermission属性,删除了指定用户的卷权限。

aws ec2 modify-snapshot-attribute \ --snapshot-id snap-1234567890abcdef0 \ --attribute createVolumePermission \ --operation-type remove \ --user-ids 123456789012

示例 2:公开快照

以下modify-snapshot-attribute示例将指定的快照设为公开。

aws ec2 modify-snapshot-attribute \ --snapshot-id snap-1234567890abcdef0 \ --attribute createVolumePermission \ --operation-type add \ --group-names all

以下代码示例演示如何使用 modify-snapshot-tier

AWS CLI

示例 1:存档快照

以下modify-snapshot-tier示例存档了指定的快照。

aws ec2 modify-snapshot-tier \ --snapshot-id snap-01234567890abcedf \ --storage-tier archive

输出:

{ "SnapshotId": "snap-01234567890abcedf", "TieringStartTime": "2021-09-15T16:44:37.574Z" }

TieringStartTime响应参数以时间格式 (YYYY-MM--: MM:DDTHH) 表示存档过程开始的日期和UTC时间。SSZ

有关快照存档的更多信息,请参阅《亚马逊EC2用户指南》中的存档亚马逊EBS快照

以下代码示例演示如何使用 modify-spot-fleet-request

AWS CLI

修改竞价型队列请求

此示例命令更新指定 Spot 队列请求的目标容量。

命令:

aws ec2 modify-spot-fleet-request --target-capacity 20 --spot-fleet-request-id sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE

输出:

{ "Return": true }

此示例命令减少了指定竞价型队列请求的目标容量,但不会因此终止任何竞价型实例。

命令:

aws ec2 modify-spot-fleet-request --target-capacity 10 --excess-capacity-termination-policy NoTermination --spot-fleet-request-ids sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE

输出:

{ "Return": true }

以下代码示例演示如何使用 modify-subnet-attribute

AWS CLI

更改子网的公有IPv4寻址行为

此示例修改了 subnet-1a2b3c4d,以指定在该子网中启动的所有实例都分配一个公有地址。IPv4如果命令成功,则不返回任何输出。

命令:

aws ec2 modify-subnet-attribute --subnet-id subnet-1a2b3c4d --map-public-ip-on-launch

更改子网的IPv6寻址行为

此示例修改了 subnet-1a2b3c4d,以指定向该子网启动的所有实例都分配了该子网范围内的地址。IPv6

命令:

aws ec2 modify-subnet-attribute --subnet-id subnet-1a2b3c4d --assign-ipv6-address-on-creation

有关更多信息,请参阅《AWS 虚拟私有云用户指南》VPC中的 “您的 IP 寻址”。

以下代码示例演示如何使用 modify-traffic-mirror-filter-network-services

AWS CLI

向流量镜像过滤器添加网络服务

以下modify-traffic-mirror-filter-network-services示例将 Amazon DNS 网络服务添加到指定的筛选条件中。

aws ec2 modify-traffic-mirror-filter-network-services \ --traffic-mirror-filter-id tmf-04812ff784EXAMPLE \ --add-network-service amazon-dns

输出:

{ "TrafficMirrorFilter": { "Tags": [ { "Key": "Name", "Value": "Production" } ], "EgressFilterRules": [], "NetworkServices": [ "amazon-dns" ], "TrafficMirrorFilterId": "tmf-04812ff784EXAMPLE", "IngressFilterRules": [ { "SourceCidrBlock": "0.0.0.0/0", "RuleNumber": 1, "DestinationCidrBlock": "0.0.0.0/0", "Description": "TCP Rule", "Protocol": 6, "TrafficDirection": "ingress", "TrafficMirrorFilterId": "tmf-04812ff784EXAMPLE", "RuleAction": "accept", "TrafficMirrorFilterRuleId": "tmf-04812ff784EXAMPLE" } ] } }

有关更多信息,请参阅《流量镜像指南》中的修改AWS 流量镜像过滤器网络服务

以下代码示例演示如何使用 modify-traffic-mirror-filter-rule

AWS CLI

修改流量镜像过滤器规则

以下modify-traffic-mirror-filter-rule示例修改了指定流量镜像过滤规则的描述。

aws ec2 modify-traffic-mirror-filter-rule \ --traffic-mirror-filter-rule-id tmfr-0ca76e0e08EXAMPLE \ --description "TCP Rule"

输出:

{ "TrafficMirrorFilterRule": { "TrafficMirrorFilterRuleId": "tmfr-0ca76e0e08EXAMPLE", "TrafficMirrorFilterId": "tmf-0293f26e86EXAMPLE", "TrafficDirection": "ingress", "RuleNumber": 100, "RuleAction": "accept", "Protocol": 6, "DestinationCidrBlock": "10.0.0.0/24", "SourceCidrBlock": "10.0.0.0/24", "Description": "TCP Rule" } }

有关更多信息,请参阅《流量镜像指南》中的修改您的AWS 流量镜像过滤器规则

以下代码示例演示如何使用 modify-traffic-mirror-session

AWS CLI

修改流量镜像会话

以下modify-traffic-mirror-session示例更改了流量镜像会话描述和要镜像的数据包数量。

aws ec2 modify-traffic-mirror-session \ --description "Change packet length" \ --traffic-mirror-session-id tms-08a33b1214EXAMPLE \ --remove-fields "packet-length"

输出:

{ "TrafficMirrorSession": { "TrafficMirrorSessionId": "tms-08a33b1214EXAMPLE", "TrafficMirrorTargetId": "tmt-07f75d8feeEXAMPLE", "TrafficMirrorFilterId": "tmf-04812ff784EXAMPLE", "NetworkInterfaceId": "eni-070203f901EXAMPLE", "OwnerId": "111122223333", "SessionNumber": 1, "VirtualNetworkId": 7159709, "Description": "Change packet length", "Tags": [] } }

有关更多信息,请参阅《流量镜像指南》中的修改您的流量镜像会话

以下代码示例演示如何使用 modify-transit-gateway-prefix-list-reference

AWS CLI

修改对前缀列表的引用

以下modify-transit-gateway-prefix-list-reference示例通过更改流量路由到的附件来修改指定路由表中的前缀列表引用。

aws ec2 modify-transit-gateway-prefix-list-reference \ --transit-gateway-route-table-id tgw-rtb-0123456789abcd123 \ --prefix-list-id pl-11111122222222333 \ --transit-gateway-attachment-id tgw-attach-aabbccddaabbccaab

输出:

{ "TransitGatewayPrefixListReference": { "TransitGatewayRouteTableId": "tgw-rtb-0123456789abcd123", "PrefixListId": "pl-11111122222222333", "PrefixListOwnerId": "123456789012", "State": "modifying", "Blackhole": false, "TransitGatewayAttachment": { "TransitGatewayAttachmentId": "tgw-attach-aabbccddaabbccaab", "ResourceType": "vpc", "ResourceId": "vpc-112233445566aabbc" } } }

有关更多信息,请参阅 T ransit Gateways 指南中的前缀列表参考

以下代码示例演示如何使用 modify-transit-gateway-vpc-attachment

AWS CLI

修改公交网关VPC附件

以下modify-transit-gateway-vpc-attachment示例向指定的传输网关VPC连接添加子网。

aws ec2 modify-transit-gateway-vpc-attachment \ --transit-gateway-attachment-id tgw-attach-09fbd47ddfEXAMPLE \ --add-subnet-ids subnet-0e51f45802EXAMPLE

输出:

{ "TransitGatewayVpcAttachment": { "TransitGatewayAttachmentId": "tgw-attach-09fbd47ddfEXAMPLE", "TransitGatewayId": "tgw-0560315ccfEXAMPLE", "VpcId": "vpc-5eccc927", "VpcOwnerId": "111122223333", "State": "modifying", "SubnetIds": [ "subnet-0e51f45802EXAMPLE", "subnet-1EXAMPLE" ], "CreationTime": "2019-08-08T16:47:38.000Z", "Options": { "DnsSupport": "enable", "Ipv6Support": "disable" } } }

有关更多信息,请参阅《公交网关指南》VPC中的公交网关附件

以下代码示例演示如何使用 modify-transit-gateway

AWS CLI

修改传输网关

以下modify-transit-gateway示例通过启用对VPN附件的ECMP支持来修改指定的传输网关。

aws ec2 modify-transit-gateway \ --transit-gateway-id tgw-111111222222aaaaa \ --options VpnEcmpSupport=enable

输出:

{ "TransitGateway": { "TransitGatewayId": "tgw-111111222222aaaaa", "TransitGatewayArn": "64512", "State": "modifying", "OwnerId": "123456789012", "CreationTime": "2020-04-30T08:41:37.000Z", "Options": { "AmazonSideAsn": 64512, "AutoAcceptSharedAttachments": "disable", "DefaultRouteTableAssociation": "enable", "AssociationDefaultRouteTableId": "tgw-rtb-0123456789abcd123", "DefaultRouteTablePropagation": "enable", "PropagationDefaultRouteTableId": "tgw-rtb-0123456789abcd123", "VpnEcmpSupport": "enable", "DnsSupport": "enable" } } }

有关更多信息,请参阅《传输网关指南》中的中转网关

以下代码示例演示如何使用 modify-verified-access-endpoint-policy

AWS CLI

为终端节点配置 “已验证访问权限” 策略

以下modify-verified-access-endpoint-policy示例将指定的已验证访问策略添加到指定的已验证访问终端节点。

aws ec2 modify-verified-access-endpoint-policy \ --verified-access-endpoint-id vae-066fac616d4d546f2 \ --policy-enabled \ --policy-document file://policy.txt

policy.txt 的内容:

permit(principal,action,resource) when { context.identity.groups.contains("finance") && context.identity.email.verified == true };

输出:

{ "PolicyEnabled": true, "PolicyDocument": "permit(principal,action,resource)\nwhen {\n context.identity.groups.contains(\"finance\") &&\n context.identity.email_verified == true\n};" }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问策略

以下代码示例演示如何使用 modify-verified-access-endpoint

AWS CLI

修改已验证访问终端节点的配置

以下modify-verified-access-endpoint示例将指定的描述添加到指定的已验证访问终端节点。

aws ec2 modify-verified-access-endpoint \ --verified-access-endpoint-id vae-066fac616d4d546f2 \ --description "Testing Verified Access"

输出:

{ "VerifiedAccessEndpoint": { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "VerifiedAccessGroupId": "vagr-0dbe967baf14b7235", "VerifiedAccessEndpointId": "vae-066fac616d4d546f2", "ApplicationDomain": "example.com", "EndpointType": "network-interface", "AttachmentType": "vpc", "DomainCertificateArn": "arn:aws:acm:us-east-2:123456789012:certificate/eb065ea0-26f9-4e75-a6ce-0a1a7EXAMPLE", "EndpointDomain": "my-ava-app.edge-00c3372d53b1540bb.vai-0ce000c0b7643abea.prod.verified-access.us-east-2.amazonaws.com", "SecurityGroupIds": [ "sg-004915970c4c8f13a" ], "NetworkInterfaceOptions": { "NetworkInterfaceId": "eni-0aec70418c8d87a0f", "Protocol": "https", "Port": 443 }, "Status": { "Code": "updating" }, "Description": "Testing Verified Access", "CreationTime": "2023-08-25T20:54:43", "LastUpdatedTime": "2023-08-25T22:46:32" } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问终端节点

以下代码示例演示如何使用 modify-verified-access-group-policy

AWS CLI

为组配置 “已验证访问权限” 策略

以下modify-verified-access-group-policy示例将指定的 “已验证访问权限” 策略添加到指定的已验证访问权限组。

aws ec2 modify-verified-access-group-policy \ --verified-access-group-id vagr-0dbe967baf14b7235 \ --policy-enabled \ --policy-document file://policy.txt

policy.txt 的内容:

permit(principal,action,resource) when { context.identity.groups.contains("finance") && context.identity.email.verified == true };

输出:

{ "PolicyEnabled": true, "PolicyDocument": "permit(principal,action,resource)\nwhen {\n context.identity.groups.contains(\"finance\") &&\n context.identity.email_verified == true\n};" }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问

以下代码示例演示如何使用 modify-verified-access-group

AWS CLI

修改已验证访问权限组的配置

以下modify-verified-access-group示例将指定的描述添加到指定的 “已验证访问权限” 组。

aws ec2 modify-verified-access-group \ --verified-access-group-id vagr-0dbe967baf14b7235 \ --description "Testing Verified Access"

输出:

{ "VerifiedAccessGroup": { "VerifiedAccessGroupId": "vagr-0dbe967baf14b7235", "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "Description": "Testing Verified Access", "Owner": "123456789012", "VerifiedAccessGroupArn": "arn:aws:ec2:us-east-2:123456789012:verified-access-group/vagr-0dbe967baf14b7235", "CreationTime": "2023-08-25T19:55:19", "LastUpdatedTime": "2023-08-25T22:17:25" } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问

以下代码示例演示如何使用 modify-verified-access-instance-logging-configuration

AWS CLI

为已验证的访问权限实例启用日志记录

以下modify-verified-access-instance-logging-configuration示例为指定的 Verified Access 实例启用访问日志记录。日志将传送到指定的 CloudWatch 日志日志组。

aws ec2 modify-verified-access-instance-logging-configuration \ --verified-access-instance-id vai-0ce000c0b7643abea \ --access-logs CloudWatchLogs={Enabled=true,LogGroup=my-log-group}

输出:

{ "LoggingConfiguration": { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "AccessLogs": { "S3": { "Enabled": false }, "CloudWatchLogs": { "Enabled": true, "DeliveryStatus": { "Code": "success" }, "LogGroup": "my-log-group" }, "KinesisDataFirehose": { "Enabled": false }, "LogVersion": "ocsf-1.0.0-rc.2", "IncludeTrustContext": false } } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问日志

以下代码示例演示如何使用 modify-verified-access-instance

AWS CLI

修改已验证访问权限实例的配置

以下modify-verified-access-instance示例将指定的描述添加到指定的已验证访问权限实例。

aws ec2 modify-verified-access-instance \ --verified-access-instance-id vai-0ce000c0b7643abea \ --description "Testing Verified Access"

输出:

{ "VerifiedAccessInstance": { "VerifiedAccessInstanceId": "vai-0ce000c0b7643abea", "Description": "Testing Verified Access", "VerifiedAccessTrustProviders": [ { "VerifiedAccessTrustProviderId": "vatp-0bb32de759a3e19e7", "TrustProviderType": "user", "UserTrustProviderType": "iam-identity-center" } ], "CreationTime": "2023-08-25T18:27:56", "LastUpdatedTime": "2023-08-25T22:41:04" } }

有关更多信息,请参阅《已验证访问用户指南》中的AWS 已验证访问实例

以下代码示例演示如何使用 modify-verified-access-trust-provider

AWS CLI

修改已验证访问信任提供商的配置

以下modify-verified-access-trust-provider示例将指定的描述添加到指定的已验证访问信任提供商。

aws ec2 modify-verified-access-trust-provider \ --verified-access-trust-provider-id vatp-0bb32de759a3e19e7 \ --description "Testing Verified Access"

输出:

{ "VerifiedAccessTrustProvider": { "VerifiedAccessTrustProviderId": "vatp-0bb32de759a3e19e7", "Description": "Testing Verified Access", "TrustProviderType": "user", "UserTrustProviderType": "iam-identity-center", "PolicyReferenceName": "idc", "CreationTime": "2023-08-25T19:00:38", "LastUpdatedTime": "2023-08-25T19:18:21" } }

有关更多信息,请参阅《已验证访问用户指南》中的 “AWS 验证访问权限的信任提供商”。

以下代码示例演示如何使用 modify-volume-attribute

AWS CLI

修改体积属性

此示例将 ID 为的卷的autoEnableIo属性设置vol-1234567890abcdef0true。如果命令成功,则不返回任何输出。

命令:

aws ec2 modify-volume-attribute --volume-id vol-1234567890abcdef0 --auto-enable-io

以下代码示例演示如何使用 modify-volume

AWS CLI

示例 1:通过更改卷大小来修改卷

以下modify-volume示例将指定卷的大小更改为 150GB。

命令:

aws ec2 modify-volume --size 150 --volume-id vol-1234567890abcdef0

输出:

{ "VolumeModification": { "TargetSize": 150, "TargetVolumeType": "io1", "ModificationState": "modifying", "VolumeId": " vol-1234567890abcdef0", "TargetIops": 100, "StartTime": "2019-05-17T11:27:19.000Z", "Progress": 0, "OriginalVolumeType": "io1", "OriginalIops": 100, "OriginalSize": 100 } }

示例 2:通过更改卷的类型、大小和IOPS值来修改卷

以下modify-volume示例将卷类型更改为已配置 IOPSSSD,将目标IOPS速率设置为 10000,并将卷大小设置为 350GB。

aws ec2 modify-volume \ --volume-type io1 \ --iops 10000 \ --size 350 \ --volume-id vol-1234567890abcdef0

输出:

{ "VolumeModification": { "TargetSize": 350, "TargetVolumeType": "io1", "ModificationState": "modifying", "VolumeId": "vol-0721c1a9d08c93bf6", "TargetIops": 10000, "StartTime": "2019-05-17T11:38:57.000Z", "Progress": 0, "OriginalVolumeType": "gp2", "OriginalIops": 150, "OriginalSize": 50 } }

以下代码示例演示如何使用 modify-vpc-attribute

AWS CLI

修改 enableDnsSupport 属性

此示例修改了该enableDnsSupport属性。此属性表示是否为启用DNS分辨率VPC。如果此属性为true,则 Amazon DNS 服务器会将您的实例DNS的主机名解析为相应的 IP 地址;否则,不会。如果命令成功,则不返回任何输出。

命令:

aws ec2 modify-vpc-attribute --vpc-id vpc-a01106c2 --enable-dns-support "{\"Value\":false}"

修改 enableDnsHostnames 属性

此示例修改了该enableDnsHostnames属性。此属性表示实例是否在VPC获取DNS主机名中启动。如果此属性为true,则中的实例会VPC获取DNS主机名;否则,它们不会。如果命令成功,则不返回任何输出。

命令:

aws ec2 modify-vpc-attribute --vpc-id vpc-a01106c2 --enable-dns-hostnames "{\"Value\":false}"

以下代码示例演示如何使用 modify-vpc-endpoint-connection-notification

AWS CLI

修改端点连接通知

此示例更改了指定端点连接通知SNS的主题。

命令:

aws ec2 modify-vpc-endpoint-connection-notification --connection-notification-id vpce-nfn-008776de7e03f5abc --connection-events Accept Reject --connection-notification-arn arn:aws:sns:us-east-2:123456789012:mytopic

输出:

{ "ReturnValue": true }

以下代码示例演示如何使用 modify-vpc-endpoint-service-configuration

AWS CLI

修改终端节点服务配置

此示例更改了指定终端节点服务的接受要求。

命令:

aws ec2 modify-vpc-endpoint-service-configuration --service-id vpce-svc-09222513e6e77dc86 --no-acceptance-required

输出:

{ "ReturnValue": true }

以下代码示例演示如何使用 modify-vpc-endpoint-service-payer-responsibility

AWS CLI

修改付款人责任

以下modify-vpc-endpoint-service-payer-responsibility示例修改了指定终端节点服务的付款人责任。

aws ec2 modify-vpc-endpoint-service-payer-responsibility \ --service-id vpce-svc-071afff70666e61e0 \ --payer-responsibility ServiceOwner

此命令不生成任何输出。

以下代码示例演示如何使用 modify-vpc-endpoint-service-permissions

AWS CLI

修改终端节点服务权限

此示例为 AWS 账户添加了连接到指定终端节点服务的权限。

命令:

aws ec2 modify-vpc-endpoint-service-permissions --service-id vpce-svc-03d5ebb7d9579a2b3 --add-allowed-principals '["arn:aws:iam::123456789012:root"]'

输出:

{ "ReturnValue": true }

此示例为特定IAM用户 (admin) 添加了连接到指定终端节点服务的权限。

命令:

aws ec2 modify-vpc-endpoint-service-permissions --service-id vpce-svc-03d5ebb7d9579a2b3 --add-allowed-principals '["arn:aws:iam::123456789012:user/admin"]'

以下代码示例演示如何使用 modify-vpc-endpoint

AWS CLI

修改网关终端节点

此示例vpce-1a2b3c4d通过将路由表rtb-aaa222bb与终端节点关联并重置策略文档来修改网关终端节点。

命令:

aws ec2 modify-vpc-endpoint --vpc-endpoint-id vpce-1a2b3c4d --add-route-table-ids rtb-aaa222bb --reset-policy

输出:

{ "Return": true }

修改接口终端节点

此示例通过向终端节点添加子网vpce-0fe5b17a0707d6fa5subnet-d6fcaa8d来修改接口终端节点。

命令:

aws ec2 modify-vpc-endpoint --vpc-endpoint-id vpce-0fe5b17a0707d6fa5 --add-subnet-id subnet-d6fcaa8d

输出:

{ "Return": true }

以下代码示例演示如何使用 modify-vpc-peering-connection-options

AWS CLI

启用本地 ClassicLink 连接通过VPC对等连接进行通信

在此示例中,对于对等连接pcx-aaaabbb,请求者的所有者VPC修改了对VPC等连接选项,使本地 ClassicLink 连接能够与对等体进行通信。VPC

命令:

aws ec2 modify-vpc-peering-connection-options --vpc-peering-connection-id pcx-aaaabbbb --requester-peering-connection-options AllowEgressFromLocalClassicLinkToRemoteVpc=true

输出:

{ "RequesterPeeringConnectionOptions": { "AllowEgressFromLocalClassicLinkToRemoteVpc": true } }

启用通过对VPC等连接从本地VPC到远程 ClassicLink 连接的通信

在此示例中,接受者的所有者VPC修改了对VPC等连接选项,使本地VPC用户能够与对等体中的 ClassicLink 连接进行通信。VPC

命令:

aws ec2 modify-vpc-peering-connection-options --vpc-peering-connection-id pcx-aaaabbbb --accepter-peering-connection-options AllowEgressFromLocalVpcToRemoteClassicLink=true

输出:

{ "AccepterPeeringConnectionOptions": { "AllowEgressFromLocalVpcToRemoteClassicLink": true } }

为对VPC等连接启用DNS分辨率支持

在此示例中,请求者的所有者VPC修改了的对VPC等连接选项,使本地pcx-aaaabbbb能够在从对等体中的实例VPC进行查询时将公共DNS主机名解析为私有 IP 地址。VPC

命令:

aws ec2 modify-vpc-peering-connection-options --vpc-peering-connection-id pcx-aaaabbbb --requester-peering-connection-options AllowDnsResolutionFromRemoteVpc=true

输出:

{ "RequesterPeeringConnectionOptions": { "AllowDnsResolutionFromRemoteVpc": true } }

以下代码示例演示如何使用 modify-vpc-tenancy

AWS CLI

修改某人的租约 VPC

此示例将的租约修改为。VPC vpc-1a2b3c4d default

命令:

aws ec2 modify-vpc-tenancy --vpc-id vpc-1a2b3c4d --instance-tenancy default

输出:

{ "Return": true }

以下代码示例演示如何使用 modify-vpn-connection-options

AWS CLI

修改您的VPN连接选项

以下modify-vpn-connection-options示例修改了指定VPN连接IPv4CIDR的客户网关端的本地。

aws ec2 modify-vpn-connection-options \ --vpn-connection-id vpn-1122334455aabbccd \ --local-ipv4-network-cidr 10.0.0.0/16

输出:

{ "VpnConnections": [ { "CustomerGatewayConfiguration": "...configuration information...", "CustomerGatewayId": "cgw-01234567abcde1234", "Category": "VPN", "State": "modifying", "Type": "ipsec.1", "VpnConnectionId": "vpn-1122334455aabbccd", "TransitGatewayId": "tgw-00112233445566aab", "Options": { "EnableAcceleration": false, "StaticRoutesOnly": true, "LocalIpv4NetworkCidr": "10.0.0.0/16", "RemoteIpv4NetworkCidr": "0.0.0.0/0", "TunnelInsideIpVersion": "ipv4" }, "Routes": [], "Tags": [ { "Key": "Name", "Value": "CanadaVPN" } ], "VgwTelemetry": [ { "AcceptedRouteCount": 0, "LastStatusChange": "2020-07-29T10:35:11.000Z", "OutsideIpAddress": "203.0.113.3", "Status": "DOWN", "StatusMessage": "" }, { "AcceptedRouteCount": 0, "LastStatusChange": "2020-09-02T09:09:33.000Z", "OutsideIpAddress": "203.0.113.5", "Status": "UP", "StatusMessage": "" } ] } ] }

有关更多信息,请参阅《AWS Site-to-Site VPN用户指南》中的修改 Site-to-SiteVPN连接选项

以下代码示例演示如何使用 modify-vpn-connection

AWS CLI

修改VPN连接

以下modify-vpn-connection示例更改了VPN连接到虚拟专用网关vpn-12345678901234567的目标网关vgw-11223344556677889

aws ec2 modify-vpn-connection \ --vpn-connection-id vpn-12345678901234567 \ --vpn-gateway-id vgw-11223344556677889

输出:

{ "VpnConnection": { "CustomerGatewayConfiguration": "...configuration information...", "CustomerGatewayId": "cgw-aabbccddee1122334", "Category": "VPN", "State": "modifying", "Type": "ipsec.1", "VpnConnectionId": "vpn-12345678901234567", "VpnGatewayId": "vgw-11223344556677889", "Options": { "StaticRoutesOnly": false }, "VgwTelemetry": [ { "AcceptedRouteCount": 0, "LastStatusChange": "2019-07-17T07:34:00.000Z", "OutsideIpAddress": "18.210.3.222", "Status": "DOWN", "StatusMessage": "IPSEC IS DOWN" }, { "AcceptedRouteCount": 0, "LastStatusChange": "2019-07-20T21:20:16.000Z", "OutsideIpAddress": "34.193.129.33", "Status": "DOWN", "StatusMessage": "IPSEC IS DOWN" } ] } }

以下代码示例演示如何使用 modify-vpn-tunnel-certificate

AWS CLI

轮换VPN隧道证书

以下modify-vpn-tunnel-certificate示例轮换连接的指定隧道的VPN证书

aws ec2 modify-vpn-tunnel-certificate \ --vpn-tunnel-outside-ip-address 203.0.113.17 \ --vpn-connection-id vpn-12345678901234567

输出:

{ "VpnConnection": { "CustomerGatewayConfiguration": ...configuration information..., "CustomerGatewayId": "cgw-aabbccddee1122334", "Category": "VPN", "State": "modifying", "Type": "ipsec.1", "VpnConnectionId": "vpn-12345678901234567", "VpnGatewayId": "vgw-11223344556677889", "Options": { "StaticRoutesOnly": false }, "VgwTelemetry": [ { "AcceptedRouteCount": 0, "LastStatusChange": "2019-09-11T17:27:14.000Z", "OutsideIpAddress": "203.0.113.17", "Status": "DOWN", "StatusMessage": "IPSEC IS DOWN", "CertificateArn": "arn:aws:acm:us-east-1:123456789101:certificate/c544d8ce-20b8-4fff-98b0-example" }, { "AcceptedRouteCount": 0, "LastStatusChange": "2019-09-11T17:26:47.000Z", "OutsideIpAddress": "203.0.114.18", "Status": "DOWN", "StatusMessage": "IPSEC IS DOWN", "CertificateArn": "arn:aws:acm:us-east-1:123456789101:certificate/5ab64566-761b-4ad3-b259-example" } ] } }

以下代码示例演示如何使用 modify-vpn-tunnel-options

AWS CLI

修改VPN连接的隧道选项

以下modify-vpn-tunnel-options示例更新了允许使用指定隧道和连接的 Diffie-Hellman 组。VPN

aws ec2 modify-vpn-tunnel-options \ --vpn-connection-id vpn-12345678901234567 \ --vpn-tunnel-outside-ip-address 203.0.113.17 \ --tunnel-options Phase1DHGroupNumbers=[{Value=14},{Value=15},{Value=16},{Value=17},{Value=18}],Phase2DHGroupNumbers=[{Value=14},{Value=15},{Value=16},{Value=17},{Value=18}]

输出:

{ "VpnConnection": { "CustomerGatewayConfiguration": "...configuration information...", "CustomerGatewayId": "cgw-aabbccddee1122334", "Category": "VPN", "State": "available", "Type": "ipsec.1", "VpnConnectionId": "vpn-12345678901234567", "VpnGatewayId": "vgw-11223344556677889", "Options": { "StaticRoutesOnly": false, "TunnelOptions": [ { "OutsideIpAddress": "203.0.113.17", "Phase1DHGroupNumbers": [ { "Value": 14 }, { "Value": 15 }, { "Value": 16 }, { "Value": 17 }, { "Value": 18 } ], "Phase2DHGroupNumbers": [ { "Value": 14 }, { "Value": 15 }, { "Value": 16 }, { "Value": 17 }, { "Value": 18 } ] }, { "OutsideIpAddress": "203.0.114.19" } ] }, "VgwTelemetry": [ { "AcceptedRouteCount": 0, "LastStatusChange": "2019-09-10T21:56:54.000Z", "OutsideIpAddress": "203.0.113.17", "Status": "DOWN", "StatusMessage": "IPSEC IS DOWN" }, { "AcceptedRouteCount": 0, "LastStatusChange": "2019-09-10T21:56:43.000Z", "OutsideIpAddress": "203.0.114.19", "Status": "DOWN", "StatusMessage": "IPSEC IS DOWN" } ] } }

以下代码示例演示如何使用 monitor-instances

AWS CLI

启用对实例的详细监控

本示例命令启用对指定实例的详细监控。

命令:

aws ec2 monitor-instances --instance-ids i-1234567890abcdef0

输出:

{ "InstanceMonitorings": [ { "InstanceId": "i-1234567890abcdef0", "Monitoring": { "State": "pending" } } ] }

以下代码示例演示如何使用 move-address-to-vpc

AWS CLI

要将地址移至 EC2-VPC

此示例将弹性 IP 地址 54.123.4.56 移至-平台。EC2 VPC

命令:

aws ec2 move-address-to-vpc --public-ip 54.123.4.56

输出:

{ "Status": "MoveInProgress" }

以下代码示例演示如何使用 move-byoip-cidr-to-ipam

AWS CLI

要将 a 转移BYOIPCIDR到 IPAM

以下move-byoip-cidr-to-ipam示例将 a 传输BYOIPCIDR到IPAM。

(Linux):

aws ec2 move-byoip-cidr-to-ipam \ --region us-west-2 \ --ipam-pool-id ipam-pool-0a03d430ca3f5c035 \ --ipam-pool-owner 111111111111 \ --cidr 130.137.249.0/24

(视窗):

aws ec2 move-byoip-cidr-to-ipam ^ --region us-west-2 ^ --ipam-pool-id ipam-pool-0a03d430ca3f5c035 ^ --ipam-pool-owner 111111111111 ^ --cidr 130.137.249.0/24

输出:

{ "ByoipCidr": { "Cidr": "130.137.249.0/24", "State": "pending-transfer" } }

有关更多信息,请参阅 Amazon VPC IPAM 用户指南IPAM中的教程:将现有转移BYOIPIPv4CIDR到

以下代码示例演示如何使用 network-insights-access-scope

AWS CLI

创建 “网络见解” 访问范围

以下create-network-insights-access-scope示例在您的 AWS 账户中创建网络见解访问范围。

aws ec2 create-network-insights-access-scope \ --cli-input-json file://access-scope-file.json

access-scope-file.json 的内容:

{ { "MatchPaths": [ { "Source": { "ResourceStatement": { "Resources": [ "vpc-abcd12e3" ] } } } ], "ExcludePaths": [ { "Source": { "ResourceStatement": { "ResourceTypes": [ "AWS::EC2::InternetGateway" ] } } } ] } }

输出:

{ "NetworkInsightsAccessScopeAnalysisId": "nisa-123456789111" }{ "NetworkInsightsAccessScope": { "NetworkInsightsAccessScopeId": "nis-123456789222", "NetworkInsightsAccessScopeArn": "arn:aws:ec2:us-east-1:123456789222:network-insights-access-scope/nis-123456789222", "CreatedDate": "2022-01-25T19:20:28.796000+00:00", "UpdatedDate": "2022-01-25T19:20:28.797000+00:00" }, "NetworkInsightsAccessScopeContent": { "NetworkInsightsAccessScopeId": "nis-04c0c0fbca737c404", "MatchPaths": [ { "Source": { "ResourceStatement": { "Resources": [ "vpc-abcd12e3" ] } } } ], "ExcludePaths": [ { "Source": { "ResourceStatement": { "ResourceTypes": [ "AWS::EC2::InternetGateway" ] } } } ] } }

有关更多信息,请参阅《网络访问分析器指南》 AWS CLI中的 “网络访问分析器入”。

以下代码示例演示如何使用 provision-byoip-cidr

AWS CLI

配置地址范围

以下provision-byoip-cidr示例预置了一个公有 IP 地址范围以供使用 AWS。

aws ec2 provision-byoip-cidr \ --cidr 203.0.113.25/24 \ --cidr-authorization-context Message="$text_message",Signature="$signed_message"

输出:

{ "ByoipCidr": { "Cidr": "203.0.113.25/24", "State": "pending-provision" } }

有关为授权上下文创建消息字符串的更多信息,请参阅 Amazon EC2 用户指南中的自带 IP 地址

以下代码示例演示如何使用 provision-ipam-pool-cidr

AWS CLI

CIDR向IPAM池配置

以下provision-ipam-pool-cidr示例将 a 置CIDR于IPAM池中。

(Linux):

aws ec2 provision-ipam-pool-cidr \ --ipam-pool-id ipam-pool-0533048da7d823723 \ --cidr 10.0.0.0/24

(视窗):

aws ec2 provision-ipam-pool-cidr ^ --ipam-pool-id ipam-pool-0533048da7d823723 ^ --cidr 10.0.0.0/24

输出:

{ "IpamPoolCidr": { "Cidr": "10.0.0.0/24", "State": "pending-provision" } }

有关更多信息,请参阅《Amazon VPC IPAM 用户指南》中的CIDRs向池配置。

以下代码示例演示如何使用 purchase-host-reservation

AWS CLI

购买专用主机预留

此示例在您的账户中为指定的专用主机购买指定的专用主机预留服务。

命令:

aws ec2 purchase-host-reservation --offering-id hro-03f707bf363b6b324 --host-id-set h-013abcd2a00cbd123

输出:

{ "TotalHourlyPrice": "1.499", "Purchase": [ { "HourlyPrice": "1.499", "InstanceFamily": "m4", "PaymentOption": "NoUpfront", "HostIdSet": [ "h-013abcd2a00cbd123" ], "HostReservationId": "hr-0d418a3a4ffc669ae", "UpfrontPrice": "0.000", "Duration": 31536000 } ], "TotalUpfrontPrice": "0.000" }

以下代码示例演示如何使用 purchase-reserved-instances-offering

AWS CLI

购买预留实例产品

此示例命令说明了购买预留实例产品的情况,并指定了产品 ID 和实例数量。

命令:

aws ec2 purchase-reserved-instances-offering --reserved-instances-offering-id ec06327e-dd07-46ee-9398-75b5fexample --instance-count 3

输出:

{ "ReservedInstancesId": "af9f760e-6f91-4559-85f7-4980eexample" }

以下代码示例演示如何使用 purchase-scheduled-instances

AWS CLI

购买计划实例

此示例购买了计划实例。

命令:

aws ec2 purchase-scheduled-instances --purchase-requests file://purchase-request.json

购买请求.json:

[ { "PurchaseToken": "eyJ2IjoiMSIsInMiOjEsImMiOi...", "InstanceCount": 1 } ]

输出:

{ "ScheduledInstanceSet": [ { "AvailabilityZone": "us-west-2b", "ScheduledInstanceId": "sci-1234-1234-1234-1234-123456789012", "HourlyPrice": "0.095", "CreateDate": "2016-01-25T21:43:38.612Z", "Recurrence": { "OccurrenceDaySet": [ 1 ], "Interval": 1, "Frequency": "Weekly", "OccurrenceRelativeToEnd": false, "OccurrenceUnit": "" }, "Platform": "Linux/UNIX", "TermEndDate": "2017-01-31T09:00:00Z", "InstanceCount": 1, "SlotDurationInHours": 32, "TermStartDate": "2016-01-31T09:00:00Z", "NetworkPlatform": "EC2-VPC", "TotalScheduledInstanceHours": 1696, "NextSlotStartTime": "2016-01-31T09:00:00Z", "InstanceType": "c4.large" } ] }

以下代码示例演示如何使用 reboot-instances

AWS CLI

重启 Amazon EC2 实例

本示例将重启指定的实例。如果命令成功,则不返回任何输出。

命令:

aws ec2 reboot-instances --instance-ids i-1234567890abcdef5

有关更多信息,请参阅《Amazon Elastic Compute Cloud 用户指南》中的“重启实例”。

以下代码示例演示如何使用 register-image

AWS CLI

示例 1:AMI使用清单文件注册

以下register-image示例在 Amazon S3 中AMI使用指定的清单文件注册一个。

aws ec2 register-image \ --name my-image \ --image-location my-s3-bucket/myimage/image.manifest.xml

输出:

{ "ImageId": "ami-1234567890EXAMPLE" }

有关更多信息,请参阅《亚马逊EC2用户指南》中的亚马逊系统映像 (AMI)

示例 2:AMI使用根设备的快照注册

以下register-image示例AMI使用EBS根卷的指定快照注册为设备/dev/xvda。块储存设备映射还包括一个空的 100 GiB EBS 容量作为设备。/dev/xvdf

aws ec2 register-image \ --name my-image \ --root-device-name /dev/xvda \ --block-device-mappings DeviceName=/dev/xvda,Ebs={SnapshotId=snap-0db2cf683925d191f} DeviceName=/dev/xvdf,Ebs={VolumeSize=100}

输出:

{ "ImageId": "ami-1a2b3c4d5eEXAMPLE" }

有关更多信息,请参阅《亚马逊EC2用户指南》中的亚马逊系统映像 (AMI)

以下代码示例演示如何使用 register-instance-event-notification-attributes

AWS CLI

示例 1:在事件通知中包含所有标签

以下register-instance-event-notification-attributes示例包括事件通知中的所有标签。

aws ec2 register-instance-event-notification-attributes \ --instance-tag-attribute IncludeAllTagsOfInstance=true

输出:

{ "InstanceTagAttribute": { "InstanceTagKeys": [], "IncludeAllTagsOfInstance": true } }

有关更多信息,请参阅适用Linux 实例的 Amazon 弹性计算云用户指南中的实例计划事件

示例 2:在事件通知中包含特定标签

以下register-instance-event-notification-attributes示例在事件通知中包含指定的标签。如果IncludeAllTagsOfInstance是,则无法指定标签true

aws ec2 register-instance-event-notification-attributes \ --instance-tag-attribute InstanceTagKeys="tag-key1","tag-key2"

输出:

{ "InstanceTagAttribute": { "InstanceTagKeys": [ "tag-key1", "tag-key2" ], "IncludeAllTagsOfInstance": false } }

有关更多信息,请参阅适用Linux 实例的 Amazon 弹性计算云用户指南中的实例计划事件

以下代码示例演示如何使用 register-transit-gateway-multicase-group-sources

AWS CLI

向传输网关组播组注册源。

以下register-transit-gateway-multicast-group-sources示例将指定的网络接口组源注册到多播组。

aws ec2 register-transit-gateway-multicast-group-sources \ --transit-gateway-multicast-domain-id tgw-mcast-domain-0c4905cef79d6e597 \ --group-ip-address 224.0.1.0 \ --network-interface-ids eni-07f290fc3c090cbae

输出:

{ "RegisteredMulticastGroupSources": { "TransitGatewayMulticastDomainId": "tgw-mcast-domain-0c4905cef79d6e597", "RegisteredNetworkInterfaceIds": [ "eni-07f290fc3c090cbae" ], "GroupIpAddress": "224.0.1.0" } }

有关更多信息,请参阅 T AWS ransit Gateways 用户指南中的向组播组注册源

以下代码示例演示如何使用 register-transit-gateway-multicast-group-members

AWS CLI

查看有关传输网关组播域关联的信息

以下register-transit-gateway-multicast-group-members示例返回指定多播域的关联。

aws ec2 register-transit-gateway-multicast-group-members \ --transit-gateway-multicast-domain-id tgw-mcast-domain-0c4905cef79d6e597 \ --group-ip-address 224.0.1.0 \ --network-interface-ids eni-0e246d32695012e81

输出:

{ "RegisteredMulticastGroupMembers": { "TransitGatewayMulticastDomainId": "tgw-mcast-domain-0c4905cef79d6e597", "RegisteredNetworkInterfaceIds": [ "eni-0e246d32695012e81" ], "GroupIpAddress": "224.0.1.0" } }

有关更多信息,请参阅 T ransit Gateways 用户指南中的管理多播域

以下代码示例演示如何使用 register-transit-gateway-multicast-group-sources

AWS CLI

向传输网关组播组注册源。

以下register-transit-gateway-multicast-group-sources示例将指定的网络接口组源注册到多播组。

aws ec2 register-transit-gateway-multicast-group-sources \ --transit-gateway-multicast-domain-id tgw-mcast-domain-0c4905cef79d6e597 \ --group-ip-address 224.0.1.0 \ --network-interface-ids eni-07f290fc3c090cbae

输出:

{ "RegisteredMulticastGroupSources": { "TransitGatewayMulticastDomainId": "tgw-mcast-domain-0c4905cef79d6e597", "RegisteredNetworkInterfaceIds": [ "eni-07f290fc3c090cbae" ], "GroupIpAddress": "224.0.1.0" } }

有关更多信息,请参阅《传输网关指南》中的管理多播域

以下代码示例演示如何使用 reject-transit-gateway-peering-attachment

AWS CLI

拒绝传输网关对等连接

以下reject-transit-gateway-peering-attachment示例拒绝了指定的传输网关对等连接请求。该--region参数指定接受者中转网关所在的区域。

aws ec2 reject-transit-gateway-peering-attachment \ --transit-gateway-attachment-id tgw-attach-4455667788aabbccd \ --region us-east-2

输出:

{ "TransitGatewayPeeringAttachment": { "TransitGatewayAttachmentId": "tgw-attach-4455667788aabbccd", "RequesterTgwInfo": { "TransitGatewayId": "tgw-123abc05e04123abc", "OwnerId": "123456789012", "Region": "us-west-2" }, "AccepterTgwInfo": { "TransitGatewayId": "tgw-11223344aabbcc112", "OwnerId": "123456789012", "Region": "us-east-2" }, "State": "rejecting", "CreationTime": "2019-12-09T11:50:31.000Z" } }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 对等连接附件

以下代码示例演示如何使用 reject-transit-gateway-vpc-attachment

AWS CLI

拒绝传输网关VPC连接

以下reject-transit-gateway-vpc-attachment示例拒绝指定的传输网关VPC连接。

aws ec2 reject-transit-gateway-vpc-attachment \ --transit-gateway-attachment-id tgw-attach-0a34fe6b4fEXAMPLE

输出:

{ "TransitGatewayVpcAttachment": { "TransitGatewayAttachmentId": "tgw-attach-0a34fe6b4fEXAMPLE", "TransitGatewayId": "tgw-0262a0e521EXAMPLE", "VpcId": "vpc-07e8ffd50fEXAMPLE", "VpcOwnerId": "111122223333", "State": "pending", "SubnetIds": [ "subnet-0752213d59EXAMPLE" ], "CreationTime": "2019-07-10T17:33:46.000Z", "Options": { "DnsSupport": "enable", "Ipv6Support": "disable" } } }

有关更多信息,请参阅《公交网关指南》VPC中的公交网关附件

以下代码示例演示如何使用 reject-transit-gateway-vpc-attachments

AWS CLI

拒绝传输网关VPC连接

以下reject-transit-gateway-vpc-attachment示例拒绝指定的传输网关VPC连接。

aws ec2 reject-transit-gateway-vpc-attachment \ --transit-gateway-attachment-id tgw-attach-0a34fe6b4fEXAMPLE

输出:

{ "TransitGatewayVpcAttachment": { "TransitGatewayAttachmentId": "tgw-attach-0a34fe6b4fEXAMPLE", "TransitGatewayId": "tgw-0262a0e521EXAMPLE", "VpcId": "vpc-07e8ffd50fEXAMPLE", "VpcOwnerId": "111122223333", "State": "pending", "SubnetIds": [ "subnet-0752213d59EXAMPLE" ], "CreationTime": "2019-07-10T17:33:46.000Z", "Options": { "DnsSupport": "enable", "Ipv6Support": "disable" } } }

有关更多信息,请参阅《公交网关指南》VPC中的公交网关附件

以下代码示例演示如何使用 reject-vpc-endpoint-connections

AWS CLI

拒绝接口终端节点连接请求

此示例拒绝指定终端节点服务的指定端点连接请求。

命令:

aws ec2 reject-vpc-endpoint-connections --service-id vpce-svc-03d5ebb7d9579a2b3 --vpc-endpoint-ids vpce-0c1308d7312217abc

输出:

{ "Unsuccessful": [] }

以下代码示例演示如何使用 reject-vpc-peering-connection

AWS CLI

拒绝对VPC等连接

此示例拒绝了指定的对VPC等连接请求。

命令:

aws ec2 reject-vpc-peering-connection --vpc-peering-connection-id pcx-1a2b3c4d

输出:

{ "Return": true }

以下代码示例演示如何使用 release-address

AWS CLI

为 EC2-Classic 发布弹性 IP 地址

此示例释放弹性 IP 地址以用于 EC2-Classic 中的实例。如果命令成功,则不返回任何输出。

命令:

aws ec2 release-address --public-ip 198.51.100.0

要为 EC2-释放弹性 IP 地址 VPC

此示例释放弹性 IP 地址以供中的实例使用VPC。如果命令成功,则不返回任何输出。

命令:

aws ec2 release-address --allocation-id eipalloc-64d5890a

以下代码示例演示如何使用 release-hosts

AWS CLI

从您的账户中释放专用主机

从您的账户中释放专用主机。必须先停止或终止主机上的实例,然后才能释放主机。

命令:

aws ec2 release-hosts --host-id=h-0029d6e3cacf1b3da

输出:

{ "Successful": [ "h-0029d6e3cacf1b3da" ], "Unsuccessful": [] }

以下代码示例演示如何使用 release-ipam-pool-allocation

AWS CLI

发放资源IPAM池分配

在此示例中,您是一名IPAM委托管理员,他试图删除一个资源IPAM池,但收到一个错误,即在池有分配时您无法删除该池。您正在使用此命令来释放池分配。

请注意以下几点:

此命令只能用于自定义分配。要在不删除资源的情况下移除资源分配,请使用将其监控状态设置为 false modify-ipam-resource-cidr。要完成此请求,你需要IPAM池 ID,你可以用describe-ipam-pools它来获取。您还需要分配 ID,您可以通过它获得get-ipam-pool-allocations。如果您不想逐个删除分配,则可以使用 “删除池--cascade option时” 在删除IPAM池之前自动释放池中的所有分配。运行此命令之前有许多先决条件。有关更多信息,请参阅 Amazon VPC IPAM 用户指南--region中的释放分配。运行此命令的位置必须是分配所在IPAM池的语言环境。

以下release-ipam-pool-allocation示例释放资源IPAM池分配。

aws ec2 release-ipam-pool-allocation \ --ipam-pool-id ipam-pool-07bdd12d7c94e4693 \ --cidr 10.0.0.0/23 \ --ipam-pool-allocation-id ipam-pool-alloc-0e66a1f730da54791b99465b79e7d1e89 \ --region us-west-1

输出:

{ "Success": true }

释放分配后,您可能需要运行delete-ipam-pool

以下代码示例演示如何使用 replace-iam-instance-profile-association

AWS CLI

替换IAM实例的实例配置文件

此示例将关联iip-assoc-060bae234aac2e7fa所代表的IAM实例配置文件替换为名为的IAM实例配置文件AdminRole

aws ec2 replace-iam-instance-profile-association \ --iam-instance-profile Name=AdminRole \ --association-id iip-assoc-060bae234aac2e7fa

输出:

{ "IamInstanceProfileAssociation": { "InstanceId": "i-087711ddaf98f9489", "State": "associating", "AssociationId": "iip-assoc-0b215292fab192820", "IamInstanceProfile": { "Id": "AIPAJLNLDX3AMYZNWYYAY", "Arn": "arn:aws:iam::123456789012:instance-profile/AdminRole" } } }

以下代码示例演示如何使用 replace-network-acl-association

AWS CLI

替换与子网ACL关联的网络

此示例将指定网络ACL与指定网络关联的子网相关ACL联。

命令:

aws ec2 replace-network-acl-association --association-id aclassoc-e5b95c8c --network-acl-id acl-5fb85d36

输出:

{ "NewAssociationId": "aclassoc-3999875b" }

以下代码示例演示如何使用 replace-network-acl-entry

AWS CLI

替换网络ACL条目

此示例替换了指定网络的条目ACL。新的规则 100 允许从UDP端口 53 () 上从 203.0.113.12/24 进入任何关联子网的入口流量。DNS

命令:

aws ec2 replace-network-acl-entry --network-acl-id acl-5fb85d36 --ingress --rule-number 100 --protocol udp --port-range From=53,To=53 --cidr-block 203.0.113.12/24 --rule-action allow

以下代码示例演示如何使用 replace-route-table-association

AWS CLI

替换与子网关联的路由表

此示例将指定的路由表与指定路由表关联的子网相关联。

命令:

aws ec2 replace-route-table-association --association-id rtbassoc-781d0d1a --route-table-id rtb-22574640

输出:

{ "NewAssociationId": "rtbassoc-3a1f0f58" }

以下代码示例演示如何使用 replace-route

AWS CLI

替换路线

此示例替换了指定路由表中的指定路由。新路由与指定的路由相匹配,CIDR并将流量发送到指定的虚拟专用网关。如果命令成功,则不返回任何输出。

命令:

aws ec2 replace-route --route-table-id rtb-22574640 --destination-cidr-block 10.0.0.0/16 --gateway-id vgw-9a4cacf3

以下代码示例演示如何使用 replace-transit-gateway-route

AWS CLI

替换指定公交网关路由表中的指定路由

以下replace-transit-gateway-route示例替换了指定公交网关路由表中的路由。

aws ec2 replace-transit-gateway-route \ --destination-cidr-block 10.0.2.0/24 \ --transit-gateway-attachment-id tgw-attach-09b52ccdb5EXAMPLE \ --transit-gateway-route-table-id tgw-rtb-0a823edbdeEXAMPLE

输出:

{ "Route": { "DestinationCidrBlock": "10.0.2.0/24", "TransitGatewayAttachments": [ { "ResourceId": "vpc-4EXAMPLE", "TransitGatewayAttachmentId": "tgw-attach-09b52ccdb5EXAMPLE", "ResourceType": "vpc" } ], "Type": "static", "State": "active" } }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 路由表

以下代码示例演示如何使用 report-instance-status

AWS CLI

报告实例的状态反馈

此示例命令报告指定实例的状态反馈。

命令:

aws ec2 report-instance-status --instances i-1234567890abcdef0 --status impaired --reason-codes unresponsive

以下代码示例演示如何使用 request-spot-fleet

AWS CLI

请求子网中价格最低的 Spot 队列

此示例命令创建一个 Spot 队列请求,其中包含两个仅因子网而异的启动规格。竞价型队列以最低价格启动指定子网中的实例。如果实例以默认方式启动VPC,则默认情况下它们会收到一个公有 IP 地址。如果实例以非默认方式启动VPC,则默认情况下它们不会收到公有 IP 地址。

请注意,您不能在竞价型队列请求中指定来自同一可用区的不同子网。

命令:

aws ec2 request-spot-fleet --spot-fleet-request-config file://config.json

config.json:

{ "SpotPrice": "0.04", "TargetCapacity": 2, "IamFleetRole": "arn:aws:iam::123456789012:role/my-spot-fleet-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "SecurityGroups": [ { "GroupId": "sg-1a2b3c4d" } ], "InstanceType": "m3.medium", "SubnetId": "subnet-1a2b3c4d, subnet-3c4d5e6f", "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" } } ] }

输出:

{ "SpotFleetRequestId": "sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE" }

请求可用区内价格最低的 Spot 队列

此示例命令创建具有两个启动规格的 Spot 队列请求,这两个启动规格仅因可用区而异。竞价型队列以最低价格在指定可用区启动实例。如果您的账户VPC仅支持EC2,Amazon EC2 将在可用区的默认子网中启动竞价型实例。如果您的账户支持 EC2-Classic,则亚马逊EC2会在可用区中启动 EC2-Classic中的实例。

命令:

aws ec2 request-spot-fleet --spot-fleet-request-config file://config.json

config.json:

{ "SpotPrice": "0.04", "TargetCapacity": 2, "IamFleetRole": "arn:aws:iam::123456789012:role/my-spot-fleet-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "SecurityGroups": [ { "GroupId": "sg-1a2b3c4d" } ], "InstanceType": "m3.medium", "Placement": { "AvailabilityZone": "us-west-2a, us-west-2b" }, "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" } } ] }

在子网中启动竞价型实例并为其分配公有 IP 地址

此示例命令为以非VPC默认方式启动的实例分配公有地址。请注意,在指定网络接口时,必须使用该网络接口包括子网 ID 和安全组 ID。

命令:

aws ec2 request-spot-fleet --spot-fleet-request-config file://config.json

config.json:

{ "SpotPrice": "0.04", "TargetCapacity": 2, "IamFleetRole": "arn:aws:iam::123456789012:role/my-spot-fleet-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "InstanceType": "m3.medium", "NetworkInterfaces": [ { "DeviceIndex": 0, "SubnetId": "subnet-1a2b3c4d", "Groups": [ "sg-1a2b3c4d" ], "AssociatePublicIpAddress": true } ], "IamInstanceProfile": { "Arn": "arn:aws:iam::880185128111:instance-profile/my-iam-role" } } ] }

使用多元化分配策略请求 Spot 队列

此示例命令创建一个 Spot 队列请求,该请求使用多元化分配策略启动 30 个实例。启动规格因实例类型而异。竞价型队列按启动规格分配实例,因此每种类型有 10 个实例。

命令:

aws ec2 request-spot-fleet --spot-fleet-request-config file://config.json

config.json:

{ "SpotPrice": "0.70", "TargetCapacity": 30, "AllocationStrategy": "diversified", "IamFleetRole": "arn:aws:iam::123456789012:role/my-spot-fleet-role", "LaunchSpecifications": [ { "ImageId": "ami-1a2b3c4d", "InstanceType": "c4.2xlarge", "SubnetId": "subnet-1a2b3c4d" }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "m3.2xlarge", "SubnetId": "subnet-1a2b3c4d" }, { "ImageId": "ami-1a2b3c4d", "InstanceType": "r3.2xlarge", "SubnetId": "subnet-1a2b3c4d" } ] }

有关更多信息,请参阅 Amazon 弹性计算云用户指南中的竞价型队列请求。

以下代码示例演示如何使用 request-spot-instances

AWS CLI

请求竞价型实例

此示例命令为指定可用区中的五个实例创建一次性竞价型实例请求。如果您的账户VPC仅支持EC2,则 Amazon EC2 会在指定可用区的默认子网中启动实例。如果您的账户支持 EC2-Classic,则亚马逊EC2将在指定的可用区域中启动 EC2-Classic 中的实例。

命令:

aws ec2 request-spot-instances --spot-price "0.03" --instance-count 5 --type "one-time" --launch-specification file://specification.json

规格.json:

{ "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "SecurityGroupIds": [ "sg-1a2b3c4d" ], "InstanceType": "m3.medium", "Placement": { "AvailabilityZone": "us-west-2a" }, "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" } }

输出:

{ "SpotInstanceRequests": [ { "Status": { "UpdateTime": "2014-03-25T20:54:21.000Z", "Code": "pending-evaluation", "Message": "Your Spot request has been submitted for review, and is pending evaluation." }, "ProductDescription": "Linux/UNIX", "SpotInstanceRequestId": "sir-df6f405d", "State": "open", "LaunchSpecification": { "Placement": { "AvailabilityZone": "us-west-2a" }, "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "SecurityGroups": [ { "GroupName": "my-security-group", "GroupId": "sg-1a2b3c4d" } ], "Monitoring": { "Enabled": false }, "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" }, "InstanceType": "m3.medium" }, "Type": "one-time", "CreateTime": "2014-03-25T20:54:20.000Z", "SpotPrice": "0.050000" }, ... ] }

此示例命令为指定子网中的五个实例创建一次性竞价型实例请求。Amazon 在指定子网中EC2启动实例。如果VPC为非默认值VPC,则默认情况下实例不会收到公有 IP 地址。

命令:

aws ec2 request-spot-instances --spot-price "0.050" --instance-count 5 --type "one-time" --launch-specification file://specification.json

规格.json:

{ "ImageId": "ami-1a2b3c4d", "SecurityGroupIds": [ "sg-1a2b3c4d" ], "InstanceType": "m3.medium", "SubnetId": "subnet-1a2b3c4d", "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" } }

输出:

{ "SpotInstanceRequests": [ { "Status": { "UpdateTime": "2014-03-25T22:21:58.000Z", "Code": "pending-evaluation", "Message": "Your Spot request has been submitted for review, and is pending evaluation." }, "ProductDescription": "Linux/UNIX", "SpotInstanceRequestId": "sir-df6f405d", "State": "open", "LaunchSpecification": { "Placement": { "AvailabilityZone": "us-west-2a" } "ImageId": "ami-1a2b3c4d" "SecurityGroups": [ { "GroupName": "my-security-group", "GroupID": "sg-1a2b3c4d" } ] "SubnetId": "subnet-1a2b3c4d", "Monitoring": { "Enabled": false }, "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" }, "InstanceType": "m3.medium", }, "Type": "one-time", "CreateTime": "2014-03-25T22:21:58.000Z", "SpotPrice": "0.050000" }, ... ] }

此示例为您以非VPC默认方式启动的竞价型实例分配公有 IP 地址。请注意,在指定网络接口时,必须使用该网络接口包括子网 ID 和安全组 ID。

命令:

aws ec2 request-spot-instances --spot-price "0.050" --instance-count 1 --type "one-time" --launch-specification file://specification.json

规格.json:

{ "ImageId": "ami-1a2b3c4d", "KeyName": "my-key-pair", "InstanceType": "m3.medium", "NetworkInterfaces": [ { "DeviceIndex": 0, "SubnetId": "subnet-1a2b3c4d", "Groups": [ "sg-1a2b3c4d" ], "AssociatePublicIpAddress": true } ], "IamInstanceProfile": { "Arn": "arn:aws:iam::123456789012:instance-profile/my-iam-role" } }

以下代码示例演示如何使用 reset-address-attribute

AWS CLI

重置与弹性 IP 地址关联的域名属性

以下reset-address-attribute示例重置弹性 IP 地址的域名属性。

Linux:

aws ec2 reset-address-attribute \ --allocation-id eipalloc-abcdef01234567890 \ --attribute domain-name

Windows:

aws ec2 reset-address-attribute ^ --allocation-id eipalloc-abcdef01234567890 ^ --attribute domain-name

输出:

{ "Addresses": [ { "PublicIp": "192.0.2.0", "AllocationId": "eipalloc-abcdef01234567890", "PtrRecord": "example.com." "PtrRecordUpdate": { "Value": "example.net.", "Status": "PENDING" } ] }

要监控待处理的更改,请参阅《AWS CLI命令参考describe-addresses-attribute中的。

以下代码示例演示如何使用 reset-ebs-default-kms-key-id

AWS CLI

重置EBS加密CMK的默认设置

以下reset-ebs-default-kms-key-id示例重置当前区域中您的 AWS 账户CMK的默认EBS加密设置。

aws ec2 reset-ebs-default-kms-key-id

输出:

{ "KmsKeyId": "arn:aws:kms:us-west-2:123456789012:key/8c5b2c63-b9bc-45a3-a87a-5513eEXAMPLE" }

以下代码示例演示如何使用 reset-fpga-image-attribute

AWS CLI

重置 Amazon FPGA 图片的属性

此示例重置了指定AFI项的加载权限。

命令:

aws ec2 reset-fpga-image-attribute --fpga-image-id afi-0d123e123bfc85abc --attribute loadPermission

输出:

{ "Return": true }

以下代码示例演示如何使用 reset-image-attribute

AWS CLI

重置 launchPermission 属性

此示例将指定的launchPermission属性重置AMI为其默认值。默认情况下,AMIs是私有的。如果命令成功,则不返回任何输出。

命令:

aws ec2 reset-image-attribute --image-id ami-5731123e --attribute launchPermission

以下代码示例演示如何使用 reset-instance-attribute

AWS CLI

重置 sourceDestCheck 属性

此示例重置了指定实例的sourceDestCheck属性。该实例必须位于VPC. 如果命令成功,则不返回任何输出。

命令:

aws ec2 reset-instance-attribute --instance-id i-1234567890abcdef0 --attribute sourceDestCheck

重置内核属性

此示例重置了指定实例的kernel属性。该实例必须处于 stopped 状态。如果命令成功,则不返回任何输出。

命令:

aws ec2 reset-instance-attribute --instance-id i-1234567890abcdef0 --attribute kernel

重置 ramdisk 属性

此示例重置了指定实例的ramdisk属性。该实例必须处于 stopped 状态。如果命令成功,则不返回任何输出。

命令:

aws ec2 reset-instance-attribute --instance-id i-1234567890abcdef0 --attribute ramdisk

以下代码示例演示如何使用 reset-network-interface-attribute

AWS CLI

重置网络接口属性

以下reset-network-interface-attribute示例将源/目标检查属性的值重置为。true

aws ec2 reset-network-interface-attribute \ --network-interface-id eni-686ea200 \ --source-dest-check

此命令不生成任何输出。

以下代码示例演示如何使用 reset-snapshot-attribute

AWS CLI

重置快照属性

此示例重置了快照snap-1234567890abcdef0的创建卷权限。如果命令成功,则不返回任何输出。

命令:

aws ec2 reset-snapshot-attribute --snapshot-id snap-1234567890abcdef0 --attribute createVolumePermission

以下代码示例演示如何使用 restore-address-to-classic

AWS CLI

将地址恢复为 EC2-Classic

此示例将弹性 IP 地址 198.51.100.0 恢复到-Classic 平台。EC2

命令:

aws ec2 restore-address-to-classic --public-ip 198.51.100.0

输出:

{ "Status": "MoveInProgress", "PublicIp": "198.51.100.0" }

以下代码示例演示如何使用 restore-image-from-recycle-bin

AWS CLI

从回收站恢复图像

以下restore-image-from-recycle-bin示例从回收站中恢复 AMI ami-0111222333444abcd。

aws ec2 restore-image-from-recycle-bin \ --image-id ami-0111222333444abcd

输出:

{ "Return": true }

有关更多信息,请参阅 Amazon 弹性计算云用户指南中的AMIs从回收站恢复

以下代码示例演示如何使用 restore-managed-prefix-list-version

AWS CLI

us-west-2**用于恢复前缀列表版本**

以下内容restore-managed-prefix-list-version恢复了指定前缀列表的版本 1 中的条目。

aws ec2 restore-managed-prefix-list-version \ --prefix-list-id pl-0123456abcabcabc1 \ --current-version 2 \ --previous-version 1

输出:

{ "PrefixList": { "PrefixListId": "pl-0123456abcabcabc1", "AddressFamily": "IPv4", "State": "restore-in-progress", "PrefixListArn": "arn:aws:ec2:us-west-2:123456789012:prefix-list/pl-0123456abcabcabc1", "PrefixListName": "vpc-cidrs", "MaxEntries": 10, "Version": 2, "OwnerId": "123456789012" } }

有关更多信息,请参阅 Amazon VPC 用户指南中的托管前缀列表

以下代码示例演示如何使用 restore-snapshot-from-recycle-bin

AWS CLI

从回收站恢复快照

以下restore-snapshot-from-recycle-bin示例从回收站恢复快照。从回收站还原快照时,该快照立即可供使用,回收站会将其删除。还原快照后,您可以像使用账户中任何其它快照一样使用它。

aws ec2 restore-snapshot-from-recycle-bin \ --snapshot-id snap-01234567890abcdef

此命令不生成任何输出。

有关亚马逊回收站的更多信息EBS,请参阅亚马逊EC2用户指南》中的从回收站恢复快照

以下代码示例演示如何使用 restore-snapshot-tier

AWS CLI

示例 1:永久恢复已存档的快照

以下restore-snapshot-tier示例永久恢复指定的快照。指定--snapshot-id并包括permanent-restore选项。

aws ec2 restore-snapshot-tier \ --snapshot-id snap-01234567890abcedf \ --permanent-restore

输出:

{ "SnapshotId": "snap-01234567890abcedf", "IsPermanentRestore": true }

有关快照存档的更多信息,请参阅亚马逊用户指南中的存档亚马逊EBS快照 <https://docs.aws.amazon.com/AWS EC2/latest/UserGuide/snapshot-archive.html>。EC2

示例 2:临时恢复已存档的快照

以下restore-snapshot-tier示例暂时恢复指定的快照。忽略 --permanent-restore 选项。指定--snapshot-id,对于temporary-restore-days,指定恢复快照的天数。 temporary-restore-days必须以天为单位指定。允许的范围1180。如果没有指定一个值,默认为 1 天。

aws ec2 restore-snapshot-tier \ --snapshot-id snap-01234567890abcedf \ --temporary-restore-days 5

输出:

{ "SnapshotId": "snap-01234567890abcedf", "RestoreDuration": 5, "IsPermanentRestore": false }

有关快照存档的更多信息,请参阅亚马逊用户指南中的存档亚马逊EBS快照 <https://docs.aws.amazon.com/AWS EC2/latest/UserGuide/snapshot-archive.html>。EC2

示例 3:修改还原周期

以下restore-snapshot-tier示例将指定快照的还原周期更改为10天。

aws ec2 restore-snapshot-tier \ --snapshot-id snap-01234567890abcedf --temporary-restore-days 10

输出:

{ "SnapshotId": "snap-01234567890abcedf", "RestoreDuration": 10, "IsPermanentRestore": false }

有关快照存档的更多信息,请参阅亚马逊用户指南中的存档亚马逊EBS快照 <https://docs.aws.amazon.com/AWS EC2/latest/UserGuide/snapshot-archive.html>。EC2

示例 4:修改还原类型

以下restore-snapshot-tier示例将指定快照的还原类型从临时更改为永久。

aws ec2 restore-snapshot-tier \ --snapshot-id snap-01234567890abcedf --permanent-restore

输出:

{ "SnapshotId": "snap-01234567890abcedf", "IsPermanentRestore": true }

有关快照存档的更多信息,请参阅亚马逊用户指南中的存档亚马逊EBS快照 <https://docs.aws.amazon.com/AWS EC2/latest/UserGuide/snapshot-archive.html>。EC2

以下代码示例演示如何使用 revoke-client-vpn-ingress

AWS CLI

撤消客户端VPN终端节点的授权规则

以下revoke-client-vpn-ingress示例撤消了所有群组的互联网访问规则 (0.0.0.0/0)。

aws ec2 revoke-client-vpn-ingress \ --client-vpn-endpoint-id cvpn-endpoint-123456789123abcde \ --target-network-cidr 0.0.0.0/0 --revoke-all-groups

输出:

{ "Status": { "Code": "revoking" } }

有关更多信息,请参阅《AWS 客户机VPN管理员指南》中的授权规则

以下代码示例演示如何使用 revoke-security-group-egress

AWS CLI

示例 1:删除允许出站流量到达特定地址范围的规则

以下revoke-security-group-egress示例命令删除了在TCP端口 80 上授予对指定地址范围的访问权限的规则。

aws ec2 revoke-security-group-egress \ --group-id sg-026c12253ce15eff7 \ --ip-permissions [{IpProtocol=tcp,FromPort=80,ToPort=80,IpRanges=[{CidrIp=10.0.0.0/16}]

此命令不生成任何输出。

有关更多信息,请参阅 Amazon EC2 用户指南中的安全组

示例 2:移除允许向特定安全组发送出站流量的规则

以下revoke-security-group-egress示例命令删除了在TCP端口 80 上授予对指定安全组的访问权限的规则。

aws ec2 revoke-security-group-egress \ --group-id sg-026c12253ce15eff7 \ --ip-permissions '[{"IpProtocol": "tcp", "FromPort": 443, "ToPort": 443,"UserIdGroupPairs": [{"GroupId": "sg-06df23a01ff2df86d"}]}]'

此命令不生成任何输出。

有关更多信息,请参阅 Amazon EC2 用户指南中的安全组

以下代码示例演示如何使用 revoke-security-group-ingress

AWS CLI

示例 1:从安全组中移除规则

以下revoke-security-group-ingress示例默认从指定的安全组中删除该203.0.113.0/24地址范围的TCP端口 22 访问权限VPC。

aws ec2 revoke-security-group-ingress \ --group-name mySecurityGroup --protocol tcp \ --port 22 \ --cidr 203.0.113.0/24

如果成功执行此命令,则不会产生任何输出。

有关更多信息,请参阅 Amazon EC2 用户指南中的安全组

示例 2:使用 IP 权限集删除规则

以下revoke-security-group-ingress示例使用ip-permissions参数删除允许ICMP发送消息的入站规则Destination Unreachable: Fragmentation Needed and Don't Fragment was Set(类型 3,代码 4)。

aws ec2 revoke-security-group-ingress \ --group-id sg-026c12253ce15eff7 \ --ip-permissions IpProtocol=icmp,FromPort=3,ToPort=4,IpRanges=[{CidrIp=0.0.0.0/0}]

如果成功执行此命令,则不会产生任何输出。

有关更多信息,请参阅 Amazon EC2 用户指南中的安全组

以下代码示例演示如何使用 run-instances

AWS CLI

示例 1:将实例启动到默认子网

以下run-instances示例在当前区域的默认子网中启动一个类型的t2.micro实例,并将其与该区域VPC的默认子网关联起来。如果您不打算使用 SSH (Linux) 或 RDP (Windows) 连接到您的实例,则密钥对是可选的。

aws ec2 run-instances \ --image-id ami-0abcdef1234567890 \ --instance-type t2.micro \ --key-name MyKeyPair

输出:

{ "Instances": [ { "AmiLaunchIndex": 0, "ImageId": "ami-0abcdef1234567890", "InstanceId": "i-1231231230abcdef0", "InstanceType": "t2.micro", "KeyName": "MyKeyPair", "LaunchTime": "2018-05-10T08:05:20.000Z", "Monitoring": { "State": "disabled" }, "Placement": { "AvailabilityZone": "us-east-2a", "GroupName": "", "Tenancy": "default" }, "PrivateDnsName": "ip-10-0-0-157.us-east-2.compute.internal", "PrivateIpAddress": "10.0.0.157", "ProductCodes": [], "PublicDnsName": "", "State": { "Code": 0, "Name": "pending" }, "StateTransitionReason": "", "SubnetId": "subnet-04a636d18e83cfacb", "VpcId": "vpc-1234567890abcdef0", "Architecture": "x86_64", "BlockDeviceMappings": [], "ClientToken": "", "EbsOptimized": false, "Hypervisor": "xen", "NetworkInterfaces": [ { "Attachment": { "AttachTime": "2018-05-10T08:05:20.000Z", "AttachmentId": "eni-attach-0e325c07e928a0405", "DeleteOnTermination": true, "DeviceIndex": 0, "Status": "attaching" }, "Description": "", "Groups": [ { "GroupName": "MySecurityGroup", "GroupId": "sg-0598c7d356eba48d7" } ], "Ipv6Addresses": [], "MacAddress": "0a:ab:58:e0:67:e2", "NetworkInterfaceId": "eni-0c0a29997760baee7", "OwnerId": "123456789012", "PrivateDnsName": "ip-10-0-0-157.us-east-2.compute.internal", "PrivateIpAddress": "10.0.0.157", "PrivateIpAddresses": [ { "Primary": true, "PrivateDnsName": "ip-10-0-0-157.us-east-2.compute.internal", "PrivateIpAddress": "10.0.0.157" } ], "SourceDestCheck": true, "Status": "in-use", "SubnetId": "subnet-04a636d18e83cfacb", "VpcId": "vpc-1234567890abcdef0", "InterfaceType": "interface" } ], "RootDeviceName": "/dev/xvda", "RootDeviceType": "ebs", "SecurityGroups": [ { "GroupName": "MySecurityGroup", "GroupId": "sg-0598c7d356eba48d7" } ], "SourceDestCheck": true, "StateReason": { "Code": "pending", "Message": "pending" }, "Tags": [], "VirtualizationType": "hvm", "CpuOptions": { "CoreCount": 1, "ThreadsPerCore": 1 }, "CapacityReservationSpecification": { "CapacityReservationPreference": "open" }, "MetadataOptions": { "State": "pending", "HttpTokens": "optional", "HttpPutResponseHopLimit": 1, "HttpEndpoint": "enabled" } } ], "OwnerId": "123456789012", "ReservationId": "r-02a3f596d91211712" }

示例 2:将实例启动到非默认子网,并添加一个公有 IP 地址

以下 run-instances 示例为要启动到非默认子网的实例请求一个公有 IP 地址。实例与指定的安全组相关联。

aws ec2 run-instances \ --image-id ami-0abcdef1234567890 \ --instance-type t2.micro \ --subnet-id subnet-08fc749671b2d077c \ --security-group-ids sg-0b0384b66d7d692f9 \ --associate-public-ip-address \ --key-name MyKeyPair

有关 run-instances 的输出示例,请参阅示例 1。

示例 3:启动具有附加卷的实例

以下 run-instances 示例使用 mapping.json 中指定的块设备映射,在启动时对附加卷进行附加。块储存设备映射可以指定EBS卷、实例存储卷或同时指定EBS卷和实例存储卷。

aws ec2 run-instances \ --image-id ami-0abcdef1234567890 \ --instance-type t2.micro \ --subnet-id subnet-08fc749671b2d077c \ --security-group-ids sg-0b0384b66d7d692f9 \ --key-name MyKeyPair \ --block-device-mappings file://mapping.json

mapping.json 的内容。此示例添加/dev/sdh了一个大小为 100 GiB 的空EBS卷。

[ { "DeviceName": "/dev/sdh", "Ebs": { "VolumeSize": 100 } } ]

mapping.json 的内容。本示例添加了 ephemeral1,作为实例存储卷。

[ { "DeviceName": "/dev/sdc", "VirtualName": "ephemeral1" } ]

有关 run-instances 的输出示例,请参阅示例 1。

有关块储存设备映射的更多信息,请参阅 Amazon EC2 用户指南中的块储存设备映射

示例 4:启动实例并在创建时添加标签

以下 run-instances 示例向实例中添加了一个键为 webserver、值为 production 的标签。该命令还会将密钥为cost-center、值为的cc123标签应用于已创建的任何EBS卷(在本例中为根卷)。

aws ec2 run-instances \ --image-id ami-0abcdef1234567890 \ --instance-type t2.micro \ --count 1 \ --subnet-id subnet-08fc749671b2d077c \ --key-name MyKeyPair \ --security-group-ids sg-0b0384b66d7d692f9 \ --tag-specifications 'ResourceType=instance,Tags=[{Key=webserver,Value=production}]' 'ResourceType=volume,Tags=[{Key=cost-center,Value=cc123}]'

有关 run-instances 的输出示例,请参阅示例 1。

示例 5:启动包含用户数据的实例

以下 run-instances 示例在名为 my_script.txt 的文件中传递用户数据,该文件包含实例的配置脚本。该脚本在启动时运行。

aws ec2 run-instances \ --image-id ami-0abcdef1234567890 \ --instance-type t2.micro \ --count 1 \ --subnet-id subnet-08fc749671b2d077c \ --key-name MyKeyPair \ --security-group-ids sg-0b0384b66d7d692f9 \ --user-data file://my_script.txt

有关 run-instances 的输出示例,请参阅示例 1。

有关实例用户数据的更多信息,请参阅 Amazon 用户指南中的使用实例EC2用户数据

示例 6:启动可突增性能实例

以下 run-instances 示例启动带有 unlimited 服务抵扣金选项的 t2.micro 实例。当启动 T2 实例时,如果未指定 --credit-specification,则默认为 standard 服务抵扣金选项。当启动 T3 实例时,默认为 unlimited 服务抵扣金选项。

aws ec2 run-instances \ --image-id ami-0abcdef1234567890 \ --instance-type t2.micro \ --count 1 \ --subnet-id subnet-08fc749671b2d077c \ --key-name MyKeyPair \ --security-group-ids sg-0b0384b66d7d692f9 \ --credit-specification CpuCredits=unlimited

有关 run-instances 的输出示例,请参阅示例 1。

有关突发性能实例的更多信息,请参阅 A mazon EC2 用户指南中的突增性能实例

以下代码示例演示如何使用 run-scheduled-instances

AWS CLI

启动计划实例

此示例在中启动指定的计划实例VPC。

命令:

aws ec2 run-scheduled-instances --scheduled-instance-id sci-1234-1234-1234-1234-123456789012 --instance-count 1 --launch-specification file://launch-specification.json

启动规范.json:

{ "ImageId": "ami-12345678", "KeyName": "my-key-pair", "InstanceType": "c4.large", "NetworkInterfaces": [ { "DeviceIndex": 0, "SubnetId": "subnet-12345678", "AssociatePublicIpAddress": true, "Groups": ["sg-12345678"] } ], "IamInstanceProfile": { "Name": "my-iam-role" } }

输出:

{ "InstanceIdSet": [ "i-1234567890abcdef0" ] }

此示例在 EC2-Classic 中启动指定的计划实例。

命令:

aws ec2 run-scheduled-instances --scheduled-instance-id sci-1234-1234-1234-1234-123456789012 --instance-count 1 --launch-specification file://launch-specification.json

启动规范.json:

{ "ImageId": "ami-12345678", "KeyName": "my-key-pair", "SecurityGroupIds": ["sg-12345678"], "InstanceType": "c4.large", "Placement": { "AvailabilityZone": "us-west-2b" } "IamInstanceProfile": { "Name": "my-iam-role" } }

输出:

{ "InstanceIdSet": [ "i-1234567890abcdef0" ] }

以下代码示例演示如何使用 search-local-gateway-routes

AWS CLI

在本地网关路由表中搜索路由

以下search-local-gateway-routes示例在指定的本地网关路由表中搜索静态路由。

aws ec2 search-local-gateway-routes \ --local-gateway-route-table-id lgw-rtb-059615ef7dEXAMPLE \ --filters "Name=type,Values=static"

输出:

{ "Route": { "DestinationCidrBlock": "0.0.0.0/0", "LocalGatewayVirtualInterfaceGroupId": "lgw-vif-grp-07145b276bEXAMPLE", "Type": "static", "State": "deleted", "LocalGatewayRouteTableId": "lgw-rtb-059615ef7EXAMPLE" } }

以下代码示例演示如何使用 search-transit-gateway-multicast-groups

AWS CLI

搜索一个或多个公交网关组播组并返回组成员资格信息

以下search-transit-gateway-multicast-groups示例返回指定多播组的组成员资格。

aws ec2 search-transit-gateway-multicast-groups \ --transit-gateway-multicast-domain-id tgw-mcast-domain-000fb24d04EXAMPLE

输出:

{ "MulticastGroups": [ { "GroupIpAddress": "224.0.1.0", "TransitGatewayAttachmentId": "tgw-attach-0372e72386EXAMPLE", "SubnetId": "subnet-0187aff814EXAMPLE", "ResourceId": "vpc-0065acced4EXAMPLE", "ResourceType": "vpc", "NetworkInterfaceId": "eni-03847706f6EXAMPLE", "GroupMember": false, "GroupSource": true, "SourceType": "static" } ] }

有关更多信息,请参阅《传输网关指南》中的管理多播组

以下代码示例演示如何使用 search-transit-gateway-routes

AWS CLI

在指定的公交网关路由表中搜索路由

以下search-transit-gateway-routes示例返回指定路由表static中所有类型的路由。

aws ec2 search-transit-gateway-routes \ --transit-gateway-route-table-id tgw-rtb-0a823edbdeEXAMPLE \ --filters "Name=type,Values=static"

输出:

{ "Routes": [ { "DestinationCidrBlock": "10.0.2.0/24", "TransitGatewayAttachments": [ { "ResourceId": "vpc-4EXAMPLE", "TransitGatewayAttachmentId": "tgw-attach-09b52ccdb5EXAMPLE", "ResourceType": "vpc" } ], "Type": "static", "State": "active" }, { "DestinationCidrBlock": "10.1.0.0/24", "TransitGatewayAttachments": [ { "ResourceId": "vpc-4EXAMPLE", "TransitGatewayAttachmentId": "tgw-attach-09b52ccdb5EXAMPLE", "ResourceType": "vpc" } ], "Type": "static", "State": "active" } ], "AdditionalRoutesAvailable": false }

有关更多信息,请参阅《公交网关指南》中的 Transit Gateway 路由表

以下代码示例演示如何使用 send-diagnostic-interrupt

AWS CLI

发送诊断中断

以下send-diagnostic-interrupt示例向指定实例发送诊断中断。

aws ec2 send-diagnostic-interrupt \ --instance-id i-1234567890abcdef0

此命令不生成任何输出。

以下代码示例演示如何使用 start-instances

AWS CLI

启动 Amazon EC2 实例

此示例启动由 Amazon EBS 支持的指定实例。

命令:

aws ec2 start-instances --instance-ids i-1234567890abcdef0

输出:

{ "StartingInstances": [ { "InstanceId": "i-1234567890abcdef0", "CurrentState": { "Code": 0, "Name": "pending" }, "PreviousState": { "Code": 80, "Name": "stopped" } } ] }

有关更多信息,请参阅《Amazon Elastic Compute Cloud 用户指南》中的“停止和启动实例”。

以下代码示例演示如何使用 start-network-insights-access-scope-analysis

AWS CLI

开始网络见解访问范围分析

以下start-network-insights-access-scope-analysis示例在您的 AWS 账户中启动范围分析。

aws ec2 start-network-insights-access-scope-analysis \ --region us-east-1 \ --network-insights-access-scope-id nis-123456789111

输出:

{ "NetworkInsightsAccessScopeAnalysis": { "NetworkInsightsAccessScopeAnalysisId": "nisa-123456789222", "NetworkInsightsAccessScopeAnalysisArn": "arn:aws:ec2:us-east-1:123456789012:network-insights-access-scope-analysis/nisa-123456789222", "NetworkInsightsAccessScopeId": "nis-123456789111", "Status": "running", "StartDate": "2022-01-26T00:47:06.814000+00:00" } }

有关更多信息,请参阅《网络访问分析器指南》 AWS CLI中的 “网络访问分析器入”。

以下代码示例演示如何使用 start-network-insights-analysis

AWS CLI

分析路径

以下start-network-insights-analysis示例分析了源和目标之间的路径。要查看路径分析的结果,请使用describe-network-insights-analyses命令。

aws ec2 start-network-insights-analysis \ --network-insights-path-id nip-0b26f224f1d131fa8

输出:

{ "NetworkInsightsAnalysis": { "NetworkInsightsAnalysisId": "nia-02207aa13eb480c7a", "NetworkInsightsAnalysisArn": "arn:aws:ec2:us-east-1:123456789012:network-insights-analysis/nia-02207aa13eb480c7a", "NetworkInsightsPathId": "nip-0b26f224f1d131fa8", "StartDate": "2021-01-20T22:58:37.495Z", "Status": "running" } }

有关更多信息,请参阅 Reach ability Analy AWS CLI zer 指南中的入门使用指南。

以下代码示例演示如何使用 start-vpc-endpoint-service-private-dns-verification

AWS CLI

启动DNS验证流程

以下start-vpc-endpoint-service-private-dns-verification示例启动指定终端节点服务的DNS验证过程。

aws ec2 start-vpc-endpoint-service-private-dns-verification \ --service-id vpce-svc-071afff70666e61e0

此命令不生成任何输出。

有关更多信息,请参阅《AWS PrivateLink 用户指南》中的管理DNS姓名

以下代码示例演示如何使用 stop-instances

AWS CLI

示例 1:停止 Amazon EC2 实例

以下stop-instances示例停止由 Amazon EBS 支持的指定实例。

aws ec2 stop-instances \ --instance-ids i-1234567890abcdef0

输出:

{ "StoppingInstances": [ { "InstanceId": "i-1234567890abcdef0", "CurrentState": { "Code": 64, "Name": "stopping" }, "PreviousState": { "Code": 16, "Name": "running" } } ] }

有关更多信息,请参阅《Amazon Elastic Compute Cloud 用户指南》中的停止和启动实例

示例 2:让 Amazon 实例处于休眠状态 EC2

如果由 Amazon EBS 支持的实例启用了休眠功能并且满足休眠先决条件,则以下stop-instances示例会使该实例休眠。实例进入休眠状态后,实例将停止。

aws ec2 stop-instances \ --instance-ids i-1234567890abcdef0 \ --hibernate

输出:

{ "StoppingInstances": [ { "CurrentState": { "Code": 64, "Name": "stopping" }, "InstanceId": "i-1234567890abcdef0", "PreviousState": { "Code": 16, "Name": "running" } } ] }

有关更多信息,请参阅《Amazon Elastic Cloud Compute 用户指南》中的休眠按需 Linux 实例

以下代码示例演示如何使用 terminate-client-vpn-connections

AWS CLI

终止与客户端终VPN端节点的连接

以下terminate-client-vpn-connections示例终止与客户端终VPN端节点的指定连接。

aws ec2 terminate-client-vpn-connections \ --client-vpn-endpoint-id vpn-endpoint-123456789123abcde \ --connection-id cvpn-connection-04edd76f5201e0cb8

输出:

{ "ClientVpnEndpointId": "vpn-endpoint-123456789123abcde", "ConnectionStatuses": [ { "ConnectionId": "cvpn-connection-04edd76f5201e0cb8", "PreviousStatus": { "Code": "active" }, "CurrentStatus": { "Code": "terminating" } } ] }

有关更多信息,请参阅《客户机VPN管理员指南》中的 “AWS 客户端连接”。

以下代码示例演示如何使用 terminate-instances

AWS CLI

终止 Amazon EC2 实例

本示例将终止指定的实例。

命令:

aws ec2 terminate-instances --instance-ids i-1234567890abcdef0

输出:

{ "TerminatingInstances": [ { "InstanceId": "i-1234567890abcdef0", "CurrentState": { "Code": 32, "Name": "shutting-down" }, "PreviousState": { "Code": 16, "Name": "running" } } ] }

有关更多信息,请参阅AWS 命令行界面用户指南中的使用 Amazon EC2 实例。

以下代码示例演示如何使用 unassign-ipv6-addresses

AWS CLI

取消分配给网络接口IPv6的地址

此示例从指定的网络接口取消指定IPv6地址的分配。

命令:

aws ec2 unassign-ipv6-addresses --ipv6-addresses 2001:db8:1234:1a00:3304:8879:34cf:4071 --network-interface-id eni-23c49b68

输出:

{ "NetworkInterfaceId": "eni-23c49b68", "UnassignedIpv6Addresses": [ "2001:db8:1234:1a00:3304:8879:34cf:4071" ] }
  • 有关API详细信息,请参阅《AWS CLI 命令参考》中的 UnassignIpv6Ad dresses。

以下代码示例演示如何使用 unassign-private-ip-addresses

AWS CLI

从网络接口取消分配辅助私有 IP 地址

此示例取消指定网络接口的指定私有 IP 地址的分配。如果命令成功,则不返回任何输出。

命令:

aws ec2 unassign-private-ip-addresses --network-interface-id eni-e5aa89a3 --private-ip-addresses 10.0.0.82

以下代码示例演示如何使用 unassign-private-nat-gateway-address

AWS CLI

从您的私有网关取消分配私有 IP 地址 NAT

以下unassign-private-nat-gateway-address示例取消指定私有网关的指定 IP 地址的分配。NAT

aws ec2 unassign-private-nat-gateway-address \ --nat-gateway-id nat-1234567890abcdef0 \ --private-ip-addresses 10.0.20.197

输出:

{ "NatGatewayId": "nat-0ee3edd182361f662", "NatGatewayAddresses": [ { "NetworkInterfaceId": "eni-0065a61b324d1897a", "PrivateIp": "10.0.20.197", "IsPrimary": false, "Status": "unassigning" } ] }

有关更多信息,请参阅 Amazon VPC 用户指南中的NAT网关

以下代码示例演示如何使用 unlock-snapshot

AWS CLI

解锁快照

以下unlock-snapshot示例解锁指定的快照。

aws ec2 unlock-snapshot \ --snapshot-id snap-0b5e733b4a8df6e0d

输出:

{ "SnapshotId": "snap-0b5e733b4a8df6e0d" }

有关更多信息,请参阅 Amazon EBS 用户指南中的快照锁

以下代码示例演示如何使用 unmonitor-instances

AWS CLI

禁用对实例的详细监控

本示例命令禁用对指定实例的详细监控。

命令:

aws ec2 unmonitor-instances --instance-ids i-1234567890abcdef0

输出:

{ "InstanceMonitorings": [ { "InstanceId": "i-1234567890abcdef0", "Monitoring": { "State": "disabling" } } ] }

以下代码示例演示如何使用 update-security-group-rule-descriptions-egress

AWS CLI

更新出站安全组规则的描述

以下update-security-group-rule-descriptions-egress示例更新了指定端口和IPv4地址范围的安全组规则的描述。描述 “Outbound HTTP access to server 2” 取代了该规则的所有现有描述。

aws ec2 update-security-group-rule-descriptions-egress \ --group-id sg-02f0d35a850ba727f \ --ip-permissions IpProtocol=tcp,FromPort=80,ToPort=80,IpRanges=[{CidrIp=203.0.113.0/24,Description="Outbound HTTP access to server 2"}]

输出:

{ "Return": true }

有关更多信息,请参阅 Amazon EC2 用户指南中的安全组规则

以下代码示例演示如何使用 update-security-group-rule-descriptions-ingress

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

以下代码示例演示如何使用 withdraw-byoip-cidr

AWS CLI

停止发布地址范围的广告

以下withdraw-byoip-cidr示例停止发布指定地址范围。

aws ec2 withdraw-byoip-cidr --cidr 203.0.113.25/24

输出:

{ "ByoipCidr": { "Cidr": "203.0.113.25/24", "StatusMessage": "ipv4pool-ec2-1234567890abcdef0", "State": "advertised" } }