Skip to content

Commit

Permalink
Rust: Add proper hello-world for Aurora (awsdocs#5605)
Browse files Browse the repository at this point in the history
* Rust: Add proper hello-world for Aurora
  • Loading branch information
DavidSouther authored and max-webster committed Mar 15, 2024
1 parent c87ec83 commit 5e97701
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
6 changes: 2 additions & 4 deletions .doc_gen/metadata/aurora_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ aurora_Hello:
- sdk_version: 1
github: rust_dev_preview/examples/aurora
excerpts:
- snippet_tags:
- rust.aurora.get_cluster.usage
- rust.aurora.describe_db_clusters.wrapper
- rust.aurora.get_cluster.test
- snippet_files:
- rust_dev_preview/examples/aurora/src/bin/hello-world.rs
services:
aurora: {DescribeDBClusters}
aurora_DescribeDBClusterParameterGroups:
Expand Down
39 changes: 39 additions & 0 deletions rust_dev_preview/examples/aurora/src/bin/hello-world.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use aws_sdk_rds::Client;

#[derive(Debug)]
struct Error(String);
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl std::error::Error for Error {}

#[tokio::main]
async fn main() -> Result<(), Error> {
tracing_subscriber::fmt::init();
let sdk_config = aws_config::from_env().load().await;
let client = Client::new(&sdk_config);

let describe_db_clusters_output = client
.describe_db_clusters()
.send()
.await
.map_err(|e| Error(e.to_string()))?;
println!(
"Found {} clusters:",
describe_db_clusters_output.db_clusters().len()
);
for cluster in describe_db_clusters_output.db_clusters() {
let name = cluster.database_name().unwrap_or("Unknown");
let engine = cluster.engine().unwrap_or("Unknown");
let id = cluster.db_cluster_identifier().unwrap_or("Unknown");
let class = cluster.db_cluster_instance_class().unwrap_or("Unknown");
println!("\tDatabase: {name}",);
println!("\t Engine: {engine}",);
println!("\t ID: {id}",);
println!("\tInstance: {class}",);
}

Ok(())
}

0 comments on commit 5e97701

Please sign in to comment.