-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moved QLDB code examples into qldb directory; added create-ledger code example #485
Changes from 2 commits
49a45e2
2d251e8
cb5f9ce
f41fe78
03cb369
84b1dc8
a039f66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,81 @@ | ||||||
/* | ||||||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||||||
* SPDX-License-Identifier: Apache-2.0. | ||||||
*/ | ||||||
|
||||||
use aws_types::region::ProvideRegion; | ||||||
|
||||||
//use qldbsession::model::StartSessionRequest; | ||||||
use qldb::model::PermissionsMode; | ||||||
use qldb::{Client, Config, Error, Region}; | ||||||
|
||||||
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. | ||||||
#[structopt(short, long)] | ||||||
default_region: Option<String>, | ||||||
|
||||||
/// The name of the ledger. | ||||||
#[structopt(short, long)] | ||||||
ledger: String, | ||||||
|
||||||
/// Whether to display additional runtime information | ||||||
#[structopt(short, long)] | ||||||
verbose: bool, | ||||||
} | ||||||
|
||||||
/// Creates an Amazon QLDB ledger. | ||||||
/// # Arguments | ||||||
/// | ||||||
/// * `-l LEDGER` - The name of the ledger. | ||||||
/// * `[-d DEFAULT-REGION]` - The region in which the client is created. | ||||||
/// If not supplied, uses the value of the **AWS_DEFAULT_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<(), Error> { | ||||||
let Opt { | ||||||
default_region, | ||||||
ledger, | ||||||
verbose, | ||||||
} = Opt::from_args(); | ||||||
|
||||||
let region = default_region | ||||||
.as_ref() | ||||||
.map(|region| Region::new(region.clone())) | ||||||
.or_else(|| aws_types::region::default_provider().region()) | ||||||
.unwrap_or_else(|| Region::new("us-west-2")); | ||||||
|
||||||
if verbose { | ||||||
println!("OLDB client version: {}\n", qldb::PKG_VERSION); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, changed. |
||||||
println!("Region: {:?}", ®ion); | ||||||
|
||||||
SubscriberBuilder::default() | ||||||
.with_env_filter("info") | ||||||
.with_span_events(FmtSpan::CLOSE) | ||||||
.init(); | ||||||
} | ||||||
|
||||||
let conf = Config::builder().region(region).build(); | ||||||
let client = Client::from_conf(conf); | ||||||
|
||||||
let result = client | ||||||
.create_ledger() | ||||||
.name(ledger) | ||||||
.permissions_mode(PermissionsMode::AllowAll) | ||||||
.send() | ||||||
.await?; | ||||||
|
||||||
match result.arn { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the result will always have an ARN, should probably unwrap here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
None => {} | ||||||
Some(a) => { | ||||||
println!("Ledger ARN: {}", a); | ||||||
} | ||||||
} | ||||||
|
||||||
Ok(()) | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
use aws_types::region::ProvideRegion; | ||
|
||
use qldbsession::model::StartSessionRequest; | ||
use qldbsession::{Client, Config, Error, Region}; | ||
|
||
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. | ||
#[structopt(short, long)] | ||
default_region: Option<String>, | ||
|
||
/// Specifies the ledger | ||
#[structopt(short, long)] | ||
ledger: String, | ||
|
||
/// Whether to display additional runtime information | ||
#[structopt(short, long)] | ||
verbose: bool, | ||
} | ||
|
||
/// Creates a low-level Amazon QLDB session. | ||
/// # Arguments | ||
/// | ||
/// * `-l LEDGER` - The name of the ledger to start a new session against. | ||
/// * `[-d DEFAULT-REGION]` - The region in which the client is created. | ||
/// If not supplied, uses the value of the **AWS_DEFAULT_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<(), Error> { | ||
let Opt { | ||
ledger, | ||
default_region, | ||
verbose, | ||
} = Opt::from_args(); | ||
|
||
let region = default_region | ||
.as_ref() | ||
.map(|region| Region::new(region.clone())) | ||
.or_else(|| aws_types::region::default_provider().region()) | ||
.unwrap_or_else(|| Region::new("us-west-2")); | ||
|
||
if verbose { | ||
println!("OLDB client version: {}\n", qldb::PKG_VERSION); | ||
println!("Region: {:?}", ®ion); | ||
println!("Ledger: {}", ledger); | ||
|
||
SubscriberBuilder::default() | ||
.with_env_filter("info") | ||
.with_span_events(FmtSpan::CLOSE) | ||
.init(); | ||
} | ||
|
||
let conf = Config::builder().region(region).build(); | ||
let client = Client::from_conf(conf); | ||
let result = client | ||
.send_command() | ||
.start_session(StartSessionRequest::builder().ledger_name(ledger).build()) | ||
.send() | ||
.await?; | ||
|
||
match result.start_session { | ||
Some(s) => { | ||
println!("Your session id: {:?}", s.session_token); | ||
} | ||
None => unreachable!("a start session will result in an Err or a start session result"), | ||
} | ||
|
||
Ok(()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0. | ||
*/ | ||
|
||
use aws_types::region::ProvideRegion; | ||
|
||
//use qldbsession::model::StartSessionRequest; | ||
use qldb::{Client, Config, Error, Region}; | ||
|
||
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. | ||
#[structopt(short, long)] | ||
default_region: Option<String>, | ||
|
||
/// Whether to display additional runtime information | ||
#[structopt(short, long)] | ||
verbose: bool, | ||
} | ||
|
||
/// Lists your Amazon QLDB ledgers. | ||
/// # Arguments | ||
/// | ||
/// * `[-d DEFAULT-REGION]` - The region in which the client is created. | ||
/// If not supplied, uses the value of the **AWS_DEFAULT_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<(), Error> { | ||
let Opt { | ||
default_region, | ||
verbose, | ||
} = Opt::from_args(); | ||
|
||
let region = default_region | ||
.as_ref() | ||
.map(|region| Region::new(region.clone())) | ||
.or_else(|| aws_types::region::default_provider().region()) | ||
.unwrap_or_else(|| Region::new("us-west-2")); | ||
|
||
if verbose { | ||
println!("OLDB client version: {}\n", qldb::PKG_VERSION); | ||
println!("Region: {:?}", ®ion); | ||
|
||
SubscriberBuilder::default() | ||
.with_env_filter("info") | ||
.with_span_events(FmtSpan::CLOSE) | ||
.init(); | ||
} | ||
|
||
let conf = Config::builder().region(region).build(); | ||
let client = Client::from_conf(conf); | ||
|
||
let result = client.list_ledgers().send().await?; | ||
|
||
if let Some(ledgers) = result.ledgers { | ||
for ledger in ledgers { | ||
println!("* {:?}", ledger); | ||
} | ||
|
||
if result.next_token.is_some() { | ||
todo!("pagination is not yet demonstrated") | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted.