与 AWS SDK或DescribeInstanceStatus一起使用 CLI - Amazon Elastic Compute Cloud

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

与 AWS SDK或DescribeInstanceStatus一起使用 CLI

以下代码示例演示如何使用 DescribeInstanceStatus

CLI
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 用户指南中的监控实例状态

PowerShell
用于 PowerShell

示例 1:此示例描述了指定实例的状态。

Get-EC2InstanceStatus -InstanceId i-12345678

输出:

AvailabilityZone : us-west-2a Events : {} InstanceId : i-12345678 InstanceState : Amazon.EC2.Model.InstanceState Status : Amazon.EC2.Model.InstanceStatusSummary SystemStatus : Amazon.EC2.Model.InstanceStatusSummary
$status = Get-EC2InstanceStatus -InstanceId i-12345678 $status.InstanceState

输出:

Code Name ---- ---- 16 running
$status.Status

输出:

Details Status ------- ------ {reachability} ok
$status.SystemStatus

输出:

Details Status ------- ------ {reachability} ok
Rust
SDK对于 Rust
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

async fn show_all_events(client: &Client) -> Result<(), Error> { let resp = client.describe_regions().send().await.unwrap(); for region in resp.regions.unwrap_or_default() { let reg: &'static str = Box::leak(Box::from(region.region_name().unwrap())); let region_provider = RegionProviderChain::default_provider().or_else(reg); let config = aws_config::from_env().region(region_provider).load().await; let new_client = Client::new(&config); let resp = new_client.describe_instance_status().send().await; println!("Instances in region {}:", reg); println!(); for status in resp.unwrap().instance_statuses() { println!( " Events scheduled for instance ID: {}", status.instance_id().unwrap_or_default() ); for event in status.events() { println!(" Event ID: {}", event.instance_event_id().unwrap()); println!(" Description: {}", event.description().unwrap()); println!(" Event code: {}", event.code().unwrap().as_ref()); println!(); } } } Ok(()) }

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