Skip to content

Commit

Permalink
Fix examples after Rust SDK breaking changes (awsdocs#5662)
Browse files Browse the repository at this point in the history
* Fix examples after Rust SDK breaking changes
* Use a combination of crate and local BehaviorVersions
  • Loading branch information
jdisanti authored Nov 16, 2023
1 parent 2e804c4 commit 9f08f27
Show file tree
Hide file tree
Showing 86 changed files with 250 additions and 143 deletions.
5 changes: 3 additions & 2 deletions rust_dev_preview/cross_service/detect_faces/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

use aws_config::meta::region::RegionProviderChain;
use aws_config::BehaviorVersion;
use aws_sdk_s3::config::Region;
use clap::Parser;
use std::error::Error;
Expand Down Expand Up @@ -205,13 +206,13 @@ async fn main() -> Result<(), Box<dyn Error>> {
println!();
}

let s3_shared_config = aws_config::from_env()
let s3_shared_config = aws_config::defaults(BehaviorVersion::latest())
.region(s3_region_provider)
.load()
.await;
let s3_client = aws_sdk_s3::Client::new(&s3_shared_config);

let rek_shared_config = aws_config::from_env()
let rek_shared_config = aws_config::defaults(BehaviorVersion::latest())
.region(rek_region_provider)
.load()
.await;
Expand Down
7 changes: 4 additions & 3 deletions rust_dev_preview/cross_service/detect_labels/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
extern crate exif;

use aws_config::meta::region::RegionProviderChain;
use aws_config::BehaviorVersion;
use aws_sdk_dynamodb::config::Region;
use aws_sdk_dynamodb::types::AttributeValue;
use clap::Parser;
Expand Down Expand Up @@ -279,7 +280,7 @@ async fn main() -> Result<(), exif::Error> {
println!();
}

let s3_shared_config = aws_config::from_env()
let s3_shared_config = aws_config::defaults(BehaviorVersion::latest())
.region(s3_region_provider)
.load()
.await;
Expand All @@ -289,15 +290,15 @@ async fn main() -> Result<(), exif::Error> {

let edata = get_exif_data(&filename);

let rek_shared_config = aws_config::from_env()
let rek_shared_config = aws_config::defaults(BehaviorVersion::latest())
.region(rek_region_provider)
.load()
.await;
let rek_client = aws_sdk_rekognition::Client::new(&rek_shared_config);

let labels = get_label_data(&rek_client, &bucket, &filename).await;

let dynamo_shared_config = aws_config::from_env()
let dynamo_shared_config = aws_config::defaults(BehaviorVersion::latest())
.region(dynamo_region_provider)
.load()
.await;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use aws_config::SdkConfig;
use aws_config::{BehaviorVersion, SdkConfig};

#[cfg(not(debug_assertions))]
pub fn init_tracing_subscriber() {
Expand Down Expand Up @@ -62,7 +62,7 @@ impl Common {
}

pub async fn load_from_env() -> Self {
let sdk_config = aws_config::load_from_env().await;
let sdk_config = aws_config::load_defaults(BehaviorVersion::latest()).await;
// PAM environment is declared in the cdk, in lib/backend/lambdas.ts
let storage_bucket =
std::env::var("STORAGE_BUCKET_NAME").expect("storage bucket in environment");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub async fn handler(
#[cfg(test)]
mod test {
use super::prepare_update_expression;
use aws_config::SdkConfig;
use aws_config::{BehaviorVersion, SdkConfig};

#[tokio::test]
async fn test_prepare_update_statement() {
Expand All @@ -136,7 +136,11 @@ mod test {
.name("label")
.build();

let client = aws_sdk_dynamodb::Client::new(&SdkConfig::builder().build());
let client = aws_sdk_dynamodb::Client::new(
&SdkConfig::builder()
.behavior_version(BehaviorVersion::latest())
.build(),
);
let update = client.update_item();
let update = prepare_update_expression(update, &object, &label);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use aws_config::BehaviorVersion;
use aws_sdk_s3::Client;

#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
let s3_client = Client::new(&aws_config::load_from_env().await);
let s3_client = Client::new(&aws_config::load_defaults(BehaviorVersion::latest()).await);
let part = 0;
let bucket: String = "bucket".to_string();
let key: String = "key".to_string();
Expand Down
3 changes: 2 additions & 1 deletion rust_dev_preview/cross_service/rest_ses/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! Main that loads environments & prepares clients, and hands them to `startup`.
use std::net::TcpListener;

use aws_config::BehaviorVersion;
use rest_ses::client::{RdsClient, SesClient};
use rest_ses::configuration::{get_settings, init_environment};
use rest_ses::startup::run;
Expand All @@ -30,7 +31,7 @@ async fn main() -> std::io::Result<()> {
init_subscriber(subscriber);

// AWS Settings (Region & role) come from the environment.
let config = aws_config::from_env().load().await;
let config = aws_config::load_defaults(BehaviorVersion::latest()).await;
let rds = RdsClient::new(&settings.rds, &config);
let ses = SesClient::new(&settings.ses, &config);

Expand Down
6 changes: 4 additions & 2 deletions rust_dev_preview/cross_service/rest_ses/tests/api/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0.
*/

use aws_config::BehaviorVersion;
use once_cell::sync::Lazy;
use rest_ses::{
client::{RdsClient, SesClient},
Expand All @@ -27,14 +28,15 @@ static TRACING: Lazy<Environment> = Lazy::new(|| {
/// Spawn the app against a MockServer resolved backend.
pub async fn spawn_app_mocked() -> (String, MockServer) {
let mock_server = MockServer::builder().start().await;
let config_loader = aws_config::from_env().endpoint_url(mock_server.uri());
let config_loader =
aws_config::defaults(BehaviorVersion::latest()).endpoint_url(mock_server.uri());
let (app, _) = prep_app(config_loader).await;
(app, mock_server)
}

/// Spawn the app using production AWS credentials.
pub async fn spawn_app() -> (String, RdsClient) {
prep_app(aws_config::from_env()).await
prep_app(aws_config::defaults(BehaviorVersion::latest())).await
}

/// Prepare the application for testing.
Expand Down
7 changes: 4 additions & 3 deletions rust_dev_preview/cross_service/telephone/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use anyhow::{Context, Result};
use aws_config::meta::region::RegionProviderChain;
use aws_config::BehaviorVersion;
use aws_sdk_polly::config::Region;
use aws_sdk_polly::types::{OutputFormat, VoiceId};
use aws_sdk_transcribe::types::{LanguageCode, Media, MediaFormat, TranscriptionJobStatus};
Expand Down Expand Up @@ -269,15 +270,15 @@ async fn main() -> Result<(), anyhow::Error> {
}

// Create configurations for each service client.
let polly_shared_config = aws_config::from_env()
let polly_shared_config = aws_config::defaults(BehaviorVersion::latest())
.region(polly_region_provider)
.load()
.await;
let s3_shared_config = aws_config::from_env()
let s3_shared_config = aws_config::defaults(BehaviorVersion::latest())
.region(s3_region_provider)
.load()
.await;
let transcribe_shared_config = aws_config::from_env()
let transcribe_shared_config = aws_config::defaults(BehaviorVersion::latest())
.region(transcribe_region_provider)
.load()
.await;
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/apigateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["behavior-version-latest"]}
aws-sdk-apigateway = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-smithy-types-convert = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = [
"convert-chrono",
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/apigatewaymanagement/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["behavior-version-latest"]}
aws-sdk-apigatewaymanagement = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
http = "0.2.5"
tokio = { version = "1.20.1", features = ["full"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["behavior-version-latest"]}
aws-sdk-applicationautoscaling = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
tokio = { version = "1.20.1", features = ["full"] }
clap = { version = "~4.4", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/aurora/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ version = "0.1.0"
[dependencies]
anyhow = "1.0.75"
assert_matches = "1.5.0"
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["behavior-version-latest"]}
aws-smithy-types = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-smithy-runtime-api = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-sdk-rds = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
Expand Down
26 changes: 13 additions & 13 deletions rust_dev_preview/examples/aurora/src/aurora_scenario/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use aws_sdk_rds::{
OrderableDbInstanceOption,
},
};
use aws_smithy_runtime_api::client::orchestrator::HttpResponse;
use aws_smithy_runtime_api::http::{Response, StatusCode};
use aws_smithy_types::body::SdkBody;
use mockall::predicate::eq;
use secrecy::ExposeSecret;
Expand Down Expand Up @@ -103,7 +103,7 @@ async fn test_scenario_set_engine_param_group_exists() {
CreateDBClusterParameterGroupError::DbParameterGroupAlreadyExistsFault(
DbParameterGroupAlreadyExistsFault::builder().build(),
),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
});

Expand Down Expand Up @@ -173,7 +173,7 @@ async fn test_scenario_get_engines_failed() {
ErrorKind::Other,
"describe_db_engine_versions error",
))),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
});

Expand Down Expand Up @@ -244,7 +244,7 @@ async fn test_scenario_get_instance_classes_error() {
ErrorKind::Other,
"describe_orderable_db_instance_options_error",
))),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
});

Expand Down Expand Up @@ -327,7 +327,7 @@ async fn test_scenario_get_cluster_error() {
ErrorKind::Other,
"describe_db_clusters_error",
))),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
});

