Skip to content

Commit 82cb50e

Browse files
authored
Use ChainProvider for region in Snowball examples (#580)
* Use ChainProvider for region in Snowball examples * Change default_region to region in Cognito and Snowball examples
1 parent 3e4cec3 commit 82cb50e

File tree

8 files changed

+61
-37
lines changed

8 files changed

+61
-37
lines changed

aws/sdk/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import software.amazon.smithy.model.Model
66
import software.amazon.smithy.model.shapes.ServiceShape
77
import software.amazon.smithy.aws.traits.ServiceTrait
88
import kotlin.streams.toList
9-
import org.jetbrains.kotlin.utils.ifEmpty
109

1110
extra["displayName"] = "Smithy :: Rust :: AWS-SDK"
1211
extra["moduleName"] = "software.amazon.smithy.rust.awssdk"

aws/sdk/examples/cognitoidentity/src/bin/list-identity-pools.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use structopt::StructOpt;
99

1010
#[derive(Debug, StructOpt)]
1111
struct Opt {
12-
/// The default region
12+
/// The region
1313
#[structopt(short, long)]
14-
default_region: Option<String>,
14+
region: Option<String>,
1515

1616
/// Whether to display additional information
1717
#[structopt(short, long)]
@@ -21,7 +21,7 @@ struct Opt {
2121
/// Lists your Amazon Cognito identities
2222
/// # Arguments
2323
///
24-
/// * `[-d DEFAULT-REGION]` - The region containing the buckets.
24+
/// * `[-r REGION]` - The region containing the buckets.
2525
/// If not supplied, uses the value of the **AWS_DEFAULT_REGION** environment variable.
2626
/// If the environment variable is not set, defaults to **us-west-2**.
2727
/// * `[-g]` - Whether to display buckets in all regions.
@@ -30,12 +30,9 @@ struct Opt {
3030
async fn main() -> Result<(), Error> {
3131
tracing_subscriber::fmt::init();
3232

33-
let Opt {
34-
default_region,
35-
verbose,
36-
} = Opt::from_args();
33+
let Opt { region, verbose } = Opt::from_args();
3734

38-
let region_provider = region::ChainProvider::first_try(default_region.map(Region::new))
35+
let region_provider = region::ChainProvider::first_try(region.map(Region::new))
3936
.or_default_provider()
4037
.or_else(Region::new("us-west-2"));
4138

aws/sdk/examples/cognitoidentityprovider/src/bin/list-user-pools.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use structopt::StructOpt;
99

1010
#[derive(Debug, StructOpt)]
1111
struct Opt {
12-
/// The default region
12+
/// The region
1313
#[structopt(short, long)]
14-
default_region: Option<String>,
14+
region: Option<String>,
1515

1616
/// Whether to display additional information
1717
#[structopt(short, long)]
@@ -21,7 +21,7 @@ struct Opt {
2121
/// Lists your Amazon Cognito user pools
2222
/// # Arguments
2323
///
24-
/// * `[-d DEFAULT-REGION]` - The region containing the buckets.
24+
/// * `[-r REGION]` - The region containing the buckets.
2525
/// If not supplied, uses the value of the **AWS_DEFAULT_REGION** environment variable.
2626
/// If the environment variable is not set, defaults to **us-west-2**.
2727
/// * `[-g]` - Whether to display buckets in all regions.
@@ -30,12 +30,9 @@ struct Opt {
3030
async fn main() -> Result<(), Error> {
3131
tracing_subscriber::fmt::init();
3232

33-
let Opt {
34-
default_region,
35-
verbose,
36-
} = Opt::from_args();
33+
let Opt { region, verbose } = Opt::from_args();
3734

38-
let region_provider = region::ChainProvider::first_try(default_region.map(Region::new))
35+
let region_provider = region::ChainProvider::first_try(region.map(Region::new))
3936
.or_default_provider()
4037
.or_else(Region::new("us-west-2"));
4138

aws/sdk/examples/cognitosync/src/bin/list-identity-pool-usage.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use structopt::StructOpt;
99

1010
#[derive(Debug, StructOpt)]
1111
struct Opt {
12-
/// The default region
12+
/// The region
1313
#[structopt(short, long)]
14-
default_region: Option<String>,
14+
region: Option<String>,
1515

1616
/// Whether to display additional information
1717
#[structopt(short, long)]
@@ -21,7 +21,7 @@ struct Opt {
2121
/// Lists identity pools registered with Amazon Cognito
2222
/// # Arguments
2323
///
24-
/// * `[-d DEFAULT-REGION]` - The region containing the buckets.
24+
/// * `[-r REGION]` - The region containing the buckets.
2525
/// If not supplied, uses the value of the **AWS_DEFAULT_REGION** environment variable.
2626
/// If the environment variable is not set, defaults to **us-west-2**.
2727
/// * `[-g]` - Whether to display buckets in all regions.
@@ -30,12 +30,9 @@ struct Opt {
3030
async fn main() -> Result<(), Error> {
3131
tracing_subscriber::fmt::init();
3232

33-
let Opt {
34-
default_region,
35-
verbose,
36-
} = Opt::from_args();
33+
let Opt { region, verbose } = Opt::from_args();
3734

38-
let region_provider = region::ChainProvider::first_try(default_region.map(Region::new))
35+
let region_provider = region::ChainProvider::first_try(region.map(Region::new))
3936
.or_default_provider()
4037
.or_else(Region::new("us-west-2"));
4138

aws/sdk/examples/snowball/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ edition = "2018"
99
[dependencies]
1010
tokio = { version = "1", features = ["full"]}
1111
aws-sdk-snowball = { path = "../../build/aws-sdk/snowball" }
12-
aws-hyper = { path = "../../build/aws-sdk/aws-hyper" }
1312
aws-types = { path = "../../build/aws-sdk/aws-types" }
1413
structopt = { version = "0.3", default-features = false }
1514
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }

aws/sdk/examples/snowball/src/bin/create-address.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
use aws_sdk_snowball::model::Address;
77
use aws_sdk_snowball::{Config, Region};
8-
use aws_types::region::{EnvironmentProvider, ProvideRegion};
8+
use aws_types::region;
99
use structopt::StructOpt;
1010

1111
#[derive(Debug, StructOpt)]
1212
struct Opt {
13-
/// The region
13+
/// The default region
1414
#[structopt(short, long)]
1515
region: Option<String>,
1616

@@ -54,6 +54,8 @@ struct Opt {
5454

5555
#[tokio::main]
5656
async fn main() -> Result<(), aws_sdk_snowball::Error> {
57+
tracing_subscriber::fmt::init();
58+
5759
let Opt {
5860
region,
5961
city,
@@ -70,10 +72,9 @@ async fn main() -> Result<(), aws_sdk_snowball::Error> {
7072
street3,
7173
} = Opt::from_args();
7274

73-
let region = EnvironmentProvider::new()
74-
.region()
75-
.or_else(|| region.as_ref().map(|region| Region::new(region.clone())))
76-
.unwrap_or_else(|| Region::new("us-west-2"));
75+
let region_provider = region::ChainProvider::first_try(region.map(Region::new))
76+
.or_default_provider()
77+
.or_else(Region::new("us-west-2"));
7778

7879
let new_address = Address::builder()
7980
.set_address_id(None)
@@ -92,7 +93,7 @@ async fn main() -> Result<(), aws_sdk_snowball::Error> {
9293
.set_is_restricted(Some(false))
9394
.build();
9495

95-
let conf = Config::builder().region(region).build();
96+
let conf = Config::builder().region(region_provider).build();
9697
let client = aws_sdk_snowball::Client::from_conf(conf);
9798

9899
let result = client.create_address().address(new_address).send().await?;

aws/sdk/examples/snowball/src/bin/describe-addresses.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,29 @@
44
*/
55

66
use aws_sdk_snowball::{Config, Region};
7+
use aws_types::region;
8+
use structopt::StructOpt;
9+
10+
#[derive(Debug, StructOpt)]
11+
struct Opt {
12+
/// The region
13+
#[structopt(short, long)]
14+
region: Option<String>,
15+
}
716

817
#[tokio::main]
918
async fn main() -> Result<(), aws_sdk_snowball::Error> {
10-
let region = Region::new("us-east-1");
11-
let conf = Config::builder().region(region).build();
19+
tracing_subscriber::fmt::init();
20+
21+
let Opt { region } = Opt::from_args();
22+
23+
let region_provider = region::ChainProvider::first_try(region.map(Region::new))
24+
.or_default_provider()
25+
.or_else(Region::new("us-east-1"));
26+
27+
let conf = Config::builder().region(region_provider).build();
1228
let client = aws_sdk_snowball::Client::from_conf(conf);
29+
1330
let addresses = client.describe_addresses().send().await?;
1431
for address in addresses.addresses.unwrap() {
1532
println!("Address: {:?}", address);

aws/sdk/examples/snowball/src/bin/list-jobs.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,29 @@
44
*/
55

66
use aws_sdk_snowball::{Config, Region};
7+
use aws_types::region;
8+
use structopt::StructOpt;
9+
10+
#[derive(Debug, StructOpt)]
11+
struct Opt {
12+
/// The region
13+
#[structopt(short, long)]
14+
region: Option<String>,
15+
}
716

817
#[tokio::main]
918
async fn main() -> Result<(), aws_sdk_snowball::Error> {
10-
let region = Region::new("us-east-1");
11-
let conf = Config::builder().region(region).build();
19+
tracing_subscriber::fmt::init();
20+
21+
let Opt { region } = Opt::from_args();
22+
23+
let region_provider = region::ChainProvider::first_try(region.map(Region::new))
24+
.or_default_provider()
25+
.or_else(Region::new("us-east-1"));
26+
27+
let conf = Config::builder().region(region_provider).build();
1228
let client = aws_sdk_snowball::Client::from_conf(conf);
29+
1330
let jobs = client.list_jobs().send().await?;
1431
for job in jobs.job_list_entries.unwrap() {
1532
println!("JobId: {:?}", job.job_id);

0 commit comments

Comments
 (0)