Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Describe one or more Amazon EBS snapshots using an Amazon SDK
The following code example shows how to describe Amazon EBS snapshots.
- Rust
-
- SDK for Rust
-
This documentation is for an SDK in preview release. The SDK is subject to change and should not be used in production.
Shows the state of a snapshot.
async fn show_state(client: &Client, id: &str) -> Result<(), Error> {
let resp = client
.describe_snapshots()
.filters(Filter::builder().name("snapshot-id").values(id).build())
.send()
.await?;
println!(
"State: {}",
resp.snapshots()
.unwrap()
.first()
.unwrap()
.state()
.unwrap()
.as_ref()
);
Ok(())
}
async fn show_snapshots(client: &Client) -> Result<(), Error> {
// "self" represents your account ID.
// You can list the snapshots for any account by replacing
// "self" with that account ID.
let resp = client.describe_snapshots().owner_ids("self").send().await?;
let snapshots = resp.snapshots().unwrap();
let length = snapshots.len();
for snapshot in snapshots {
println!(
"ID: {}",
snapshot.snapshot_id().unwrap_or_default()
);
println!(
"Description: {}",
snapshot.description().unwrap_or_default()
);
println!("State: {}", snapshot.state().unwrap().as_ref());
println!();
}
println!();
println!("Found {} snapshot(s)", length);
println!();
Ok(())
}
For a complete list of Amazon SDK developer guides and code examples, see
Using this service with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.