Skip to content

Commit 7d140b1

Browse files
authored
Refactored MediaLive code example (#555)
* Refactored MediaLive code example to use common example pattern; re-ordered crates in Cargo.toml * Refactored MediaPackage code examples to use common example pattern; re-ordered crates in Cargo.toml
1 parent 771b0f2 commit 7d140b1

File tree

5 files changed

+146
-11
lines changed

5 files changed

+146
-11
lines changed

aws/sdk/examples/medialive/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2018"
88

99
[dependencies]
1010
medialive = { package = "aws-sdk-medialive", path = "../../build/aws-sdk/medialive" }
11+
aws-types = { path = "../../build/aws-sdk/aws-types" }
1112
tokio = { version = "1", features = ["full"] }
12-
# used only to enable basic logging:
13-
env_logger = "0.8.2"
13+
structopt = { version = "0.3", default-features = false }
14+
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }

aws/sdk/examples/medialive/src/bin/medialive-helloworld.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,54 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6-
/// Lists your AWS Elemental MediaLive input names and ARNs.
6+
use aws_types::region::ProvideRegion;
7+
use medialive::{Client, Config, Error, Region, PKG_VERSION};
8+
use structopt::StructOpt;
9+
10+
#[derive(Debug, StructOpt)]
11+
struct Opt {
12+
/// The default AWS Region.
13+
#[structopt(short, long)]
14+
default_region: Option<String>,
15+
16+
/// Whether to display additional information.
17+
#[structopt(short, long)]
18+
verbose: bool,
19+
}
20+
21+
/// Lists your AWS Elemental MediaLive input names and ARNs in the Region.
22+
/// # Arguments
23+
///
24+
/// * `[-d DEFAULT-REGION]` - The Region in which the client is created.
25+
/// If not supplied, uses the value of the **AWS_REGION** environment variable.
26+
/// If the environment variable is not set, defaults to **us-west-2**.
27+
/// * `[-v]` - Whether to display additional information.
728
#[tokio::main]
8-
async fn main() -> Result<(), medialive::Error> {
9-
let client = medialive::Client::from_env();
29+
async fn main() -> Result<(), Error> {
30+
tracing_subscriber::fmt::init();
31+
32+
let Opt {
33+
default_region,
34+
verbose,
35+
} = Opt::from_args();
36+
37+
let region = default_region
38+
.as_ref()
39+
.map(|region| Region::new(region.clone()))
40+
.or_else(|| aws_types::region::default_provider().region())
41+
.unwrap_or_else(|| Region::new("us-west-2"));
42+
43+
println!();
44+
45+
if verbose {
46+
println!("MediaLive version: {}", PKG_VERSION);
47+
println!("Region: {:?}", &region);
48+
println!();
49+
}
50+
51+
let conf = Config::builder().region(region).build();
52+
let client = Client::from_conf(conf);
53+
1054
let input_list = client.list_inputs().send().await?;
1155

1256
for i in input_list.inputs.unwrap_or_default() {

aws/sdk/examples/mediapackage/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ edition = "2018"
88

99
[dependencies]
1010
mediapackage = { package = "aws-sdk-mediapackage", path = "../../build/aws-sdk/mediapackage" }
11+
aws-types = { path = "../../build/aws-sdk/aws-types" }
1112
tokio = { version = "1", features = ["full"] }
12-
# used only to enable basic logging:
13-
env_logger = "0.8.2"
13+
structopt = { version = "0.3", default-features = false }
14+
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }

aws/sdk/examples/mediapackage/src/bin/list-endpoints.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,54 @@
44
*/
55

66
/// Lists your AWS Elemental MediaPackage endpoint URLs.
7+
use aws_types::region::ProvideRegion;
8+
use mediapackage::{Client, Config, Error, Region, PKG_VERSION};
9+
use structopt::StructOpt;
10+
11+
#[derive(Debug, StructOpt)]
12+
struct Opt {
13+
/// The default AWS Region.
14+
#[structopt(short, long)]
15+
default_region: Option<String>,
16+
17+
/// Whether to display additional information.
18+
#[structopt(short, long)]
19+
verbose: bool,
20+
}
21+
22+
/// Lists your AWS Elemental MediaPackage endpoint descriptions and URLs.
23+
/// # Arguments
24+
///
25+
/// * `[-d DEFAULT-REGION]` - The Region in which the client is created.
26+
/// If not supplied, uses the value of the **AWS_REGION** environment variable.
27+
/// If the environment variable is not set, defaults to **us-west-2**.
28+
/// * `[-v]` - Whether to display additional information.
729
#[tokio::main]
8-
async fn main() -> Result<(), mediapackage::Error> {
9-
let client = mediapackage::Client::from_env();
30+
async fn main() -> Result<(), Error> {
31+
tracing_subscriber::fmt::init();
32+
33+
let Opt {
34+
default_region,
35+
verbose,
36+
} = Opt::from_args();
37+
38+
let region = default_region
39+
.as_ref()
40+
.map(|region| Region::new(region.clone()))
41+
.or_else(|| aws_types::region::default_provider().region())
42+
.unwrap_or_else(|| Region::new("us-west-2"));
43+
44+
println!();
45+
46+
if verbose {
47+
println!("MediaPackage version: {}", PKG_VERSION);
48+
println!("Region: {:?}", &region);
49+
println!();
50+
}
51+
52+
let conf = Config::builder().region(region).build();
53+
let client = Client::from_conf(conf);
54+
1055
let or_endpoints = client.list_origin_endpoints().send().await?;
1156

1257
for e in or_endpoints.origin_endpoints.unwrap_or_default() {

aws/sdk/examples/mediapackage/src/bin/mediapackage-helloworld.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,54 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
use aws_types::region::ProvideRegion;
7+
use mediapackage::{Client, Config, Error, Region, PKG_VERSION};
8+
use structopt::StructOpt;
9+
10+
#[derive(Debug, StructOpt)]
11+
struct Opt {
12+
/// The default AWS Region.
13+
#[structopt(short, long)]
14+
default_region: Option<String>,
15+
16+
/// Whether to display additional information.
17+
#[structopt(short, long)]
18+
verbose: bool,
19+
}
20+
621
/// Lists your AWS Elemental MediaPackage channel ARNs and descriptions.
22+
/// # Arguments
23+
///
24+
/// * `[-d DEFAULT-REGION]` - The Region in which the client is created.
25+
/// If not supplied, uses the value of the **AWS_REGION** environment variable.
26+
/// If the environment variable is not set, defaults to **us-west-2**.
27+
/// * `[-v]` - Whether to display additional information.
728
#[tokio::main]
8-
async fn main() -> Result<(), mediapackage::Error> {
9-
let client = mediapackage::Client::from_env();
29+
async fn main() -> Result<(), Error> {
30+
tracing_subscriber::fmt::init();
31+
32+
let Opt {
33+
default_region,
34+
verbose,
35+
} = Opt::from_args();
36+
37+
let region = default_region
38+
.as_ref()
39+
.map(|region| Region::new(region.clone()))
40+
.or_else(|| aws_types::region::default_provider().region())
41+
.unwrap_or_else(|| Region::new("us-west-2"));
42+
43+
println!();
44+
45+
if verbose {
46+
println!("MediaPackage version: {}", PKG_VERSION);
47+
println!("Region: {:?}", &region);
48+
println!();
49+
}
50+
51+
let conf = Config::builder().region(region).build();
52+
let client = Client::from_conf(conf);
53+
1054
let list_channels = client.list_channels().send().await?;
1155

1256
for c in list_channels.channels.unwrap_or_default() {

0 commit comments

Comments
 (0)