Skip to content

Commit 317b86d

Browse files
aws-sdk-rust-cicpyle0819DavidSoutherjdisantirlhagerm
committed
[examples] Sync SDK examples from awsdocs/aws-doc-sdk-examples
Includes commit(s): a292296d0b163cdd04b7f6635fdb3db1d1a1e182 dc94be86e8f00336ced1216b76793c161c40f2a3 157465835a187ea9f51110869578878c10c05b34 2ab2acdf0f5d8a26c390141c89e0844aebb33ae8 97c67e03fa7db36d27ef54dc6bd7b882543d066e 4248c8b8b8d8bf136a1e2e7ff64bae708ea571f2 acbc2501d51e25dd9121ec6303664d95f8517cbc ca6cdd308d6a34e91e500bad85fcb7c0d9cf1eb5 4409fc9b2258d279dd9b8ddcf1acaec06eee75ea 01bcc8fb3400af72fce1d625a051a0c1fcf99d36 afcf30f40642331a26e34719c25e19dda1a447cf 59b9dab1f43b5391cf3f766a554ba1ef2fa29a63 275f4231b7cf2573317a330b088d376766383777 20e29158888a75865b00e38e51f2761798a82899 e634373d4c8c4e65784a7c6520ff533f4022e8d4 29b5d3dda6231bc1cedeba8b4ccaf7154258b66f 77c6276633312a6962138f3465b4c9ece95f575f f614d9313834faea1a7a9245943f33ea1f93fbe3 2affa0d71cf9d4cbda11a60418be88fe2a835eb7 c2d5d9755a44cfef15ade3d154d377a087262cdd e8f4252b642d45a9b20b478241570b8cd9a9103e cf400c3d1eefb910869a961bc3c948e75386daa1 Co-authored-by: Corey Pyle <corepyle@amazon.com> Co-authored-by: David Souther <davidsouther+github@gmail.com> Co-authored-by: John DiSanti <jdisanti@amazon.com> Co-authored-by: Rachel Hagerman <110480692+rlhagerm@users.noreply.github.com> Co-authored-by: WMR <github@waughonline.com> Co-authored-by: Zelda Hessler <zhessler@amazon.com>
1 parent 3026bf1 commit 317b86d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+2166
-216
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@ members = [
66
"examples/autoscaling",
77
"examples/autoscalingplans",
88
"examples/batch",
9-
"examples/ca-certs",
109
"examples/cloudformation",
1110
"examples/cloudwatch",
1211
"examples/cloudwatchlogs",
1312
"examples/cognitoidentity",
1413
"examples/cognitoidentityprovider",
1514
"examples/cognitosync",
1615
"examples/config",
16+
"examples/custom-root-certificates",
1717
"examples/dynamodb",
1818
"examples/ebs",
1919
"examples/ec2",
2020
"examples/ecr",
2121
"examples/ecs",
2222
"examples/eks",
2323
"examples/globalaccelerator",
24+
"examples/glue",
2425
"examples/greengrassv2",
2526
"examples/iam",
2627
"examples/iot",

examples/apigateway/Cargo.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name = "apigateway-code-examples"
33
version = "0.1.0"
44
edition = "2021"
55
publish = false
6+
7+
[dependencies]
8+
thiserror = "1.0"
9+
610
[dependencies.aws-config]
711
path = "../../sdk/aws-config"
812
version = "0.52.0"
@@ -16,14 +20,14 @@ features = ["convert-chrono"]
1620
path = "../../sdk/aws-smithy-types-convert"
1721
version = "0.52.0"
1822

19-
[dependencies.tokio]
20-
version = "1.20.1"
21-
features = ["full"]
22-
2323
[dependencies.structopt]
2424
version = "0.3"
2525
default-features = false
2626

27+
[dependencies.tokio]
28+
version = "1.20.1"
29+
features = ["full"]
30+
2731
[dependencies.tracing-subscriber]
2832
version = "0.3.15"
2933
features = ["env-filter"]

examples/apigateway/src/bin/get_rest_apis.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
* SPDX-License-Identifier: Apache-2.0.
44
*/
55

6+
use apigateway_code_examples::Error;
67
use aws_config::meta::region::RegionProviderChain;
7-
use aws_sdk_apigateway::{Client, Error, Region, PKG_VERSION};
8+
use aws_sdk_apigateway::types::DisplayErrorContext;
9+
use aws_sdk_apigateway::{Client, Region, PKG_VERSION};
810
use aws_smithy_types_convert::date_time::DateTimeExt;
11+
use std::process;
912
use structopt::StructOpt;
1013

1114
#[derive(Debug, StructOpt)]
@@ -31,7 +34,7 @@ async fn show_apis(client: &Client) -> Result<(), Error> {
3134
println!("Version: {}", api.version().unwrap_or_default());
3235
println!(
3336
"Created: {}",
34-
api.created_date().unwrap().to_chrono_utc()
37+
api.created_date().unwrap().to_chrono_utc()?
3538
);
3639
println!();
3740
}
@@ -49,10 +52,16 @@ async fn show_apis(client: &Client) -> Result<(), Error> {
4952
/// If the environment variable is not set, defaults to **us-west-2**.
5053
/// * `[-v]` - Whether to display information.
5154
#[tokio::main]
52-
async fn main() -> Result<(), Error> {
55+
async fn main() {
5356
tracing_subscriber::fmt::init();
54-
let Opt { region, verbose } = Opt::from_args();
5557

58+
if let Err(err) = run_example(Opt::from_args()).await {
59+
eprintln!("Error: {}", DisplayErrorContext(err));
60+
process::exit(1);
61+
}
62+
}
63+
64+
async fn run_example(Opt { region, verbose }: Opt) -> Result<(), Error> {
5665
let region_provider = RegionProviderChain::first_try(region.map(Region::new))
5766
.or_default_provider()
5867
.or_else(Region::new("us-west-2"));

examples/apigateway/src/lib.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
use std::error::Error as StdError;
7+
8+
#[derive(thiserror::Error, Debug)]
9+
#[error("unhandled error")]
10+
pub struct Error {
11+
#[source]
12+
source: Box<dyn StdError + Send + Sync + 'static>,
13+
}
14+
15+
impl Error {
16+
pub fn unhandled(source: impl Into<Box<dyn StdError + Send + Sync + 'static>>) -> Self {
17+
Self {
18+
source: source.into(),
19+
}
20+
}
21+
}
22+
23+
impl From<aws_sdk_apigateway::Error> for Error {
24+
fn from(source: aws_sdk_apigateway::Error) -> Self {
25+
Error::unhandled(source)
26+
}
27+
}
28+
29+
impl<T> From<aws_sdk_apigateway::types::SdkError<T>> for Error
30+
where
31+
T: StdError + Send + Sync + 'static,
32+
{
33+
fn from(source: aws_sdk_apigateway::types::SdkError<T>) -> Self {
34+
Error::unhandled(source)
35+
}
36+
}
37+
38+
impl From<aws_smithy_types_convert::date_time::Error> for Error {
39+
fn from(source: aws_smithy_types_convert::date_time::Error) -> Self {
40+
Self {
41+
source: source.into(),
42+
}
43+
}
44+
}

examples/apigatewaymanagement/src/bin/post_to_connection.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,13 @@ async fn main() -> Result<(), Error> {
102102
}
103103

104104
// snippet-start:[apigatewaymanagement.rust.post_to_connection_client]
105-
let uri = format!(
105+
let endpoint = Endpoint::immutable(format!(
106106
"https://{api_id}.execute-api.{region}.amazonaws.com/{stage}",
107107
api_id = api_id,
108108
region = region,
109109
stage = stage
110-
)
111-
.parse()
112-
.expect("could not construct valid URI for endpoint");
113-
let endpoint = Endpoint::immutable(uri);
110+
))
111+
.expect("valid endpoint");
114112

115113
let shared_config = aws_config::from_env().region(region_provider).load().await;
116114
let api_management_config = config::Builder::from(&shared_config)

examples/cognitoidentity/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ publish = false
77

88
[dependencies]
99
chrono = "0.4"
10+
thiserror = "1.0"
1011

1112
[dependencies.aws-config]
1213
path = "../../sdk/aws-config"
@@ -21,14 +22,14 @@ features = ["convert-chrono"]
2122
path = "../../sdk/aws-smithy-types-convert"
2223
version = "0.52.0"
2324

24-
[dependencies.tokio]
25-
version = "1.20.1"
26-
features = ["full"]
27-
2825
[dependencies.structopt]
2926
version = "0.3"
3027
default-features = false
3128

29+
[dependencies.tokio]
30+
version = "1.20.1"
31+
features = ["full"]
32+
3233
[dependencies.tracing-subscriber]
3334
version = "0.3.15"
3435
features = ["env-filter"]

examples/cognitoidentity/src/bin/list-pool-identities.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
*/
55

66
use aws_config::meta::region::RegionProviderChain;
7-
use aws_sdk_cognitoidentity::{Client, Error, Region, PKG_VERSION};
7+
use aws_sdk_cognitoidentity::types::DisplayErrorContext;
8+
use aws_sdk_cognitoidentity::{Client, Region, PKG_VERSION};
89
use aws_smithy_types_convert::date_time::DateTimeExt;
10+
use cognitoidentity_code_examples::Error;
11+
use std::process;
912
use structopt::StructOpt;
1013

1114
#[derive(Debug, StructOpt)]
@@ -36,9 +39,9 @@ async fn list_identities(client: &Client, pool_id: &str) -> Result<(), Error> {
3639
if let Some(ids) = response.identities() {
3740
println!("Identitities:");
3841
for id in ids {
39-
let creation_timestamp = (*id.creation_date().unwrap()).to_chrono_utc();
42+
let creation_timestamp = (*id.creation_date().unwrap()).to_chrono_utc()?;
4043
let idid = id.identity_id().unwrap_or_default();
41-
let mod_timestamp = (*id.last_modified_date().unwrap()).to_chrono_utc();
44+
let mod_timestamp = (*id.last_modified_date().unwrap()).to_chrono_utc()?;
4245
println!(" Creation date: {}", creation_timestamp);
4346
println!(" ID: {}", idid);
4447
println!(" Last modified date: {}", mod_timestamp);
@@ -69,15 +72,22 @@ async fn list_identities(client: &Client, pool_id: &str) -> Result<(), Error> {
6972
/// If the environment variable is not set, defaults to **us-west-2**.
7073
/// * `[-v]` - Whether to display additional information.
7174
#[tokio::main]
72-
async fn main() -> Result<(), Error> {
75+
async fn main() {
7376
tracing_subscriber::fmt::init();
7477

75-
let Opt {
78+
if let Err(err) = run_example(Opt::from_args()).await {
79+
eprintln!("Error: {}", DisplayErrorContext(err));
80+
process::exit(1);
81+
}
82+
}
83+
84+
async fn run_example(
85+
Opt {
7686
identity_pool_id,
7787
region,
7888
verbose,
79-
} = Opt::from_args();
80-
89+
}: Opt,
90+
) -> Result<(), Error> {
8191
let region_provider = RegionProviderChain::first_try(region.map(Region::new))
8292
.or_default_provider()
8393
.or_else(Region::new("us-west-2"));
@@ -96,5 +106,7 @@ async fn main() -> Result<(), Error> {
96106
let shared_config = aws_config::from_env().region(region_provider).load().await;
97107
let client = Client::new(&shared_config);
98108

99-
list_identities(&client, &identity_pool_id).await
109+
list_identities(&client, &identity_pool_id).await?;
110+
111+
Ok(())
100112
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
6+
use std::error::Error as StdError;
7+
8+
#[derive(thiserror::Error, Debug)]
9+
#[error("unhandled error")]
10+
pub struct Error {
11+
#[from]
12+
source: Box<dyn StdError + Send + Sync + 'static>,
13+
}
14+
15+
impl From<aws_sdk_cognitoidentity::Error> for Error {
16+
fn from(source: aws_sdk_cognitoidentity::Error) -> Self {
17+
Self {
18+
source: source.into(),
19+
}
20+
}
21+
}
22+
23+
impl<T> From<aws_sdk_cognitoidentity::types::SdkError<T>> for Error
24+
where
25+
T: StdError + Send + Sync + 'static,
26+
{
27+
fn from(source: aws_sdk_cognitoidentity::types::SdkError<T>) -> Self {
28+
Self {
29+
source: source.into(),
30+
}
31+
}
32+
}
33+
34+
impl From<aws_smithy_types_convert::date_time::Error> for Error {
35+
fn from(source: aws_smithy_types_convert::date_time::Error) -> Self {
36+
Self {
37+
source: source.into(),
38+
}
39+
}
40+
}

examples/cognitoidentityprovider/Cargo.toml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ version = "0.1.0"
44
authors = ["John DiSanti <jdisanti@amazon.com>", "Doug Schwartz <dougsch@amazon.com>"]
55
edition = "2021"
66
publish = false
7+
8+
[dependencies]
9+
thiserror = "1.0"
10+
711
[dependencies.aws-config]
812
path = "../../sdk/aws-config"
913
version = "0.52.0"
@@ -17,14 +21,14 @@ features = ["convert-chrono"]
1721
path = "../../sdk/aws-smithy-types-convert"
1822
version = "0.52.0"
1923

20-
[dependencies.tokio]
21-
version = "1.20.1"
22-
features = ["full"]
23-
2424
[dependencies.structopt]
2525
version = "0.3"
2626
default-features = false
2727

28+
[dependencies.tokio]
29+
version = "1.20.1"
30+
features = ["full"]
31+
2832
[dependencies.tracing-subscriber]
2933
version = "0.3.15"
3034
features = ["env-filter"]

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

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

66
use aws_config::meta::region::RegionProviderChain;
7-
use aws_sdk_cognitoidentityprovider::{Client, Error, Region, PKG_VERSION};
7+
use aws_sdk_cognitoidentityprovider::types::DisplayErrorContext;
8+
use aws_sdk_cognitoidentityprovider::{Client, Region, PKG_VERSION};
89
use aws_smithy_types_convert::date_time::DateTimeExt;
10+
use cognitoidentityprovider_code_examples::Error;
11+
use std::process;
912
use structopt::StructOpt;
1013

1114
#[derive(Debug, StructOpt)]
@@ -32,7 +35,7 @@ async fn show_pools(client: &Client) -> Result<(), Error> {
3235
println!(" Lambda Config: {:?}", pool.lambda_config().unwrap());
3336
println!(
3437
" Last modified: {}",
35-
pool.last_modified_date().unwrap().to_chrono_utc()
38+
pool.last_modified_date().unwrap().to_chrono_utc()?
3639
);
3740
println!(
3841
" Creation date: {:?}",
@@ -55,11 +58,16 @@ async fn show_pools(client: &Client) -> Result<(), Error> {
5558
/// If the environment variable is not set, defaults to **us-west-2**.
5659
/// * `[-v]` - Whether to display additional information.
5760
#[tokio::main]
58-
async fn main() -> Result<(), Error> {
61+
async fn main() {
5962
tracing_subscriber::fmt::init();
6063

61-
let Opt { region, verbose } = Opt::from_args();
64+
if let Err(err) = run_example(Opt::from_args()).await {
65+
eprintln!("Error: {}", DisplayErrorContext(err));
66+
process::exit(1);
67+
}
68+
}
6269

70+
async fn run_example(Opt { region, verbose }: Opt) -> Result<(), Error> {
6371
let region_provider = RegionProviderChain::first_try(region.map(Region::new))
6472
.or_default_provider()
6573
.or_else(Region::new("us-west-2"));

0 commit comments

Comments
 (0)