Expand Down Expand Up @@ -419,7 +419,7 @@ async fn test_scenario_cluster_parameters_error() {
ErrorKind::Other,
"describe_db_cluster_parameters_error",
))),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
});

Expand Down Expand Up @@ -478,7 +478,7 @@ async fn test_scenario_update_auto_increment_error() {
ErrorKind::Other,
"modify_db_cluster_parameter_group_error",
))),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
});

Expand Down Expand Up @@ -602,7 +602,7 @@ async fn test_start_cluster_and_instance_cluster_create_error() {
ErrorKind::Other,
"create db cluster error",
))),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
});

Expand Down Expand Up @@ -667,7 +667,7 @@ async fn test_start_cluster_and_instance_instance_create_error() {
ErrorKind::Other,
"create db instance error",
))),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
});

Expand Down Expand Up @@ -733,7 +733,7 @@ async fn test_start_cluster_and_instance_wait_hiccup() {
ErrorKind::Other,
"describe cluster error",
))),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
})
.with(eq("RustSDKCodeExamplesDBCluster"))
Expand Down Expand Up @@ -892,7 +892,7 @@ async fn test_scenario_clean_up_errors() {
ErrorKind::Other,
"describe db instances error",
))),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
});

Expand Down Expand Up @@ -923,7 +923,7 @@ async fn test_scenario_clean_up_errors() {
ErrorKind::Other,
"describe db clusters error",
))),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
});

