Skip to content

Commit

Permalink
Refactored RDS data code example (#561)
Browse files Browse the repository at this point in the history
* Refactored RDS data code examples to use common example pattern; re-ordered crates in Cargo.toml

* Updated RDSData helloworld code example to use ? instead of expect()
  • Loading branch information
Doug-AWS committed Jun 30, 2021
1 parent 710cde4 commit cdee93b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
1 change: 0 additions & 1 deletion aws/sdk/examples/rdsdata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ version = "0.1.0"
[dependencies]
rdsdata = {package = "aws-sdk-rdsdata", path = "../../build/aws-sdk/rdsdata"}
aws-types = { path = "../../build/aws-sdk/aws-types" }

tokio = {version = "1", features = ["full"]}
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
44 changes: 21 additions & 23 deletions aws/sdk/examples/rdsdata/src/bin/rdsdata-helloworld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,29 @@
* SPDX-License-Identifier: Apache-2.0.
*/

use rdsdata::{Client, Config, Region};

use aws_types::region::ProvideRegion;

use rdsdata::{Client, Config, Error, Region, PKG_VERSION};
use structopt::StructOpt;
use tracing_subscriber::fmt::format::FmtSpan;
use tracing_subscriber::fmt::SubscriberBuilder;

#[derive(Debug, StructOpt)]
struct Opt {
/// The region. Overrides environment variable AWS_DEFAULT_REGION.
/// The default AWS Region.
#[structopt(short, long)]
default_region: Option<String>,

/// The SQL query string
/// The SQL query string.
#[structopt(short, long)]
query: String,

/// The ARN of your Aurora serverless DB cluster
/// The ARN of your Aurora serverless DB cluster.
#[structopt(short, long)]
resource_arn: String,

/// The ARN of the Secrets Manager secret
/// The ARN of the Secrets Manager secret.
#[structopt(short, long)]
secret_arn: String,

/// Whether to display additional runtime information
/// Whether to display additional information.
#[structopt(short, long)]
verbose: bool,
}
Expand All @@ -44,12 +40,14 @@ struct Opt {
/// It should look something like __arn:aws:rds:us-west-2:AWS_ACCOUNT:cluster:database-2__.
/// * `-s SECRET_ARN` - The ARN of the Secrets Manager secret.
/// It should look something like: __arn:aws:secretsmanager:us-west-2:AWS_ACCOUNT:secret:database2/test/postgres-b8maVb__.
/// * `[-d DEFAULT-REGION]` - The region in which the client is created.
/// If not supplied, uses the value of the **AWS_DEFAULT_REGION** environment variable.
/// * `[-d DEFAULT-REGION]` - The Region in which the client is created.
/// If not supplied, uses the value of the **AWS_REGION** environment variable.
/// If the environment variable is not set, defaults to **us-west-2**.
/// * `[-v]` - Whether to display additional information.
#[tokio::main]
async fn main() -> Result<(), rdsdata::Error> {
async fn main() -> Result<(), Error> {
tracing_subscriber::fmt::init();

let Opt {
default_region,
query,
Expand All @@ -64,18 +62,16 @@ async fn main() -> Result<(), rdsdata::Error> {
.or_else(|| aws_types::region::default_provider().region())
.unwrap_or_else(|| Region::new("us-west-2"));

println!();

if verbose {
println!("RDS data client version: {}\n", rdsdata::PKG_VERSION);
println!("Region: {:?}", &region);
println!("Resource ARN: {}", resource_arn);
println!("Secrets ARN: {}", secret_arn);
println!("RDS data version: {}", PKG_VERSION);
println!("Region: {:?}", &region);
println!("Resource ARN: {}", &resource_arn);
println!("Secrets ARN: {}", &secret_arn);
println!("Query:");
println!(" {}", query);

SubscriberBuilder::default()
.with_env_filter("info")
.with_span_events(FmtSpan::CLOSE)
.init();
println!(" {}", &query);
println!();
}

let conf = Config::builder().region(region).build();
Expand All @@ -91,5 +87,7 @@ async fn main() -> Result<(), rdsdata::Error> {
let result = st.send().await?;

println!("{:?}", result);
println!();

Ok(())
}

0 comments on commit cdee93b

Please sign in to comment.