Expand Down Expand Up @@ -1000,7 +1000,7 @@ async fn test_scenario_snapshot_error() {
ErrorKind::Other,
"create snapshot error",
))),
HttpResponse::new(SdkBody::empty()),
Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()),
))
});

Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/auto-scaling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["behavior-version-latest"]}
aws-sdk-autoscaling = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-sdk-ec2 = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-types = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/autoscalingplans/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"

[dependencies]
aws-sdk-autoscalingplans = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["behavior-version-latest"]}
aws-types = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
tokio = { version = "1.20.1", features = ["full"] }
clap = { version = "~4.4", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/batch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["behavior-version-latest"]}
aws-sdk-batch = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
tokio = { version = "1.20.1", features = ["full"] }
clap = { version = "~4.4", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/cloudformation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["behavior-version-latest"]}
aws-sdk-cloudformation = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
tokio = { version = "1.20.1", features = ["full"] }
clap = { version = "~4.4", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/cloudwatch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["behavior-version-latest"]}
aws-sdk-cloudwatch = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
tokio = { version = "1.20.1", features = ["full"] }
clap = { version = "~4.4", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/cloudwatchlogs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["behavior-version-latest"]}
aws-sdk-cloudwatchlogs = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-types = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
tokio = { version = "1.20.1", features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion rust_dev_preview/examples/cognitoidentity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = ["behavior-version-latest"]}
aws-sdk-cognitoidentity = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-smithy-types-convert = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next", features = [
"convert-chrono",
Expand Down
Loading

0 comments on commit 9f08f27

Please sign in to comment.