diff --git a/.github/workflows/ci-sdk.yaml b/.github/workflows/ci-sdk.yaml index b5468e87a0..1c44ef43f4 100644 --- a/.github/workflows/ci-sdk.yaml +++ b/.github/workflows/ci-sdk.yaml @@ -171,11 +171,15 @@ jobs: RUSTC_FORCE_INCREMENTAL: 1 RUSTFLAGS: -D warnings - all-services-check: - name: Full SDK - Generate and cargo check + generate-all-services: + name: Full SDK - Generate runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + with: + repository: awsdocs/aws-doc-sdk-examples + path: aws-doc-sdk-examples - uses: actions/cache@v2 name: Gradle Cache with: @@ -194,8 +198,13 @@ jobs: uses: actions/setup-java@v1 with: java-version: ${{ env.java_version }} + - name: Take examples from `awsdocs/aws-doc-sdk-examples` + run: | + mv aws-doc-sdk-examples/rust_dev_preview aws/sdk/examples + rm -rf aws/sdk/examples/.cargo + rm aws/sdk/examples/Cargo.toml - name: Generate and check all services - run: ./gradlew -Paws.fullsdk=true :aws:sdk:cargoCheck + run: ./gradlew -Paws.fullsdk=true :aws:sdk:assemble - name: Generate a name for the SDK id: gen-name run: echo "name=${GITHUB_REF##*/}" >> $GITHUB_ENV @@ -206,3 +215,59 @@ jobs: with: name: aws-sdk-${{ env.name }}-${{ github.sha }} path: sdk.tar + + check-all-examples: + name: Full SDK - Check examples + runs-on: ubuntu-latest + needs: generate-all-services + env: + # Disable incremental compilation to reduce disk space use + CARGO_INCREMENTAL: 0 + RUSTFLAGS: -D warnings + steps: + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ env.rust_version }} + components: ${{ env.rust_toolchain_components }} + default: true + - name: Generate a name for the SDK + id: gen-name + run: echo "name=${GITHUB_REF##*/}" >> $GITHUB_ENV + - uses: actions/download-artifact@v2 + name: Download SDK Artifact + with: + name: aws-sdk-${{ env.name }}-${{ github.sha }} + path: artifact + - name: untar + run: tar -xvf ./artifact/sdk.tar + - name: Check the SDK + run: cargo check + working-directory: ./examples + + check-all-services: + name: Full SDK - Check services + runs-on: ubuntu-latest + needs: generate-all-services + env: + # Disable incremental compilation to reduce disk space use + CARGO_INCREMENTAL: 0 + RUSTFLAGS: -D warnings + steps: + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ env.rust_version }} + components: ${{ env.rust_toolchain_components }} + default: true + - name: Generate a name for the SDK + id: gen-name + run: echo "name=${GITHUB_REF##*/}" >> $GITHUB_ENV + - uses: actions/download-artifact@v2 + name: Download SDK Artifact + with: + name: aws-sdk-${{ env.name }}-${{ github.sha }} + path: artifact + - name: untar + run: tar -xvf ./artifact/sdk.tar + - name: Check the SDK + run: cargo check + working-directory: ./sdk diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 25686931de..d3743f26ca 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -21,4 +21,16 @@ author = "rcoh" message = "Improve docs on `Endpoint::{mutable, immutable}`" references = ["smithy-rs#1087"] meta = { "breaking" = false, "tada" = false, "bug" = false } -author = "rcoh" \ No newline at end of file +author = "rcoh" + +[[aws-sdk-rust]] +message = "SDK examples now come from [`awsdocs/aws-doc-sdk-examples`](https://github.com/awsdocs/aws-doc-sdk-examples) rather than from `smithy-rs`" +references = ["smithy-rs#1118"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "jdisanti" + +[[smithy-rs]] +message = "SDK examples now come from [`awsdocs/aws-doc-sdk-examples`](https://github.com/awsdocs/aws-doc-sdk-examples) rather than from `smithy-rs`" +references = ["smithy-rs#1118"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "jdisanti" diff --git a/aws/sdk/build.gradle.kts b/aws/sdk/build.gradle.kts index d200e380c0..8a43c40613 100644 --- a/aws/sdk/build.gradle.kts +++ b/aws/sdk/build.gradle.kts @@ -24,6 +24,7 @@ val defaultRustDocFlags: String by project val properties = PropertyRetriever(rootProject, project) val publisherToolPath = rootProject.projectDir.resolve("tools/publisher") +val sdkVersionerToolPath = rootProject.projectDir.resolve("tools/sdk-versioner") val outputDir = buildDir.resolve("aws-sdk") val sdkOutputDir = outputDir.resolve("sdk") val examplesOutputDir = outputDir.resolve("examples") @@ -50,6 +51,7 @@ val awsServices: AwsServices by lazy { discoverServices(loadServiceMembership()) val eventStreamAllowList: Set by lazy { eventStreamAllowList() } fun getSdkVersion(): String = properties.get("aws.sdk.version") ?: throw kotlin.Exception("SDK version missing") +fun getSmithyRsVersion(): String = properties.get("smithy.rs.runtime.crate.version") ?: throw kotlin.Exception("smithy-rs version missing") fun getRustMSRV(): String = properties.get("rust.msrv") ?: throw kotlin.Exception("Rust MSRV missing") fun loadServiceMembership(): Membership { @@ -179,10 +181,32 @@ task("relocateExamples") { } } } - inputs.dir(projectDir.resolve("examples")) + if (awsServices.examples.isNotEmpty()) { + inputs.dir(projectDir.resolve("examples")) + } outputs.dir(outputDir) } +task("fixExampleManifests") { + description = "Adds dependency path and corrects version number of examples after relocation" + doLast { + if (awsServices.examples.isNotEmpty()) { + exec { + workingDir(sdkVersionerToolPath) + commandLine( + "cargo", "run", "--", + outputDir.resolve("examples").absolutePath, + "--sdk-path", "../../sdk", + "--sdk-version", getSdkVersion(), + "--smithy-version", getSmithyRsVersion() + ) + } + } + } + outputs.dir(outputDir) + dependsOn("relocateExamples") +} + /** * The aws/rust-runtime crates depend on local versions of the Smithy core runtime enabling local compilation. However, * those paths need to be replaced in the final build. We should probably fix this with some symlinking. @@ -252,7 +276,9 @@ task("generateCargoWorkspace") { outputDir.resolve("Cargo.toml").writeText(generateCargoWorkspace(awsServices)) } inputs.property("servicelist", awsServices.moduleNames.toString()) - inputs.dir(projectDir.resolve("examples")) + if (awsServices.examples.isNotEmpty()) { + inputs.dir(projectDir.resolve("examples")) + } outputs.file(outputDir.resolve("Cargo.toml")) outputs.upToDateWhen { false } } @@ -271,6 +297,7 @@ tasks.register("fixManifests") { dependsOn("relocateRuntime") dependsOn("relocateAwsRuntime") dependsOn("relocateExamples") + dependsOn("fixExampleManifests") } tasks.register("hydrateReadme") { diff --git a/aws/sdk/examples/.gitignore b/aws/sdk/examples/.gitignore deleted file mode 100644 index 2c96eb1b65..0000000000 --- a/aws/sdk/examples/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target/ -Cargo.lock diff --git a/aws/sdk/examples/apigateway/Cargo.toml b/aws/sdk/examples/apigateway/Cargo.toml deleted file mode 100644 index 6debfba7d5..0000000000 --- a/aws/sdk/examples/apigateway/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "apigateway-code-examples" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-smithy-types-convert = { path = "../../build/aws-sdk/sdk/aws-smithy-types-convert", features = ["convert-chrono"] } -aws-sdk-apigateway = { path = "../../build/aws-sdk/sdk/apigateway" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/apigateway/README.md b/aws/sdk/examples/apigateway/README.md deleted file mode 100644 index dd23fc7b77..0000000000 --- a/aws/sdk/examples/apigateway/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# AWS SDK for Rust code examples for API Gateway - -Amazon API Gateway (API Gateway) enables you to create and deploy your own REST and WebSocket APIs at any scale. You can create robust, secure, and scalable APIs that access Amazon Web Services or other web services, as well as data that’s stored in the AWS Cloud. - -## Purpose - -These examples demonstrate how to perform several API Gateway operations using the alpha version of the AWS SDK for Rust. - -## Prerequisites - -You must have an AWS account, and have configured your default credentials and AWS Region as described in [https://github.com/awslabs/aws-sdk-rust](https://github.com/awslabs/aws-sdk-rust). - -## Running the code - -### get_rest_apis - -This example describes the API Gateway REST APIs in the Region. - -`cargo run --bin get_rest_apis -- [-r REGION] [-v]` - -- _REGION_ is name of the Region where the stacks are located. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### Notes - -- We recommend that you grant this code least privilege, - or at most the minimum permissions required to perform the task. - For more information, see - [Grant Least Privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege) - in the AWS Identity and Access Management User Guide. -- This code has not been tested in all AWS Regions. - Some AWS services are available only in specific - [Regions](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). -- Running this code might result in charges to your AWS account. - -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 \ No newline at end of file diff --git a/aws/sdk/examples/apigateway/src/bin/get_rest_apis.rs b/aws/sdk/examples/apigateway/src/bin/get_rest_apis.rs deleted file mode 100644 index 5e91cf536e..0000000000 --- a/aws/sdk/examples/apigateway/src/bin/get_rest_apis.rs +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_apigateway::{Client, Error, Region, PKG_VERSION}; -use aws_smithy_types_convert::date_time::DateTimeExt; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Displays the Amazon API Gateway REST APIs in the Region. -async fn show_apis(client: &Client) -> Result<(), Error> { - let resp = client.get_rest_apis().send().await?; - - for api in resp.items().unwrap_or_default() { - println!("ID: {}", api.id().unwrap_or_default()); - println!("Name: {}", api.name().unwrap_or_default()); - println!("Description: {}", api.description().unwrap_or_default()); - println!("Version: {}", api.version().unwrap_or_default()); - println!( - "Created: {}", - api.created_date().unwrap().to_chrono_utc() - ); - println!(); - } - - Ok(()) -} - -/// Displays information about the Amazon API Gateway REST APIs in the Region. -/// -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-v]` - Whether to display information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("APIGateway client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - show_apis(&client).await -} diff --git a/aws/sdk/examples/apigatewaymanagement/Cargo.toml b/aws/sdk/examples/apigatewaymanagement/Cargo.toml deleted file mode 100644 index f8d5bbbe91..0000000000 --- a/aws/sdk/examples/apigatewaymanagement/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "apigatewaymanagement-code-examples" -version = "0.1.0" -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-apigatewaymanagement = { path = "../../build/aws-sdk/sdk/apigatewaymanagement" } -http = "0.2.5" -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/apigatewaymanagement/README.md b/aws/sdk/examples/apigatewaymanagement/README.md deleted file mode 100644 index ee8150e62a..0000000000 --- a/aws/sdk/examples/apigatewaymanagement/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# AWS SDK for Rust code examples for API Gateway - -The Amazon API Gateway Management API allows you to directly manage runtime aspects of your deployed APIs. To use it, -you must explicitly set the SDK's endpoint to point to the endpoint of your deployed API. The endpoint will be of the -form `https://[api-id].execute-api.[region].amazonaws.com/[stage]` where: -* `api-id` is the ID of your API (eg. `xy4n5r0m12`) -* `region` is the region of your API (eg. `us-east-1`) -* `stage` is the deployment stage of your API (eg. `test`, `prod`, `beta`) -, or will be the endpoint corresponding to your API's -custom domain and base path, if applicable. - -### Notes - -- We recommend that you grant this code least privilege, or at most the minimum permissions required to perform the - task. For more information, see - [Grant Least Privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege) - in the AWS Identity and Access Management User Guide. -- This code has not been tested in all AWS Regions. Some AWS services are available only in specific - [Regions](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). -- Running this code might result in charges to your AWS account. - -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 diff --git a/aws/sdk/examples/apigatewaymanagement/src/bin/post_to_connection.rs b/aws/sdk/examples/apigatewaymanagement/src/bin/post_to_connection.rs deleted file mode 100644 index edc503bcd7..0000000000 --- a/aws/sdk/examples/apigatewaymanagement/src/bin/post_to_connection.rs +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_apigatewaymanagement::{config, Blob, Client, Endpoint, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -/// AWS apigatewaymanagenent must be used with a custom endpoint, which this example demonstrates how to set. -/// -/// Usage: -/// 1. Setup a Websocket API Gateway endpoint with a route configured. -/// 2. Connect to the route with `wscat`: `wscat -c wss://.execute-api..amazonaws.com//` -/// 2. Determine the connection id (eg. by configuring your route to echo the connection id into the websocket) -/// 3. Invoke this example. The `data` sent should appear in `wscat` -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, - - /// API ID for your API - #[structopt(short, long)] - api_id: String, - - /// Deployment stage for your API - #[structopt(short, long)] - stage: String, - - /// Connection Id to send data to - #[structopt(short, long)] - connection_id: String, - - /// Data to send to the connection - #[structopt(short, long)] - data: String, -} - -/// Displays information about the Amazon API Gateway REST APIs in the Region. -/// -/// # Arguments -/// -/// * `--api-id` - API ID for your API -/// * `--stage` - Stage for your API -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-v]` - Whether to display information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let Opt { - region, - verbose, - api_id, - stage, - connection_id, - data, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - let region = region_provider.region().await.expect("region must be set"); - if verbose { - println!("APIGatewayManagement client version: {}", PKG_VERSION); - println!("Region: {}", region.as_ref()); - - println!(); - } - - let uri = format!( - "https://{api_id}.execute-api.{region}.amazonaws.com/{stage}", - api_id = api_id, - region = region, - stage = stage - ) - .parse() - .expect("could not construct valid URI for endpoint"); - let endpoint = Endpoint::immutable(uri); - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let api_management_config = config::Builder::from(&shared_config) - .endpoint_resolver(endpoint) - .build(); - let client = Client::from_conf(api_management_config); - - client - .post_to_connection() - .connection_id(connection_id) - .data(Blob::new(data)) - .send() - .await?; - Ok(()) -} diff --git a/aws/sdk/examples/applicationautoscaling/Cargo.toml b/aws/sdk/examples/applicationautoscaling/Cargo.toml deleted file mode 100644 index 6112338400..0000000000 --- a/aws/sdk/examples/applicationautoscaling/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "applicationautoscaling-code-examples" -version = "0.1.0" -authors = ["John DiSanti , Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-applicationautoscaling = { path = "../../build/aws-sdk/sdk/applicationautoscaling" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/applicationautoscaling/README.md b/aws/sdk/examples/applicationautoscaling/README.md deleted file mode 100644 index 64b7d5b5eb..0000000000 --- a/aws/sdk/examples/applicationautoscaling/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# AWS SDK for Rust code examples for Application Auto Scaling - -Application Auto Scaling enables auto scaling for resources beyond just EC2, either with scaling policies or with scheduled scaling. - -## Purpose - -These examples demonstrate how to perform several Application Auto Scaling operations using the alpha version of the AWS SDK for Rust. - -## Prerequisites - -You must have an AWS account, and have configured your default credentials and AWS Region as described in [https://github.com/awslabs/aws-sdk-rust](https://github.com/awslabs/aws-sdk-rust). - -## Running the code - -### describe-scaling-policies - -This example lists your Application Auto Scaling policies in the Region. - -`cargo run --bin describe-scaling-policies -- [-r REGION] [-v]` - -- _REGION_ is name of the Region where the stacks are located. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -## Notes - -- We recommend that you grant this code least privilege, - or at most the minimum permissions required to perform the task. - For more information, see - [Grant Least Privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege) - in the AWS Identity and Access Management User Guide. -- This code has not been tested in all AWS Regions. - Some AWS services are available only in specific - [Regions](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). -- Running this code might result in charges to your AWS account. - -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 \ No newline at end of file diff --git a/aws/sdk/examples/applicationautoscaling/src/bin/describe-scaling-policies.rs b/aws/sdk/examples/applicationautoscaling/src/bin/describe-scaling-policies.rs deleted file mode 100644 index 5fe8b614d1..0000000000 --- a/aws/sdk/examples/applicationautoscaling/src/bin/describe-scaling-policies.rs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_applicationautoscaling::model::ServiceNamespace; -use aws_sdk_applicationautoscaling::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Lists the Application Auto Scaling policies. -async fn show_policies(client: &Client) -> Result<(), Error> { - let response = client - .describe_scaling_policies() - .service_namespace(ServiceNamespace::Ec2) - .send() - .await?; - if let Some(policies) = response.scaling_policies { - println!("Auto Scaling Policies:"); - for policy in policies { - println!("{:?}\n", policy); - } - } - println!("Next token: {:?}", response.next_token); - - Ok(()) -} - -/// Lists your Application Auto Scaling policies in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The region containing the buckets. -/// 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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!("Application Auto Scaling client version: {}", PKG_VERSION); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - println!(); - } - - let client = Client::new(&shared_config); - - show_policies(&client).await -} diff --git a/aws/sdk/examples/autoscaling/Cargo.toml b/aws/sdk/examples/autoscaling/Cargo.toml deleted file mode 100644 index d5b14b273a..0000000000 --- a/aws/sdk/examples/autoscaling/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "autoscaling-code-examples" -version = "0.1.0" -authors = ["Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-autoscaling = { path = "../../build/aws-sdk/sdk/autoscaling" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/autoscaling/README.md b/aws/sdk/examples/autoscaling/README.md deleted file mode 100644 index 13a0784f0f..0000000000 --- a/aws/sdk/examples/autoscaling/README.md +++ /dev/null @@ -1,77 +0,0 @@ -# AWS SDK for Rust code examples for Amazon EC2 Auto Scaling groups - -An Amazon EC2 Auto Scaling group (Auto Scaling group) enables you to treat a collection of Amazon EC2 instances as a logical grouping for the purposes of automatic scaling and management. - -## Purpose - -These examples demonstrate how to perform several Auto Scaling group operations using the alpha version of the AWS SDK for Rust. - -## Prerequisites - -You must have an AWS account, and have configured your default credentials and AWS Region as described in [https://github.com/awslabs/aws-sdk-rust](https://github.com/awslabs/aws-sdk-rust). - -## Running the code - -### create-autoscaling-group - -This example creates an Auto Scaling group with an initial EC2 instance in the Region. - -`cargo run --bin create-autoscaling-group -- -a AUTOSCALING-NAME -i INSTANCE-ID [-r REGION] [-v]` - -- _AUTOSCALING-NAME_ is the name of the Auto Scaling group. -- _INSTANCE-ID_ is the ID of the EC2 instance to add to the Auto Scaling group. -- _REGION_ is name of the Region where the stacks are located. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### delete-autoscaling-group - -This example deletes an Auto Scaling group in the Region. - -`cargo run --bin delete-autoscaling-group -- -a AUTOSCALING-NAME [-f] [-r REGION] [-v]` - -- _AUTOSCALING-NAME_ is the name of the Auto Scaling group. -- __-f__ forces the deletion. -- _REGION_ is name of the Region where the stacks are located. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### list-autoscaling-groups - -This example lists your Amazon EC2 Auto Scaling groups in the Region. - -`cargo run --bin list-autoscaling-groups -- [-r REGION] [-v]` - -- _REGION_ is name of the Region where the stacks are located. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### update-autoscaling-group - -This example updates an Auto Scaling group in the Region to a new maximum size. - -`cargo run --bin update-autoscaling-group -- -a AUTOSCALING-NAME -m MAXIMUM-SiZE [-r REGION] [-v]` - -- _AUTOSCALING-NAME_ is the name of the Auto Scaling group. -- _MAXIMUM-SiZE_ is the mazimum size of the Auto Scaling group. -- _REGION_ is name of the Region where the stacks are located. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### Notes - -- We recommend that you grant this code least privilege, - or at most the minimum permissions required to perform the task. - For more information, see - [Grant Least Privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege) - in the AWS Identity and Access Management User Guide. -- This code has not been tested in all AWS Regions. - Some AWS services are available only in specific - [Regions](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). -- Running this code might result in charges to your AWS account. - -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 \ No newline at end of file diff --git a/aws/sdk/examples/autoscaling/src/bin/create-autoscaling-group.rs b/aws/sdk/examples/autoscaling/src/bin/create-autoscaling-group.rs deleted file mode 100644 index 92dfd1d999..0000000000 --- a/aws/sdk/examples/autoscaling/src/bin/create-autoscaling-group.rs +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_autoscaling::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The name of the Amazon EC2 Auto Scaling group. - #[structopt(short, long)] - autoscaling_name: String, - - /// The ID of the EC2 instance to add to the Auto Scaling group. - #[structopt(short, long)] - instance_id: String, - - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Creates a group. -async fn create_group(client: &Client, name: &str, id: &str) -> Result<(), Error> { - client - .create_auto_scaling_group() - .auto_scaling_group_name(name) - .instance_id(id) - .min_size(1) - .max_size(5) - .send() - .await?; - - println!("Created AutoScaling group"); - - Ok(()) -} - -/// Creates an Auto Scaling group in the Region. -/// # Arguments -/// -/// * `-a AUTOSCALING-NAME` - The name of the Auto Scaling group. -/// * `-i INSTANCE-ID` - The ID of the EC2 instance to add to the Auto Scaling group. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - autoscaling_name, - instance_id, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("Auto Scaling client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("Auto Scaling group name: {}", &autoscaling_name); - println!("Instance ID: {}", &instance_id); - - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - create_group(&client, &autoscaling_name, &instance_id).await -} diff --git a/aws/sdk/examples/autoscaling/src/bin/delete-autoscaling-group.rs b/aws/sdk/examples/autoscaling/src/bin/delete-autoscaling-group.rs deleted file mode 100644 index 1647d7227d..0000000000 --- a/aws/sdk/examples/autoscaling/src/bin/delete-autoscaling-group.rs +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_autoscaling::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The name of the Amazon EC2 Auto Scaling group. - #[structopt(short, long)] - autoscaling_name: String, - - /// Whether to force the deletion. - #[structopt(short, long)] - force: bool, - - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Deletes a group. -async fn delete_group(client: &Client, name: &str, force: bool) -> Result<(), Error> { - client - .delete_auto_scaling_group() - .auto_scaling_group_name(name) - .set_force_delete(force.then(|| true)) - .send() - .await?; - - println!("Deleted Auto Scaling group"); - - Ok(()) -} - -/// Updates an Auto Scaling group in the Region to the specified maximum size. -/// # Arguments -/// -/// * `-a AUTOSCALING-NAME` - The name of the Auto Scaling group. -/// * - [-f] - Whether to force the deletion. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - autoscaling_name, - force, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - println!(); - - if verbose { - println!("Auto Scaling client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("Auto Scaling group name: {}", &autoscaling_name); - println!("Force deletion?: {}", &force); - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - delete_group(&client, &autoscaling_name, force).await -} diff --git a/aws/sdk/examples/autoscaling/src/bin/list-autoscaling-groups.rs b/aws/sdk/examples/autoscaling/src/bin/list-autoscaling-groups.rs deleted file mode 100644 index 3f27a5906e..0000000000 --- a/aws/sdk/examples/autoscaling/src/bin/list-autoscaling-groups.rs +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_autoscaling::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Lists your groups. -async fn list_groups(client: &Client) -> Result<(), Error> { - let resp = client.describe_auto_scaling_groups().send().await?; - - println!("Groups:"); - - let groups = resp.auto_scaling_groups.unwrap_or_default(); - - for group in &groups { - println!( - " {}", - group.auto_scaling_group_name.as_deref().unwrap_or_default() - ); - println!( - " ARN: {}", - group.auto_scaling_group_arn.as_deref().unwrap_or_default() - ); - println!(" Minimum size: {}", group.min_size.unwrap_or_default()); - println!(" Maximum size: {}", group.max_size.unwrap_or_default()); - println!(); - } - - println!("Found {} group(s)", groups.len()); - - Ok(()) -} - -/// Lists your Amazon EC2 Auto Scaling groups in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("Auto Scaling client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - list_groups(&client).await -} diff --git a/aws/sdk/examples/autoscaling/src/bin/update-autoscaling-group.rs b/aws/sdk/examples/autoscaling/src/bin/update-autoscaling-group.rs deleted file mode 100644 index 3d222f4aa6..0000000000 --- a/aws/sdk/examples/autoscaling/src/bin/update-autoscaling-group.rs +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_autoscaling::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The name of the Amazon EC2 Auto Scaling group. - #[structopt(short, long)] - autoscaling_name: String, - - /// The new maximum size of the Auto Scaling group. - #[structopt(short, long)] - max_size: i32, - - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Updates the size of a group. -async fn update_group(client: &Client, name: &str, size: i32) -> Result<(), Error> { - client - .update_auto_scaling_group() - .auto_scaling_group_name(name) - .max_size(size) - .send() - .await?; - - println!("Updated AutoScaling group"); - - Ok(()) -} - -/// Updates an Auto Scaling group in the Region to a new maximum size. -/// # Arguments -/// -/// * `-a AUTOSCALING-NAME` - The name of the Auto Scaling group. -/// * `-m MAXIMUM-SiZE` - The mazimum size of the Auto Scaling group. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - autoscaling_name, - max_size, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("Auto Scaling client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("AutoScaling group name: {}", &autoscaling_name); - println!("Max size: {}", &max_size); - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - update_group(&client, &autoscaling_name, max_size).await -} diff --git a/aws/sdk/examples/autoscalingplans/Cargo.toml b/aws/sdk/examples/autoscalingplans/Cargo.toml deleted file mode 100644 index ef73b6ec54..0000000000 --- a/aws/sdk/examples/autoscalingplans/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "autoscalingplans" -version = "0.1.0" -authors = ["John DiSanti "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-autoscalingplans = { path = "../../build/aws-sdk/sdk/autoscalingplans" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/autoscalingplans/src/bin/describe-scaling-plans.rs b/aws/sdk/examples/autoscalingplans/src/bin/describe-scaling-plans.rs deleted file mode 100644 index d8e0b79515..0000000000 --- a/aws/sdk/examples/autoscalingplans/src/bin/describe-scaling-plans.rs +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_autoscalingplans::{Client, Error, Region}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The region - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your Amazon Cognito identities -/// # Arguments -/// -/// * `[-r REGION]` - The region containing the buckets. -/// 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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!( - "Auto Scaling Plans client version: {}", - aws_sdk_autoscalingplans::PKG_VERSION - ); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - println!(); - } - - let client = Client::new(&shared_config); - - let response = client.describe_scaling_plans().send().await?; - if let Some(plans) = response.scaling_plans { - println!("Auto Scaling Plans:"); - for plan in plans { - println!("{:?}\n", plan); - } - } - println!("Next token: {:?}", response.next_token); - - Ok(()) -} diff --git a/aws/sdk/examples/batch/Cargo.toml b/aws/sdk/examples/batch/Cargo.toml deleted file mode 100644 index cdb1ed878d..0000000000 --- a/aws/sdk/examples/batch/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "batch-code-examples" -version = "0.1.0" -authors = ["Alistair McLean ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-batch = { path = "../../build/aws-sdk/sdk/batch" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/batch/src/bin/helloworld.rs b/aws/sdk/examples/batch/src/bin/helloworld.rs deleted file mode 100644 index e90c75531b..0000000000 --- a/aws/sdk/examples/batch/src/bin/helloworld.rs +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_batch::{Client, Region}; - -#[tokio::main] -async fn main() -> Result<(), aws_sdk_batch::Error> { - tracing_subscriber::fmt::init(); - - let region_provider = RegionProviderChain::default_provider().or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - let rsp = client.describe_compute_environments().send().await?; - - let compute_envs = rsp.compute_environments.unwrap_or_default(); - println!("Compute environments ({}):", compute_envs.len()); - for env in compute_envs { - let arn = env.compute_environment_arn.as_deref().unwrap_or_default(); - let name = env.compute_environment_name.as_deref().unwrap_or_default(); - - println!( - " Compute Environment Name : {}, Compute Environment ARN : {}", - name, arn - ); - } - - Ok(()) -} diff --git a/aws/sdk/examples/ca-certs/Cargo.toml b/aws/sdk/examples/ca-certs/Cargo.toml deleted file mode 100644 index 7ab851146f..0000000000 --- a/aws/sdk/examples/ca-certs/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "custom-root-certs" -version = "0.1.0" -authors = ["rcoh@amazon.com>"] -edition = "2018" - -description = "An example demonstrating setting a custom root certificate with rustls" - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client" } -# bringing our own HTTPs so no need for the default features -aws-sdk-s3 = { package = "aws-sdk-s3", path = "../../build/aws-sdk/sdk/s3", default-features = false } -tokio = { version = "1", features = ["full"] } -rustls = "0.20.2" -hyper-rustls = { version = "0.23.0", features = ["http2"] } diff --git a/aws/sdk/examples/ca-certs/src/main.rs b/aws/sdk/examples/ca-certs/src/main.rs deleted file mode 100644 index c6991f188a..0000000000 --- a/aws/sdk/examples/ca-certs/src/main.rs +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::provider_config::ProviderConfig; -use aws_smithy_client::hyper_ext; -use rustls::RootCertStore; - -#[tokio::main] -async fn main() { - // insert your root CAs - let root_store = RootCertStore::empty(); - let config = rustls::ClientConfig::builder() - .with_safe_defaults() - .with_root_certificates(root_store) - .with_no_client_auth(); - let rustls_connector = hyper_rustls::HttpsConnectorBuilder::new() - .with_tls_config(config) - .https_only() - .enable_http1() - .enable_http2() - .build(); - - // Currently, aws_config connectors are buildable directly from something that implements `hyper::Connect`. - // This enables different providers to construct clients with different timeouts. - let provider_config = ProviderConfig::default().with_tcp_connector(rustls_connector.clone()); - let shared_conf = aws_config::from_env() - .configure(provider_config) - .load() - .await; - let s3_config = aws_sdk_s3::Config::from(&shared_conf); - // however, for generated clients, they are constructred from a Hyper adapter directly: - let s3_client = aws_sdk_s3::Client::from_conf_conn( - s3_config, - hyper_ext::Adapter::builder().build(rustls_connector), - ); - let _ = s3_client.list_buckets().send().await; -} diff --git a/aws/sdk/examples/cloudformation/Cargo.toml b/aws/sdk/examples/cloudformation/Cargo.toml deleted file mode 100644 index 6651a5dd98..0000000000 --- a/aws/sdk/examples/cloudformation/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "cloudformation-code-examples" -version = "0.1.0" -authors = ["Alistair McLean ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-cloudformation = { package = "aws-sdk-cloudformation", path = "../../build/aws-sdk/sdk/cloudformation" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/cloudformation/src/bin/create-stack.rs b/aws/sdk/examples/cloudformation/src/bin/create-stack.rs deleted file mode 100644 index 184a34fd01..0000000000 --- a/aws/sdk/examples/cloudformation/src/bin/create-stack.rs +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_cloudformation::{Client, Error, Region, PKG_VERSION}; - -use std::fs; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the AWS CloudFormation stack. - #[structopt(short, long)] - stack_name: String, - - /// The name of the file containing the stack template. - #[structopt(short, long)] - template_file: String, - - /// Whether to display additional runtime information. - #[structopt(short, long)] - verbose: bool, -} - -/// Creates a CloudFormation stack in the region. -/// # Arguments -/// -/// * `-s STACK-NAME` - The name of the stack. -/// * `-t TEMPLATE-NAME` - The name of the file containing the stack template. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - stack_name, - template_file, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("CloudFormation client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Stack: {}", &stack_name); - println!("Template: {}", &template_file); - println!(); - } - - // Get content of template file as a string. - let contents = - fs::read_to_string(template_file).expect("Something went wrong reading the file"); - - client - .create_stack() - .stack_name(stack_name) - .template_body(contents) - .send() - .await?; - - println!("Stack created."); - println!("Use describe-stacks with your stack name to see the status of your stack."); - println!("You cannot use/deploy the stack until the status is 'CreateComplete'."); - println!(); - - Ok(()) -} diff --git a/aws/sdk/examples/cloudformation/src/bin/delete-stack.rs b/aws/sdk/examples/cloudformation/src/bin/delete-stack.rs deleted file mode 100644 index 8e737d7796..0000000000 --- a/aws/sdk/examples/cloudformation/src/bin/delete-stack.rs +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_cloudformation::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the AWS CloudFormation stack. - #[structopt(short, long)] - stack_name: String, - - /// Whether to display additional runtime information. - #[structopt(short, long)] - verbose: bool, -} - -/// Deletes a CloudFormation stack. -/// # Arguments -/// -/// * `-s STACK-NAME` - The name of the stack. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - stack_name, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("CloudFormation client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Stack: {}", &stack_name); - println!(); - } - - client.delete_stack().stack_name(stack_name).send().await?; - - println!("Stack deleted"); - println!(); - - Ok(()) -} diff --git a/aws/sdk/examples/cloudformation/src/bin/describe-stack.rs b/aws/sdk/examples/cloudformation/src/bin/describe-stack.rs deleted file mode 100644 index 02bf412a06..0000000000 --- a/aws/sdk/examples/cloudformation/src/bin/describe-stack.rs +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_cloudformation::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the AWS CloudFormation stack. - #[structopt(short, long)] - stack_name: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Retrieves the status of a CloudFormation stack in the Region. -/// # Arguments -/// -/// * `-s STACK-NAME` - The name of the stack. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - stack_name, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("CloudFormation version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Stack: {}", &stack_name); - println!(); - } - - // Return an error if stack_name does not exist - let resp = client - .describe_stacks() - .stack_name(stack_name) - .send() - .await?; - - // Otherwise we get a list of stacks that match the stack_name. - // The list should only have one item, so just access is via pop(). - let status = resp.stacks.unwrap_or_default().pop().unwrap().stack_status; - - println!("Stack status: {:?}", status); - - println!(); - - Ok(()) -} diff --git a/aws/sdk/examples/cloudformation/src/bin/list-stacks.rs b/aws/sdk/examples/cloudformation/src/bin/list-stacks.rs deleted file mode 100644 index 93e240e009..0000000000 --- a/aws/sdk/examples/cloudformation/src/bin/list-stacks.rs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_cloudformation::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the name and status of your AWS CloudFormation stacks in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("CloudFormation client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!(); - } - - let stacks = client.list_stacks().send().await?; - - for s in stacks.stack_summaries.unwrap_or_default() { - println!("{}", s.stack_name.as_deref().unwrap_or_default()); - println!(" Status: {:?}", s.stack_status.unwrap()); - println!(); - } - - Ok(()) -} diff --git a/aws/sdk/examples/cloudwatch/Cargo.toml b/aws/sdk/examples/cloudwatch/Cargo.toml deleted file mode 100644 index 3b85ebb1ac..0000000000 --- a/aws/sdk/examples/cloudwatch/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "cloudwatch-code-examples" -version = "0.1.0" -authors = ["AWS Rust SDK Team ", "Russell Cohen "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-cloudwatch = { path = "../../build/aws-sdk/sdk/cloudwatch" } -tokio = { version = "1", features = ["full"] } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/cloudwatch/src/bin/list-metrics.rs b/aws/sdk/examples/cloudwatch/src/bin/list-metrics.rs deleted file mode 100644 index 54b635a58b..0000000000 --- a/aws/sdk/examples/cloudwatch/src/bin/list-metrics.rs +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_sdk_cloudwatch::Client; - -#[tokio::main] -async fn main() -> Result<(), aws_sdk_cloudwatch::Error> { - tracing_subscriber::fmt::init(); - - let shared_config = aws_config::load_from_env().await; - let client = Client::new(&shared_config); - let rsp = client.list_metrics().send().await?; - let metrics = rsp.metrics.unwrap_or_default(); - println!("found {} metric(s)", metrics.len()); - for metric in metrics { - println!("metric: {:?}", metric); - } - Ok(()) -} diff --git a/aws/sdk/examples/cloudwatchlogs/Cargo.toml b/aws/sdk/examples/cloudwatchlogs/Cargo.toml deleted file mode 100644 index ac544ec938..0000000000 --- a/aws/sdk/examples/cloudwatchlogs/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "cloudwatchlogs-code-examples" -version = "0.1.0" -authors = ["AWS Rust SDK Team ", "Russell Cohen "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-cloudwatchlogs = { path = "../../build/aws-sdk/sdk/cloudwatchlogs" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } diff --git a/aws/sdk/examples/cloudwatchlogs/src/bin/get-log-events.rs b/aws/sdk/examples/cloudwatchlogs/src/bin/get-log-events.rs deleted file mode 100644 index cb452dacd3..0000000000 --- a/aws/sdk/examples/cloudwatchlogs/src/bin/get-log-events.rs +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_sdk_cloudwatchlogs::Client; - -#[tokio::main] -async fn main() -> Result<(), aws_sdk_cloudwatchlogs::Error> { - tracing_subscriber::fmt::init(); - - let shared_config = aws_config::load_from_env().await; - let client = Client::new(&shared_config); - /* uncomment to create a log group */ - /* - client - .create_log_group() - .log_group_name("test-logs") - .send() - .await?; - - client - .create_log_stream() - .log_group_name("test-logs") - .log_stream_name("test-stream") - .send() - .await?; - */ - let log_events = client - .get_log_events() - .log_group_name("test-logs") - .log_stream_name("test-stream") - .send() - .await?; - let events = log_events.events.unwrap_or_default(); - println!("number of events: {}", events.len()); - for event in events { - println!("message: {}", event.message.unwrap_or_default()); - } - Ok(()) -} diff --git a/aws/sdk/examples/cognitoidentity/Cargo.toml b/aws/sdk/examples/cognitoidentity/Cargo.toml deleted file mode 100644 index 1bdcdcdbc2..0000000000 --- a/aws/sdk/examples/cognitoidentity/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "cognitoidentity-code-examples" -version = "0.1.0" -authors = ["John DiSanti ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-smithy-types-convert = { path = "../../build/aws-sdk/sdk/aws-smithy-types-convert", features = ["convert-chrono"] } -aws-sdk-cognitoidentity = { path = "../../build/aws-sdk/sdk/cognitoidentity" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -chrono = "0.4" -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/cognitoidentity/src/bin/describe-identity-pool.rs b/aws/sdk/examples/cognitoidentity/src/bin/describe-identity-pool.rs deleted file mode 100644 index 56a1f12fdf..0000000000 --- a/aws/sdk/examples/cognitoidentity/src/bin/describe-identity-pool.rs +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_cognitoidentity::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The ID of the identity pool to describe. - #[structopt(short, long)] - identity_pool_id: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Displays some information about an Amazon Cognito identitiy pool. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - identity_pool_id, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("Cognito client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Identity pool ID: {}", identity_pool_id); - println!(); - } - - let client = Client::new(&shared_config); - - let response = client - .describe_identity_pool() - .identity_pool_id(identity_pool_id) - .send() - .await?; - - let allow_classic = response.allow_classic_flow().unwrap_or_default(); - let allow_unauth_ids = response.allow_unauthenticated_identities(); - println!(" Allow classic flow {}", allow_classic); - println!(" Allow unauthenticated identities: {}", allow_unauth_ids); - if let Some(providers) = response.cognito_identity_providers() { - println!(" Identity Providers:"); - for provider in providers { - let client_id = provider.client_id().unwrap_or_default(); - let name = provider.provider_name().unwrap_or_default(); - let server_side_check = provider.server_side_token_check().unwrap_or_default(); - - println!(" Client ID: {}", client_id); - println!(" Name: {}", name); - println!(" Service-side token check: {}", server_side_check); - println!(); - } - } - - let developer_provider = response.developer_provider_name().unwrap_or_default(); - let id = response.identity_pool_id().unwrap_or_default(); - let name = response.identity_pool_name().unwrap_or_default(); - - println!(" Developer provider: {}", developer_provider); - println!(" Identity pool ID: {}", id); - println!(" Identity pool name: {}", name); - - if let Some(tags) = response.identity_pool_tags() { - println!(" Tags:"); - for (key, value) in tags { - println!(" key: {}", key); - println!(" value: {}", value); - } - } - - if let Some(open_id_arns) = response.open_id_connect_provider_ar_ns() { - println!(" Open ID provider ARNs:"); - for arn in open_id_arns { - println!(" {}", arn); - } - } - - if let Some(saml_arns) = response.saml_provider_ar_ns() { - println!(" SAML provider ARNs:"); - for arn in saml_arns { - println!(" {}", arn); - } - } - - // SupportedLoginProviders - if let Some(login_providers) = response.supported_login_providers() { - println!(" Supported login providers:"); - for (key, value) in login_providers { - println!(" key: {}", key); - println!(" value: {}", value); - } - } - - println!(); - - Ok(()) -} diff --git a/aws/sdk/examples/cognitoidentity/src/bin/list-identity-pools.rs b/aws/sdk/examples/cognitoidentity/src/bin/list-identity-pools.rs deleted file mode 100644 index 86c396f02a..0000000000 --- a/aws/sdk/examples/cognitoidentity/src/bin/list-identity-pools.rs +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_cognitoidentity::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your Amazon Cognito identity pools in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("Cognito client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!(); - } - - let client = Client::new(&shared_config); - - let response = client.list_identity_pools().max_results(10).send().await?; - - // Print IDs and names of pools. - if let Some(pools) = response.identity_pools() { - println!("Identity pools:"); - for pool in pools { - let id = pool.identity_pool_id().unwrap_or_default(); - let name = pool.identity_pool_name().unwrap_or_default(); - println!(" Identity pool ID: {}", id); - println!(" Identity pool name: {}", name); - println!(); - } - } - - println!("Next token: {:?}", response.next_token()); - - Ok(()) -} diff --git a/aws/sdk/examples/cognitoidentity/src/bin/list-pool-identities.rs b/aws/sdk/examples/cognitoidentity/src/bin/list-pool-identities.rs deleted file mode 100644 index 35a4d9ae69..0000000000 --- a/aws/sdk/examples/cognitoidentity/src/bin/list-pool-identities.rs +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_cognitoidentity::{Client, Error, Region, PKG_VERSION}; -use aws_smithy_types_convert::date_time::DateTimeExt; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The ID of the identity pool to describe. - #[structopt(short, long)] - identity_pool_id: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the identities in an Amazon Cognito identity pool. -/// # Arguments -/// -/// * `-i IDENTITY-POOL-ID` - The ID of the identity pool. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - identity_pool_id, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("Cognito client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Identity pool ID: {}", identity_pool_id); - println!(); - } - - let client = Client::new(&shared_config); - - let response = client - .list_identities() - .identity_pool_id(identity_pool_id) - .max_results(10) - .send() - .await?; - - if let Some(ids) = response.identities() { - println!("Identitities:"); - for id in ids { - let creation_timestamp = id.creation_date().unwrap().to_chrono_utc(); - let idid = id.identity_id().unwrap_or_default(); - let mod_timestamp = id.last_modified_date().unwrap().to_chrono_utc(); - println!(" Creation date: {}", creation_timestamp); - println!(" ID: {}", idid); - println!(" Last modified date: {}", mod_timestamp); - - println!(" Logins:"); - for login in id.logins().unwrap_or_default() { - println!(" {}", login); - } - - println!(); - } - } - - println!("Next token: {:?}", response.next_token()); - - println!(); - - Ok(()) -} diff --git a/aws/sdk/examples/cognitoidentityprovider/Cargo.toml b/aws/sdk/examples/cognitoidentityprovider/Cargo.toml deleted file mode 100644 index 8f30e4bcb5..0000000000 --- a/aws/sdk/examples/cognitoidentityprovider/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "cognitoidentityprovider-code-examples" -version = "0.1.0" -authors = ["John DiSanti ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-smithy-types-convert = { path = "../../build/aws-sdk/sdk/aws-smithy-types-convert", features = ["convert-chrono"] } -aws-sdk-cognitoidentityprovider = { package = "aws-sdk-cognitoidentityprovider", path = "../../build/aws-sdk/sdk/cognitoidentityprovider" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/cognitoidentityprovider/src/bin/list-user-pools.rs b/aws/sdk/examples/cognitoidentityprovider/src/bin/list-user-pools.rs deleted file mode 100644 index 4a13753987..0000000000 --- a/aws/sdk/examples/cognitoidentityprovider/src/bin/list-user-pools.rs +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_cognitoidentityprovider::{Client, Error, Region, PKG_VERSION}; -use aws_smithy_types_convert::date_time::DateTimeExt; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your Amazon Cognito user pools in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The region containing the buckets. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("Cognito client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!(); - } - - let response = client.list_user_pools().max_results(10).send().await?; - if let Some(pools) = response.user_pools() { - println!("User pools:"); - for pool in pools { - println!(" ID: {}", pool.id().unwrap_or_default()); - println!(" Name: {}", pool.name().unwrap_or_default()); - println!(" Status: {:?}", pool.status()); - println!(" Lambda Config: {:?}", pool.lambda_config().unwrap()); - println!( - " Last modified: {}", - pool.last_modified_date().unwrap().to_chrono_utc() - ); - println!( - " Creation date: {:?}", - pool.creation_date().unwrap().to_chrono_utc() - ); - println!(); - } - } - println!("Next token: {}", response.next_token().unwrap_or_default()); - - Ok(()) -} diff --git a/aws/sdk/examples/cognitosync/Cargo.toml b/aws/sdk/examples/cognitosync/Cargo.toml deleted file mode 100644 index cd2323919b..0000000000 --- a/aws/sdk/examples/cognitosync/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "cognitosync-code-examples" -version = "0.1.0" -authors = ["John DiSanti ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-smithy-types-convert = { path = "../../build/aws-sdk/sdk/aws-smithy-types-convert", features = ["convert-chrono"] } -aws-sdk-cognitosync = { package = "aws-sdk-cognitosync", path = "../../build/aws-sdk/sdk/cognitosync" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/cognitosync/src/bin/list-identity-pool-usage.rs b/aws/sdk/examples/cognitosync/src/bin/list-identity-pool-usage.rs deleted file mode 100644 index 23c9354bbf..0000000000 --- a/aws/sdk/examples/cognitosync/src/bin/list-identity-pool-usage.rs +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_cognitosync::{Client, Error, Region, PKG_VERSION}; -use aws_smithy_types_convert::date_time::DateTimeExt; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the identity pools registered with Amazon Cognito in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The region containing the buckets. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-g]` - Whether to display buckets in all regions. -/// * `[-v]` - Whether to display additional information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Cognito client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!(); - } - - let response = client - .list_identity_pool_usage() - .max_results(10) - .send() - .await?; - - if let Some(pools) = response.identity_pool_usages() { - println!("Identity pools:"); - - for pool in pools { - println!( - " Identity pool ID: {}", - pool.identity_pool_id().unwrap_or_default() - ); - println!( - " Data storage: {}", - pool.data_storage().unwrap_or_default() - ); - println!( - " Sync sessions count: {}", - pool.sync_sessions_count().unwrap_or_default() - ); - println!( - " Last modified: {}", - pool.last_modified_date().unwrap().to_chrono_utc() - ); - println!(); - } - } - - println!("Next token: {:?}", response.next_token()); - - Ok(()) -} diff --git a/aws/sdk/examples/config/Cargo.toml b/aws/sdk/examples/config/Cargo.toml deleted file mode 100644 index 6485fa8358..0000000000 --- a/aws/sdk/examples/config/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "config-code-examples" -version = "0.1.0" -authors = ["Russell Cohen ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-config = { package = "aws-sdk-config", path = "../../build/aws-sdk/sdk/config" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/config/README.md b/aws/sdk/examples/config/README.md deleted file mode 100644 index 86c82c318e..0000000000 --- a/aws/sdk/examples/config/README.md +++ /dev/null @@ -1,129 +0,0 @@ -# AWS SDK for Rust code examples for AWS Config - -AWS Config - -## Purpose - -These examples demonstrate how to perform several AWS Config operations using the alpha version of the AWS SDK for Rust. - -## Prerequisites - -You must have an AWS account, and have configured your default credentials and AWS Region as described in [https://github.com/awslabs/aws-sdk-rust](https://github.com/awslabs/aws-sdk-rust). - -## Running the code - -### config-helloworld - -This example lists the configuration history for an AWS Config resource. - -`cargo run --bin config-helloworld -- -resource_id RESOURCE-ID -resource_type RESOURCE-TYPE NAME [-r REGION] [-v]` - -- _RESOURCE-ID_ is the ID of the AWS Config resource. -- _RESOURCE-TYPE_ is the type of the AWS Config resource, such as __AWS::EC2::SecurityGroup__. -- _REGION_ is the Region in which the client is created. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### delete-configuration-recorder - -This example deletes an AWS Config configuration recorder. - -`cargo run --bin delete-configuration-recorder -- -n NAME [-r REGION] [-v]` - -- _NAME_ is the name of the configuration recorder to delete. -- _REGION_ is the Region in which the client is created. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### delete-delivery-channel - -This example deletes an AWS Config delivery channel. - -`cargo run --bin delete-delivery-channel -- -c CHANNEL [-r REGION] [-v]` - -- _CHANNEL_ is the name of the channel to delete. -- _REGION_ is the Region in which the client is created. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### enable-config - -This example enables AWS Config for a resource type, in the Region. - -`cargo run --bin enable-config -- -b BUCKET -i IAM-ARN -k KMS-ARN -n NAME -p PREFIX -s SNS-ARN -t TYPE [-r REGION] [-v]` - -- _BUCKET_ is the name of the Amazon bucket to which AWS Config delivers configuration snapshots and configuration history files. -- _IAM-ARN_ is the ARN of the IAM role that used to describe the AWS resources associated with the account. -- _KMS-ARN_ is the ARN of the KMS key that used to encrypt the data in the bucket. -- _NAME_ is the name of the configuration. -- _PREFIX_ is the prefix for the bucket. -- _SNS-ARN_ is the ARN of the Amazon SNS topic to which AWS Config sends notifications about configuration changes. -- _TYPE_ is the type of resource for AWS Config to support. - If not supplied, defaults to `AWS::DynamoDB::Table` (DynamoDB tables). -- _REGION_ is the Region in which the client is created. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### list-configuration-recorders - -This example lists the AWS Config configuration recorders in the Region. - -`cargo run --bin list-configuration-recorders -- [-r REGION] [-v]` - -- _REGION_ is the Region in which the client is created. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### list-delivery-channels - -This example lists the AWS Config delivery channels in the Region. - -`cargo run --bin list-delivery-channels -- [-r REGION] [-v]` - -- _REGION_ is the Region in which the client is created. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### list-resources - -This example lists your AWS Config resources, by resource type, in the Region. - -`cargo run --bin list-resources -- [-r REGION] [-v]` - -- _REGION_ is the Region in which the client is created. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### show-resource-history - -This example displays the configuration history for a resource. - -`cargo run --bin show-resource-history -- -i ID --resource-type RESOURCE-TYPE [-r REGION] [-v]` - -- _ID_ is the ID of the resource. -- _RESOURCE-TYPE_ is the resource type, such as `AWS::EC2::SecurityGroup`. -- _REGION_ is the Region in which the client is created. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -### Notes - -- We recommend that you grant this code least privilege, - or at most the minimum permissions required to perform the task. - For more information, see - [Grant Least Privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege) - in the AWS Identity and Access Management User Guide. -- This code has not been tested in all AWS Regions. - Some AWS services are available only in specific - [Regions](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). -- Running this code might result in charges to your AWS account. - -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 \ No newline at end of file diff --git a/aws/sdk/examples/config/src/bin/config-helloworld.rs b/aws/sdk/examples/config/src/bin/config-helloworld.rs deleted file mode 100644 index 7c0e77bcee..0000000000 --- a/aws/sdk/examples/config/src/bin/config-helloworld.rs +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_config::model::ResourceType; -use aws_sdk_config::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The resource id. - #[structopt(long)] - resource_id: String, - - /// The resource type, e.g. "AWS::EC2::SecurityGroup" - #[structopt(long)] - resource_type: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Retrieves the configuration history for a resource. -async fn get_history( - client: &aws_sdk_config::Client, - id: &str, - res: ResourceType, -) -> Result<(), aws_sdk_config::Error> { - let rsp = client - .get_resource_config_history() - .resource_id(id) - .resource_type(res) - .send() - .await?; - - println!("configuration history for {}:", id); - - for item in rsp.configuration_items.unwrap_or_default() { - println!("item: {:?}", item); - } - - Ok(()) -} - -/// Lists the configuration history for a resource in the Region. -/// -/// NOTE: AWS Config must be enabled to discover resources -/// # Arguments -/// -/// * `-resource_id RESOURCE-ID` - The ID of the resource. -/// * `-resource_type RESOURCE-TYPE` - The type of resource, such as **AWS::EC2::SecurityGroup**. -/// * `[-r REGION]` - The AWS Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-v]` - Whether to display information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let Opt { - region, - resource_id, - resource_type, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - - println!(); - - if verbose { - println!("Config client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - // parse resource type from user input - let parsed = ResourceType::from(resource_type.as_str()); - if matches!(parsed, ResourceType::Unknown(_)) { - panic!( - "unknown resource type: `{}`. Valid resource types: {:#?}", - &resource_type, - ResourceType::values() - ) - } - - get_history(&client, &resource_id, parsed).await -} diff --git a/aws/sdk/examples/config/src/bin/delete-configuration-recorder.rs b/aws/sdk/examples/config/src/bin/delete-configuration-recorder.rs deleted file mode 100644 index bea8889dc8..0000000000 --- a/aws/sdk/examples/config/src/bin/delete-configuration-recorder.rs +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_config::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the configuration recorder to delete. - #[structopt(short, long)] - name: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Deletes a configuration recorder. -async fn delete_recorder( - client: &aws_sdk_config::Client, - name: &str, -) -> Result<(), aws_sdk_config::Error> { - client - .delete_configuration_recorder() - .configuration_recorder_name(name) - .send() - .await?; - - println!("Done"); - - println!(); - - Ok(()) -} - -/// Deletes an AWS Config configuration recorder. -/// -/// # Arguments -/// -/// * `-n NAME` - The name of the configuration recorder to delete. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-v]` - Whether to display information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let Opt { - name, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("Config client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("Configuration recorder: {}", &name); - - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - delete_recorder(&client, &name).await -} diff --git a/aws/sdk/examples/config/src/bin/delete-delivery-channel.rs b/aws/sdk/examples/config/src/bin/delete-delivery-channel.rs deleted file mode 100644 index fca22c632a..0000000000 --- a/aws/sdk/examples/config/src/bin/delete-delivery-channel.rs +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_config::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The channel to delete. - #[structopt(short, long)] - channel: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Deletes a channel. -async fn delete_channel( - client: &aws_sdk_config::Client, - channel: &str, -) -> Result<(), aws_sdk_config::Error> { - client - .delete_delivery_channel() - .delivery_channel_name(channel) - .send() - .await?; - - println!("Done"); - - Ok(()) -} - -/// Deletes an AWS Config delivery channel. -/// -/// # Arguments -/// -/// * `-c CHANNEL` - The name of the channel to delete. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-v]` - Whether to display information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let Opt { - channel, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("Config client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("Delivery channel: {}", channel); - - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - delete_channel(&client, &channel).await -} diff --git a/aws/sdk/examples/config/src/bin/enable-config.rs b/aws/sdk/examples/config/src/bin/enable-config.rs deleted file mode 100644 index ac76590863..0000000000 --- a/aws/sdk/examples/config/src/bin/enable-config.rs +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_config::model::{ - ConfigSnapshotDeliveryProperties, ConfigurationRecorder, DeliveryChannel, - MaximumExecutionFrequency, RecordingGroup, ResourceType, -}; -use aws_sdk_config::{Client, Error, Region, PKG_VERSION}; -use std::process; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the Amazon bucket. - #[structopt(short, long)] - bucket: String, - - /// The ARN of the IAM role. - #[structopt(short, long)] - iam_arn: String, - - /// The ARN of the KMS key used to encrypt the data placed in the bucket. - #[structopt(short, long)] - kms_arn: String, - - /// The name of the configuration. - #[structopt(default_value = "default", short, long)] - name: String, - - /// The prefix for the bucket. - #[structopt(short, long)] - prefix: String, - - /// The ARN of the Amazon SNS topic. - #[structopt(short, long)] - sns_arn: String, - - /// The type of resource to record info about. - #[structopt(default_value = "AWS::DynamoDB::Table", short, long)] - type_: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Enables config. -async fn enable_config( - client: &aws_sdk_config::Client, - name: &str, - kms_arn: &str, - bucket: &str, - sns_arn: &str, - iam_arn: &str, - prefix: &str, -) -> Result<(), aws_sdk_config::Error> { - // If we already have a configuration recorder in the Region, we cannot create another. - let resp = client.describe_configuration_recorders().send().await?; - - let recorders = resp.configuration_recorders.unwrap_or_default(); - - //let num_recorders = recorders.len(); - - if recorders.is_empty() { - println!("You already have a configuration recorder in this region"); - println!("Use delete-configuration-recorder to delete it before you call this again."); - - for recorder in recorders { - println!("Recorder: {}", recorder.name.as_deref().unwrap_or_default()); - } - - process::exit(1); - } - - // If we already have a delivery channel in the Region, we cannot create another. - let resp = client.describe_delivery_channels().send().await?; - - let channels = resp.delivery_channels.unwrap_or_default(); - - let num_channels = channels.len(); - - if num_channels != 0 { - println!("You already have a delivery channel in this region"); - println!("Use delete-delivery-channel to delete it before you call this again."); - - for channel in channels { - println!(" Channel: {}", channel.name.as_deref().unwrap_or_default()); - } - - process::exit(1); - } - - let resource_types: Vec = vec![ResourceType::Topic]; - - let rec_group = RecordingGroup::builder() - .set_resource_types(Some(resource_types)) - .build(); - - let cfg_recorder = ConfigurationRecorder::builder() - .name(name) - .role_arn(iam_arn) - .set_recording_group(Some(rec_group)) - .build(); - - client - .put_configuration_recorder() - .configuration_recorder(cfg_recorder) - .send() - .await?; - - println!("Configured recorder."); - - // Create delivery channel - let snapshot_props = ConfigSnapshotDeliveryProperties::builder() - .delivery_frequency(MaximumExecutionFrequency::TwelveHours) - .build(); - - let delivery_channel = DeliveryChannel::builder() - .name(name) - .s3_bucket_name(bucket) - .s3_key_prefix(prefix) - .s3_kms_key_arn(kms_arn) - .sns_topic_arn(sns_arn) - .config_snapshot_delivery_properties(snapshot_props) - .build(); - - client - .put_delivery_channel() - .delivery_channel(delivery_channel) - .send() - .await?; - - println!("Configured delivery channel."); - - Ok(()) -} - -/// Enables AWS Config for a resource type, in the Region. -/// -/// # Arguments -/// -/// * `-b BUCKET` - The name of the Amazon bucket to which AWS Config delivers configuration snapshots and configuration history files. -/// * `-i IAM-ARN` - The ARN of the IAM role that used to describe the AWS resources associated with the account. -/// * `-k KMS-ARN` - The ARN of the KMS key that used to encrypt the data in the bucket. -/// * `-p PREFIX` - The prefix for the bucket. -/// * `-s SNS-ARN` - The ARN of the Amazon SNS topic to which AWS Config sends notifications about configuration changes. -/// * `[-t TYPE]` - The type of resource for AWS Config to support. -/// If not supplied, defaults to `AWS::DynamoDB::Table` (DynamoDB tables). -/// * `[-n NAME]` - The name of the configuration. -/// If not supplied, defaults to `default`. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-v]` - Whether to display information. -/// Need: s3 key prefix AND kms key -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let Opt { - region, - bucket, - iam_arn, - kms_arn, - name, - prefix, - sns_arn, - type_, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - - println!(); - - if verbose { - println!("Config client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("Resource type: {}", type_); - println!("Config (delivery channel) name: {}", name); - println!("Bucket: {}", bucket); - println!("Prefix: {}", prefix); - println!("SNS ARN: {}", sns_arn); - println!("IAM ARN: {}", iam_arn); - println!("KMS ARN: {}", kms_arn); - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - enable_config( - &client, &name, &kms_arn, &bucket, &sns_arn, &iam_arn, &prefix, - ) - .await -} diff --git a/aws/sdk/examples/config/src/bin/list-configuration-recorders.rs b/aws/sdk/examples/config/src/bin/list-configuration-recorders.rs deleted file mode 100644 index 1e4b39f14a..0000000000 --- a/aws/sdk/examples/config/src/bin/list-configuration-recorders.rs +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_config::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Lists your recorders. -async fn show_recorders(client: &aws_sdk_config::Client) -> Result<(), aws_sdk_config::Error> { - let resp = client.describe_configuration_recorders().send().await?; - - let recorders = resp.configuration_recorders.unwrap_or_default(); - - if recorders.is_empty() { - println!("You have no configuration recorders") - } else { - for recorder in recorders { - println!("Recorder: {}", recorder.name.as_deref().unwrap_or_default()); - } - } - - println!(); - - Ok(()) -} - -/// Lists the AWS Config configuration recorders in the Region. -/// -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-v]` - Whether to display information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("Config client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - show_recorders(&client).await -} diff --git a/aws/sdk/examples/config/src/bin/list-delivery-channels.rs b/aws/sdk/examples/config/src/bin/list-delivery-channels.rs deleted file mode 100644 index a7872bbc64..0000000000 --- a/aws/sdk/examples/config/src/bin/list-delivery-channels.rs +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_config::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Lists your deliver channels. -async fn show_channels(client: &aws_sdk_config::Client) -> Result<(), aws_sdk_config::Error> { - let resp = client.describe_delivery_channels().send().await?; - - let channels = resp.delivery_channels.unwrap_or_default(); - - let num_channels = channels.len(); - - if num_channels == 0 { - println!("You have no delivery channels") - } else { - for channel in channels { - println!(" Channel: {}", channel.name.as_deref().unwrap_or_default()); - } - } - - println!(); - - Ok(()) -} - -/// Lists the AWS Config delivery channels in the Region. -/// -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-v]` - Whether to display information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("Config client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - show_channels(&client).await -} diff --git a/aws/sdk/examples/config/src/bin/list-resources.rs b/aws/sdk/examples/config/src/bin/list-resources.rs deleted file mode 100644 index 68ef02c196..0000000000 --- a/aws/sdk/examples/config/src/bin/list-resources.rs +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_config::model::ResourceType; -use aws_sdk_config::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Lists your resources. -async fn show_resources( - verbose: bool, - client: &aws_sdk_config::Client, -) -> Result<(), aws_sdk_config::Error> { - for value in ResourceType::values() { - let parsed = ResourceType::from(*value); - - let resp = client - .list_discovered_resources() - .resource_type(parsed) - .send() - .await?; - - let resources = resp.resource_identifiers.unwrap_or_default(); - - if !resources.is_empty() || verbose { - println!(); - println!("Resources of type {}:", value); - } - - for resource in resources { - println!( - " Resource ID: {}", - resource.resource_id.as_deref().unwrap_or_default() - ); - } - } - - println!(); - - Ok(()) -} - -/// Lists your AWS Config resources, by resource type, in the Region. -/// -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-v]` - Whether to display information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("Config client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if !verbose { - println!("You won't see any output if you don't have any resources defined in the region."); - } - - show_resources(verbose, &client).await -} diff --git a/aws/sdk/examples/config/src/bin/show-resource-history.rs b/aws/sdk/examples/config/src/bin/show-resource-history.rs deleted file mode 100644 index ef5635818d..0000000000 --- a/aws/sdk/examples/config/src/bin/show-resource-history.rs +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_config::model::ResourceType; -use aws_sdk_config::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The ID of the resource. - #[structopt(short, long)] - id: String, - - /// The resource type. - #[structopt(long)] - resource_type: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Shows the history for a resource. -async fn show_history( - client: &aws_sdk_config::Client, - id: &str, - res: ResourceType, -) -> Result<(), aws_sdk_config::Error> { - let rsp = client - .get_resource_config_history() - .resource_id(id) - .resource_type(res) - .send() - .await?; - println!("configuration history for {}:", id); - for item in rsp.configuration_items.unwrap_or_default() { - println!("item: {:?}", item); - } - - Ok(()) -} - -/// Displays the configuration history for a resource in the Region. -/// -/// NOTE: AWS Config must be enabled to discover resources. -/// # Arguments -/// -/// * `-i ID` - The ID of the resource. -/// * `--resource-type RESOURCE-TYPE` - The resource type, such as `AWS::EC2::SecurityGroup`. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-v]` - Whether to display information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let Opt { - region, - id, - resource_type, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("Config client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("Resource ID: {}", &id); - println!("Resource type: {}", &resource_type); - println!(); - } - - // Parse resource type from user input. - let parsed = ResourceType::from(resource_type.as_str()); - - // Make sure it's a known type. - if matches!(parsed, ResourceType::Unknown(_)) { - panic!( - "unknown resource type: `{}`. Valid resource types: {:#?}", - &resource_type, - ResourceType::values() - ) - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - show_history(&client, &id, parsed).await -} diff --git a/aws/sdk/examples/dynamodb/Cargo.toml b/aws/sdk/examples/dynamodb/Cargo.toml deleted file mode 100644 index 2b54508995..0000000000 --- a/aws/sdk/examples/dynamodb/Cargo.toml +++ /dev/null @@ -1,22 +0,0 @@ -[package] -name = "dynamodb-code-examples" -version = "0.1.0" -authors = ["Russell Cohen ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-http = { path = "../../build/aws-sdk/sdk/aws-http" } -aws-sdk-dynamodb = { path = "../../build/aws-sdk/sdk/dynamodb" } -aws-smithy-http = { path = "../../build/aws-sdk/sdk/aws-smithy-http" } -aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client" } -aws-smithy-types = { path = "../../build/aws-sdk/sdk/aws-smithy-types" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -rand = "0.8.3" -serde_json = "1" -structopt = { version = "0.3", default-features = false } -tokio = { version = "1", features = ["full"] } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } -tokio-stream = "0.1.8" diff --git a/aws/sdk/examples/dynamodb/src/bin/README.md b/aws/sdk/examples/dynamodb/src/bin/README.md deleted file mode 100644 index 3a4e85eebf..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# DynamoDB Hello World Example -This repo has a simple hello-world example for DynamoDB that will create a table if it doesn't exist & list tables present in the database. - -By default, the code is written to target DynamoDB local—A docker compose file is provided for convenience. Usage: - -``` -docker-compose up -d -cargo run -``` - -The example can also be updated to run against production DynamoDB if credentials are provided. diff --git a/aws/sdk/examples/dynamodb/src/bin/add-item.rs b/aws/sdk/examples/dynamodb/src/bin/add-item.rs deleted file mode 100644 index 8076cab18f..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/add-item.rs +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_dynamodb::model::AttributeValue; -use aws_sdk_dynamodb::{Client, Error, Region, PKG_VERSION}; - -use std::process; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The permission type of the user, standard_user or admin. - #[structopt(short, long)] - p_type: String, - - /// The user's age. - #[structopt(short, long)] - age: String, - - /// The user's username. - #[structopt(short, long)] - username: String, - - /// The user's first name. - #[structopt(short, long)] - first: String, - - /// The user's last name. - #[structopt(short, long)] - last: String, - - /// The table name. - #[structopt(short, long)] - table: String, - - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Adds an item to an Amazon DynamoDB table. -/// The table schema must use one of username, p_type, age, first, or last as the primary key. -/// # Arguments -/// -/// * `-t TABLE` - The name of the table. -/// * `-u USERNAME` - The username of the new table item. -/// * `-p PERMISSION-TYPE` - The type of user, either "standard_user" or "admin". -/// * `-a AGE` - The age of the user. -/// * `-f FIRST` - The first name of the user. -/// * `-l LAST` - The last name of the user. -/// * `[-r REGION]` - The region in which the table is created. -/// If not supplied, uses the value of the **AWS_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 { - table, - username, - p_type, - age, - first, - last, - region, - verbose, - } = Opt::from_args(); - - if p_type != "standard_user" && p_type != "admin" { - println!("\n{} is not a valid permission type", p_type); - println!("You must specify a permission type value of 'admin' or 'standard_user':"); - println!("-p PERMISSION-TYPE\n"); - process::exit(1); - } - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("DynamoDB client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Table: {}", table); - println!("User: {}", username); - println!("Type: {}", p_type); - println!("Age: {}", age); - println!("First: {}", first); - println!("Last: {}\n", last); - - println!(); - } - - let client = Client::new(&shared_config); - - let user_av = AttributeValue::S(String::from(&username)); - let type_av = AttributeValue::S(String::from(&p_type)); - let age_av = AttributeValue::S(String::from(&age)); - let first_av = AttributeValue::S(String::from(&first)); - let last_av = AttributeValue::S(String::from(&last)); - - let request = client - .put_item() - .table_name(table) - .item("username", user_av) - .item("account_type", type_av) - .item("age", age_av) - .item("first_name", first_av) - .item("last_name", last_av); - - println!("Executing request [{:?}] to add item...", request); - - request.send().await?; - - println!( - "Added user {}, {} {}, age {} as {} user", - username, first, last, age, p_type - ); - - Ok(()) -} diff --git a/aws/sdk/examples/dynamodb/src/bin/create-table.rs b/aws/sdk/examples/dynamodb/src/bin/create-table.rs deleted file mode 100644 index a2269abdb1..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/create-table.rs +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_dynamodb::model::{ - AttributeDefinition, KeySchemaElement, KeyType, ProvisionedThroughput, ScalarAttributeType, -}; -use aws_sdk_dynamodb::{Client, Error, Region, PKG_VERSION}; - -use std::process; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The region - #[structopt(short, long)] - region: Option, - - /// The table name - #[structopt(short, long)] - table: String, - - /// The primary key - #[structopt(short, long)] - key: String, - - /// Activate verbose mode - #[structopt(short, long)] - verbose: bool, -} - -/// Creates a DynamoDB table. -/// # Arguments -/// -/// * `-k KEY` - The primary key for the table. -/// * `-t TABLE` - The name of the table. -/// * `[-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> { - tracing_subscriber::fmt::init(); - let Opt { - table, - key, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("DynamoDB client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Table: {}", table); - println!("Key: {}", key); - - println!(); - } - - let ad = AttributeDefinition::builder() - .attribute_name(String::from(&key)) - .attribute_type(ScalarAttributeType::S) - .build(); - - let ks = KeySchemaElement::builder() - .attribute_name(String::from(&key)) - .key_type(KeyType::Hash) - .build(); - - let pt = ProvisionedThroughput::builder() - .read_capacity_units(10) - .write_capacity_units(5) - .build(); - - match client - .create_table() - .table_name(String::from(&table)) - .key_schema(ks) - .attribute_definitions(ad) - .provisioned_throughput(pt) - .send() - .await - { - Ok(_) => println!("Added table {} with key {}", table, key), - Err(e) => { - println!("Got an error creating table:"); - println!("{}", e); - process::exit(1); - } - }; - - Ok(()) -} diff --git a/aws/sdk/examples/dynamodb/src/bin/crud.rs b/aws/sdk/examples/dynamodb/src/bin/crud.rs deleted file mode 100644 index 843e51aaa5..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/crud.rs +++ /dev/null @@ -1,383 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_http::retry::AwsErrorRetryPolicy; -use aws_sdk_dynamodb::error::DescribeTableError; -use aws_sdk_dynamodb::input::DescribeTableInput; -use aws_sdk_dynamodb::middleware::DefaultMiddleware; -use aws_sdk_dynamodb::model::{ - AttributeDefinition, AttributeValue, KeySchemaElement, KeyType, ProvisionedThroughput, - ScalarAttributeType, Select, TableStatus, -}; -use aws_sdk_dynamodb::operation::DescribeTable; -use aws_sdk_dynamodb::output::DescribeTableOutput; -use aws_sdk_dynamodb::{Client, Config, Error, Region, PKG_VERSION}; -use aws_smithy_client::erase::DynConnector; -use aws_smithy_http::result::{SdkError, SdkSuccess}; - -use aws_smithy_http::operation::Operation; -use aws_smithy_http::retry::ClassifyResponse; -use aws_smithy_types::retry::RetryKind; -use rand::distributions::Alphanumeric; -use rand::{thread_rng, Rng}; -use std::io::{stdin, Read}; -use std::time::Duration; -use std::{iter, process}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// Whether to run in interactive mode (you have to press return between operations) - #[structopt(short, long)] - interactive: bool, - - /// The AWS Region - #[structopt(short, long)] - region: Option, - - /// Activate verbose mode - #[structopt(short, long)] - verbose: bool, -} - -/// Create a random, n-length string -fn random_string(n: usize) -> String { - let mut rng = thread_rng(); - iter::repeat(()) - .map(|()| rng.sample(Alphanumeric)) - .map(char::from) - .take(n) - .collect() -} - -/// Create a new table. -async fn make_table( - client: &Client, - table: &str, - key: &str, -) -> Result<(), SdkError> { - let ad = AttributeDefinition::builder() - .attribute_name(key) - .attribute_type(ScalarAttributeType::S) - .build(); - - let ks = KeySchemaElement::builder() - .attribute_name(key) - .key_type(KeyType::Hash) - .build(); - - let pt = ProvisionedThroughput::builder() - .read_capacity_units(10) - .write_capacity_units(5) - .build(); - - match client - .create_table() - .table_name(table) - .key_schema(ks) - .attribute_definitions(ad) - .provisioned_throughput(pt) - .send() - .await - { - Ok(_) => Ok(()), - Err(e) => Err(e), - } -} - -/// For add_item and query_item -#[derive(Clone)] -struct Item { - table: String, - key: String, - value: String, - first_name: String, - last_name: String, - age: String, - utype: String, -} - -/// Add an item to the table. -async fn add_item( - client: &Client, - item: Item, -) -> Result<(), SdkError> { - let user_av = AttributeValue::S(item.value); - let type_av = AttributeValue::S(item.utype); - let age_av = AttributeValue::S(item.age); - let first_av = AttributeValue::S(item.first_name); - let last_av = AttributeValue::S(item.last_name); - - match client - .put_item() - .table_name(item.table) - .item(item.key, user_av) - .item("account_type", type_av) - .item("age", age_av) - .item("first_name", first_av) - .item("last_name", last_av) - .send() - .await - { - Ok(_) => Ok(()), - Err(e) => Err(e), - } -} - -/// Query the table for an item matching the input values. -/// Returns true if the item is found; otherwise false. -async fn query_item(client: &Client, item: Item) -> bool { - let value = &item.value; - let key = &item.key; - let user_av = AttributeValue::S(value.to_string()); - - match client - .query() - .table_name(item.table) - .key_condition_expression("#key = :value".to_string()) - .expression_attribute_names("#key".to_string(), key.to_string()) - .expression_attribute_values(":value".to_string(), user_av) - .select(Select::AllAttributes) - .send() - .await - { - Ok(resp) => { - if resp.count > 0 { - println!("Found a matching entry in the table:"); - println!("{:?}", resp.items.unwrap_or_default().pop()); - true - } else { - println!("Did not find a match."); - false - } - } - Err(e) => { - println!("Got an error querying table:"); - println!("{}", e); - process::exit(1); - } - } -} - -/// Hand-written waiter to retry every second until the table is out of `Creating` state -#[derive(Clone)] -struct WaitForReadyTable { - inner: R, -} - -impl ClassifyResponse, SdkError> - for WaitForReadyTable -where - R: ClassifyResponse, SdkError>, -{ - fn classify( - &self, - response: Result<&SdkSuccess, &SdkError>, - ) -> RetryKind { - match self.inner.classify(response) { - RetryKind::NotRetryable => (), - other => return other, - }; - match response { - Ok(SdkSuccess { parsed, .. }) => { - if parsed - .table - .as_ref() - .unwrap() - .table_status - .as_ref() - .unwrap() - == &TableStatus::Creating - { - RetryKind::Explicit(Duration::from_secs(1)) - } else { - RetryKind::NotRetryable - } - } - _ => RetryKind::NotRetryable, - } - } -} - -/// Wait for the user to press Enter. -fn pause() { - println!("Press Enter to continue."); - stdin().read_exact(&mut [0]).unwrap(); -} - -/// Performs CRUD (create, read, update, delete) operations on a DynamoDB table and table item. -/// It creates a table, adds an item to the table, updates the item, deletes the item, and deletes the table. -/// The table name, primary key, and primary key value are all created as random strings. -/// -/// # Arguments -/// -/// * `[-i]` - Whether to pause between operations. -/// * `[-r REGION]` - The region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { - interactive, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - // Create 10-character random table name - let table = random_string(10); - - // Create a 6-character random key name - let key = random_string(6); - - // Create a 12-character random key value - let value = random_string(12); - - // Specify first name, last name, age, and type - let first_name = "DummyFirstName"; - let last_name = "DummyLastName"; - let age = "33"; - let utype = "standard_user"; - - println!(); - - if verbose { - println!("DynamoDB client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Table: {}", table); - println!("Key: {}", key); - println!("Value: {}", value); - println!("First name: {}", first_name); - println!("Last name: {}", last_name); - println!("Age: {}", age); - println!("User type: {}", utype); - - println!(); - } - - let client = Client::new(&shared_config); - - /* Create table */ - println!("Creating the table."); - match make_table(&client, &table, &key).await { - Err(e) => { - println!("Got an error creating the table:"); - println!("{}", e); - process::exit(1); - } - Ok(_) => { - println!("Created the table."); - } - } - - println!("Waiting for table to be ready."); - - let raw_client = aws_smithy_client::Client::::dyn_https(); - - raw_client - .call(wait_for_ready_table(&table, client.conf()).await) - .await - .expect("table should become ready."); - - println!("Table is now ready to use."); - - if interactive { - pause(); - } - - println!("Adding item to table."); - - let mut item = Item { - table: table.clone(), - key: key.clone(), - value: value.clone(), - first_name: first_name.to_string(), - last_name: last_name.to_string(), - age: age.to_string(), - utype: utype.to_string(), - }; - - add_item(&client, item.clone()).await?; - println!("Added item to table."); - - if interactive { - pause(); - } - - item.age = "44".to_string(); - - /* Update the item */ - println!("Modifying table item to change age to 44."); - - add_item(&client, item.clone()).await?; - - println!("Modified table item."); - - if interactive { - pause(); - } - - /* Get item and compare it with the one we added */ - println!("Comparing table item to original value."); - - query_item(&client, item).await; - - if interactive { - pause(); - } - - /* Delete item */ - println!("Deleting item."); - let user_av = AttributeValue::S(value); - client - .delete_item() - .table_name(&table) - .key(key, user_av) - .send() - .await?; - - println!("Deleted item."); - - if interactive { - pause(); - } - - /* Delete table */ - println!("Deleting table."); - client.delete_table().table_name(&table).send().await?; - println!("Deleted table."); - println!(); - - Ok(()) -} - -/// Construct a `DescribeTable` request with a policy to retry every second until the table -/// is ready -async fn wait_for_ready_table( - table_name: &str, - conf: &Config, -) -> Operation> { - let operation = DescribeTableInput::builder() - .table_name(table_name) - .build() - .expect("valid input") - .make_operation(conf) - .await - .expect("valid operation"); - let waiting_policy = WaitForReadyTable { - inner: operation.retry_policy().clone(), - }; - operation.with_retry_policy(waiting_policy) -} diff --git a/aws/sdk/examples/dynamodb/src/bin/data.json b/aws/sdk/examples/dynamodb/src/bin/data.json deleted file mode 100644 index 315aa202aa..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/data.json +++ /dev/null @@ -1,53 +0,0 @@ -[ - { - "year": 2013, - "title": "Turn It Down, Or Else!", - "info": { - "directors": [ - "Alice Smith", - "Bob Jones" - ], - "release_date": "2013-01-18T00:00:00Z", - "rating": 6.2, - "genres": [ - "Comedy", - "Drama" - ], - "image_url": "http://ia.media-imdb.com/images/N/O9ERWAU7FS797AJ7LU8HN09AMUP908RLlo5JF90EWR7LJKQ7@@._V1_SX400_.jpg", - "plot": "A rock band plays their music at high volumes, annoying the neighbors.", - "rank": 11, - "running_time_secs": 5215, - "actors": [ - "David Matthewman", - "Ann Thomas", - "Jonathan G. Neff" - ] - } - }, - { - "year": 2013, - "title": "Rush", - "info": { - "directors": [ - "Ron Howard" - ], - "release_date": "2013-09-02T00:00:00Z", - "rating": 8.3, - "genres": [ - "Action", - "Biography", - "Drama", - "Sport" - ], - "image_url": "http://ia.media-imdb.com/images/M/MV5BMTQyMDE0MTY0OV5BMl5BanBnXkFtZTcwMjI2OTI0OQ@@._V1_SX400_.jpg", - "plot": "A re-creation of the merciless 1970s rivalry between Formula One rivals James Hunt and Niki Lauda.", - "rank": 2, - "running_time_secs": 7380, - "actors": [ - "Daniel Bruhl", - "Chris Hemsworth", - "Olivia Wilde" - ] - } - } -] diff --git a/aws/sdk/examples/dynamodb/src/bin/delete-item.rs b/aws/sdk/examples/dynamodb/src/bin/delete-item.rs deleted file mode 100644 index bc345892e2..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/delete-item.rs +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_dynamodb::model::AttributeValue; -use aws_sdk_dynamodb::{Client, Error, Region, PKG_VERSION}; - -use std::process; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the table. - #[structopt(short, long)] - table: String, - - /// The key for the item in the table. - #[structopt(short, long)] - key: String, - - /// The value of the item to delete from the table. - #[structopt(short, long)] - value: String, - - /// Whether to display additional information. - #[structopt(short, long)] - info: bool, -} - -/// Deletes an item from an Amazon DynamoDB table. -/// The table schema must use the key as the primary key. -/// # Arguments -/// -/// * `-t TABLE` - The name of the table. -/// * `-k KEY` - The table's primary key. -/// * `-v VALUE` - The value of the item's primary key. -/// * `[-r REGION]` - The region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-i]` - Whether to display additional information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - - let Opt { - info, - key, - region, - table, - value, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if info { - println!("DynamoDB client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Table: {}", &table); - println!("Key: {}", &key); - println!(); - } - - let client = Client::new(&shared_config); - - match client - .delete_item() - .table_name(table) - .key(key, AttributeValue::S(value)) - .send() - .await - { - Ok(_) => println!("Deleted item from table"), - Err(e) => { - println!("Got an error deleting item from table:"); - println!("{}", e); - process::exit(1); - } - }; - - Ok(()) -} diff --git a/aws/sdk/examples/dynamodb/src/bin/delete-table.rs b/aws/sdk/examples/dynamodb/src/bin/delete-table.rs deleted file mode 100644 index bc3b1579bd..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/delete-table.rs +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_dynamodb::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the table. - #[structopt(short, long)] - table: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Deletes a DynamoDB table. -/// # Arguments -/// -/// * `-t TABLE` - The name of the table. -/// * `[-r REGION]` - The region in which the client is created. -/// If not supplied, uses the value of the **AWS_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 { - table, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("DynamoDB client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Table: {}", &table); - println!(); - } - - let client = Client::new(&shared_config); - - client.delete_table().table_name(table).send().await?; - - println!("Deleted table"); - - Ok(()) -} diff --git a/aws/sdk/examples/dynamodb/src/bin/docker-compose.yml b/aws/sdk/examples/dynamodb/src/bin/docker-compose.yml deleted file mode 100644 index 98d36b2f1d..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/docker-compose.yml +++ /dev/null @@ -1,7 +0,0 @@ -version: '3.7' -services: - dynamodb-local: - image: amazon/dynamodb-local:latest - container_name: dynamodb-local - ports: - - 8000:8000 diff --git a/aws/sdk/examples/dynamodb/src/bin/dynamodb-helloworld.rs b/aws/sdk/examples/dynamodb/src/bin/dynamodb-helloworld.rs deleted file mode 100644 index e5830efa50..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/dynamodb-helloworld.rs +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_dynamodb::model::{ - AttributeDefinition, KeySchemaElement, KeyType, ProvisionedThroughput, ScalarAttributeType, -}; -use aws_sdk_dynamodb::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your DynamoDB tables and creates the table **test-table**. -/// # Arguments -/// -/// * `[-r REGION]` - The region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!("DynamoDB client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!(); - } - - let client = Client::new(&shared_config); - - let tables = client.list_tables().send().await?; - - println!("Current DynamoDB tables: {:?}", tables); - - let new_table = client - .create_table() - .table_name("test-table") - .key_schema( - KeySchemaElement::builder() - .attribute_name("k") - .key_type(KeyType::Hash) - .build(), - ) - .attribute_definitions( - AttributeDefinition::builder() - .attribute_name("k") - .attribute_type(ScalarAttributeType::S) - .build(), - ) - .provisioned_throughput( - ProvisionedThroughput::builder() - .write_capacity_units(10) - .read_capacity_units(10) - .build(), - ) - .send() - .await?; - println!( - "new table: {:#?}", - &new_table.table_description.unwrap().table_arn.unwrap() - ); - - Ok(()) -} diff --git a/aws/sdk/examples/dynamodb/src/bin/list-items.rs b/aws/sdk/examples/dynamodb/src/bin/list-items.rs deleted file mode 100644 index 56c587faa5..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/list-items.rs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_dynamodb::{Client, Error, Region, PKG_VERSION}; -use tokio_stream::StreamExt; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the table. - #[structopt(short, long)] - table: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the items in a DynamoDB table. -/// # Arguments -/// -/// * `-t TABLE` - The name of the table. -/// * `[-r REGION]` - The region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - table, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("DynamoDB client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Table: {}", &table); - - println!(); - } - - let items: Result, _> = client - .scan() - .table_name(table) - .into_paginator() - .items() - .send() - .collect() - .await; - - println!("Items in table:"); - for item in items? { - println!(" {:?}", item); - } - - Ok(()) -} diff --git a/aws/sdk/examples/dynamodb/src/bin/list-tables.rs b/aws/sdk/examples/dynamodb/src/bin/list-tables.rs deleted file mode 100644 index a9a3fc677b..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/list-tables.rs +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_dynamodb::{Client, Error, Region, PKG_VERSION}; -use tokio_stream::StreamExt; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your DynamoDB tables. -/// # Arguments -/// -/// * `[-r REGION]` - The region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("DynamoDB client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!(); - } - - let client = Client::new(&shared_config); - - let paginator = client.list_tables().into_paginator().items().send(); - let table_names = paginator.collect::, _>>().await?; - - println!("Tables:"); - - for name in &table_names { - println!(" {}", name); - } - - println!("Found {} tables", table_names.len()); - Ok(()) -} diff --git a/aws/sdk/examples/dynamodb/src/bin/movies.rs b/aws/sdk/examples/dynamodb/src/bin/movies.rs deleted file mode 100644 index 2b83a94373..0000000000 --- a/aws/sdk/examples/dynamodb/src/bin/movies.rs +++ /dev/null @@ -1,275 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use std::collections::HashMap; -use std::time::Duration; - -use aws_config::meta::region::RegionProviderChain; -use aws_http::retry::AwsErrorRetryPolicy; -use aws_sdk_dynamodb::client::fluent_builders::Query; -use aws_sdk_dynamodb::error::DescribeTableError; -use aws_sdk_dynamodb::input::DescribeTableInput; -use aws_sdk_dynamodb::middleware::DefaultMiddleware; -use aws_sdk_dynamodb::model::{ - AttributeDefinition, AttributeValue, KeySchemaElement, KeyType, ProvisionedThroughput, - ScalarAttributeType, TableStatus, -}; -use aws_sdk_dynamodb::operation::DescribeTable; -use aws_sdk_dynamodb::output::DescribeTableOutput; -use aws_sdk_dynamodb::{Client, Config, Error, Region, PKG_VERSION}; -use aws_smithy_client::erase::DynConnector; -use aws_smithy_http::operation::Operation; -use aws_smithy_http::result::{SdkError, SdkSuccess}; -use aws_smithy_http::retry::ClassifyResponse; -use aws_smithy_types::retry::RetryKind; -use serde_json::Value; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the table. - #[structopt(short, long)] - table: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// A partial reimplementation of -/// -/// in Rust -/// -/// - Create table -/// - Wait for table to be ready -/// - Add a couple of rows -/// - Query for those rows -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - table, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("DynamoDB client version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("Table: {}", &table); - println!(); - } - - let client = Client::new(&shared_config); - - let raw_client = aws_smithy_client::Client::::dyn_https(); - - let table_exists = client - .list_tables() - .send() - .await - .expect("should succeed") - .table_names - .as_ref() - .unwrap() - .contains(&table.to_string()); - - if !table_exists { - create_table(&client, &table.to_string()) - .send() - .await - .expect("failed to create table"); - } - - raw_client - .call(wait_for_ready_table(&table.to_string(), client.conf()).await) - .await - .expect("table should become ready"); - - // data.json contains 2 movies from 2013 - let data = match serde_json::from_str(include_str!("data.json")).expect("should be valid JSON") - { - Value::Array(inner) => inner, - data => panic!("data must be an array, got: {:?}", data), - }; - for value in data { - client - .put_item() - .table_name(&table) - .set_item(Some(parse_item(value))) - .send() - .await - .expect("failed to insert item"); - } - let films_2222 = movies_in_year(&client, &table.to_string(), 2222) - .send() - .await - .expect("query should succeed"); - // this isn't back to the future, there are no movies from 2022 - assert_eq!(films_2222.count, 0); - - let films_2013 = movies_in_year(&client, &table.to_string(), 2013) - .send() - .await - .expect("query should succeed"); - assert_eq!(films_2013.count, 2); - let titles: Vec = films_2013 - .items - .unwrap() - .into_iter() - .map(|mut row| row.remove("title").expect("row should have title")) - .collect(); - assert_eq!( - titles, - vec![ - AttributeValue::S("Rush".to_string()), - AttributeValue::S("Turn It Down, Or Else!".to_string()) - ] - ); - - Ok(()) -} - -fn create_table( - client: &Client, - table_name: &str, -) -> aws_sdk_dynamodb::client::fluent_builders::CreateTable { - client - .create_table() - .table_name(table_name) - .key_schema( - KeySchemaElement::builder() - .attribute_name("year") - .key_type(KeyType::Hash) - .build(), - ) - .key_schema( - KeySchemaElement::builder() - .attribute_name("title") - .key_type(KeyType::Range) - .build(), - ) - .attribute_definitions( - AttributeDefinition::builder() - .attribute_name("year") - .attribute_type(ScalarAttributeType::N) - .build(), - ) - .attribute_definitions( - AttributeDefinition::builder() - .attribute_name("title") - .attribute_type(ScalarAttributeType::S) - .build(), - ) - .provisioned_throughput( - ProvisionedThroughput::builder() - .read_capacity_units(10) - .write_capacity_units(10) - .build(), - ) -} - -fn parse_item(value: Value) -> HashMap { - match value_to_item(value) { - AttributeValue::M(map) => map, - other => panic!("can only insert top level values, got {:?}", other), - } -} - -fn value_to_item(value: Value) -> AttributeValue { - match value { - Value::Null => AttributeValue::Null(true), - Value::Bool(b) => AttributeValue::Bool(b), - Value::Number(n) => AttributeValue::N(n.to_string()), - Value::String(s) => AttributeValue::S(s), - Value::Array(a) => AttributeValue::L(a.into_iter().map(value_to_item).collect()), - Value::Object(o) => { - AttributeValue::M(o.into_iter().map(|(k, v)| (k, value_to_item(v))).collect()) - } - } -} - -fn movies_in_year(client: &Client, table_name: &str, year: u16) -> Query { - client - .query() - .table_name(table_name) - .key_condition_expression("#yr = :yyyy") - .expression_attribute_names("#yr", "year") - .expression_attribute_values(":yyyy", AttributeValue::N(year.to_string())) -} - -/// Hand-written waiter to retry every second until the table is out of `Creating` state -#[derive(Clone)] -struct WaitForReadyTable { - inner: R, -} - -impl ClassifyResponse, SdkError> - for WaitForReadyTable -where - R: ClassifyResponse, SdkError>, -{ - fn classify( - &self, - response: Result<&SdkSuccess, &SdkError>, - ) -> RetryKind { - match self.inner.classify(response) { - RetryKind::NotRetryable => (), - other => return other, - }; - match response { - Ok(SdkSuccess { parsed, .. }) => { - if parsed - .table - .as_ref() - .unwrap() - .table_status - .as_ref() - .unwrap() - == &TableStatus::Creating - { - RetryKind::Explicit(Duration::from_secs(1)) - } else { - RetryKind::NotRetryable - } - } - _ => RetryKind::NotRetryable, - } - } -} - -/// Construct a `DescribeTable` request with a policy to retry every second until the table -/// is ready -async fn wait_for_ready_table( - table_name: &str, - conf: &Config, -) -> Operation> { - let operation = DescribeTableInput::builder() - .table_name(table_name) - .build() - .expect("valid input") - .make_operation(conf) - .await - .expect("valid operation"); - let waiting_policy = WaitForReadyTable { - inner: operation.retry_policy().clone(), - }; - operation.with_retry_policy(waiting_policy) -} diff --git a/aws/sdk/examples/ebs/Cargo.toml b/aws/sdk/examples/ebs/Cargo.toml deleted file mode 100644 index e5b17f0e04..0000000000 --- a/aws/sdk/examples/ebs/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "ebs-code-examples" -version = "0.1.0" -authors = ["Russell Cohen "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-ebs = { package = "aws-sdk-ebs", path = "../../build/aws-sdk/sdk/ebs" } -aws-sdk-ec2 = { package = "aws-sdk-ec2", path = "../../build/aws-sdk/sdk/ec2" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"]} -base64 = "0.13.0" -sha2 = "0.9.5" -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/ebs/src/bin/create-snapshot.rs b/aws/sdk/examples/ebs/src/bin/create-snapshot.rs deleted file mode 100644 index 64f648f4b8..0000000000 --- a/aws/sdk/examples/ebs/src/bin/create-snapshot.rs +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ebs::model::ChecksumAlgorithm; -use aws_sdk_ebs::{ByteStream, Client, Error, Region, PKG_VERSION}; - -use sha2::Digest; -use structopt::StructOpt; - -/// Amazon EBS only supports one fixed size of block -const EBS_BLOCK_SIZE: usize = 524288; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The snapshot's description. - #[structopt(short, long)] - description: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Creates an Amazon Elastic Block Store snapshot with the specified description. -/// # Arguments -/// -/// * `-d DESCRIPTION` - The description of the snapshot. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - description, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("EBS version: {}", PKG_VERSION); - println!("Description: {}", description); - println!("Region: {}", shared_config.region().unwrap()); - println!(); - } - - let snapshot = client - .start_snapshot() - .description(description) - .encrypted(false) - .volume_size(1) - .send() - .await?; - - let snapshot_id = snapshot.snapshot_id.unwrap(); - let mut blocks = vec![]; - - // Append a block of all 1s. - let mut block: Vec = Vec::new(); - block.resize(EBS_BLOCK_SIZE, 1); - blocks.push(block); - - // Append a block of all 0s. - let mut block: Vec = Vec::new(); - block.resize(EBS_BLOCK_SIZE, 0); - blocks.push(block); - - for (idx, block) in blocks.into_iter().enumerate() { - let mut hasher = sha2::Sha256::new(); - hasher.update(&block); - let checksum = hasher.finalize(); - let checksum = base64::encode(&checksum[..]); - - client - .put_snapshot_block() - .snapshot_id(&snapshot_id) - .block_index(idx as i32) - .block_data(ByteStream::from(block)) - .checksum(checksum) - .checksum_algorithm(ChecksumAlgorithm::ChecksumAlgorithmSha256) - .data_length(EBS_BLOCK_SIZE as i32) - .send() - .await?; - } - client - .complete_snapshot() - .changed_blocks_count(2) - .snapshot_id(&snapshot_id) - .send() - .await?; - - println!("Snapshot ID {}", snapshot_id); - println!("The state is 'completed' when all of the modified blocks have been transferred to Amazon S3."); - println!("Use the get-snapshot-state code example to get the state of the snapshot."); - - Ok(()) -} diff --git a/aws/sdk/examples/ebs/src/bin/delete-snapshot.rs b/aws/sdk/examples/ebs/src/bin/delete-snapshot.rs deleted file mode 100644 index 68aafcd947..0000000000 --- a/aws/sdk/examples/ebs/src/bin/delete-snapshot.rs +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The ID of the snapshot. - #[structopt(short, long)] - snapshot_id: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Deletes an Amazon Elastic Block Store snapshot. -/// It must be `completed` before you can use the snapshot. -/// # Arguments -/// -/// * `-s SNAPSHOT-ID` - The ID of the snapshot. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - snapshot_id, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("EC2 version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!("Snapshot ID: {}", snapshot_id); - println!(); - } - - client - .delete_snapshot() - .snapshot_id(snapshot_id) - .send() - .await?; - - println!("Deleted"); - - Ok(()) -} diff --git a/aws/sdk/examples/ebs/src/bin/get-snapshot-state.rs b/aws/sdk/examples/ebs/src/bin/get-snapshot-state.rs deleted file mode 100644 index 3cde59fe46..0000000000 --- a/aws/sdk/examples/ebs/src/bin/get-snapshot-state.rs +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2::model::Filter; -use aws_sdk_ec2::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The ID of the snapshot. - #[structopt(short, long)] - snapshot_id: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Retrieves the state of an Amazon Elastic Block Store snapshot using Amazon EC2 API. -/// It must be `completed` before you can use the snapshot. -/// # Arguments -/// -/// * `-s SNAPSHOT-ID` - The ID of the snapshot. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - snapshot_id, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("EC2 version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!("Snapshot ID: {}", snapshot_id); - println!(); - } - - let resp = client - .describe_snapshots() - .filters( - Filter::builder() - .name("snapshot-id") - .values(snapshot_id) - .build(), - ) - .send() - .await?; - - println!( - "State: {}", - resp.snapshots - .unwrap() - .pop() - .unwrap() - .state - .unwrap() - .as_ref() - ); - - Ok(()) -} diff --git a/aws/sdk/examples/ebs/src/bin/list-snapshots.rs b/aws/sdk/examples/ebs/src/bin/list-snapshots.rs deleted file mode 100644 index 0434912c1b..0000000000 --- a/aws/sdk/examples/ebs/src/bin/list-snapshots.rs +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Displays some information about the Amazon Elastic Block Store snapshots you own in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("EC2 version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - - println!(); - } - - // "self" represents your account ID. - // You can list the snapshots for any account by replacing - // "self" with that account ID. - let resp = client.describe_snapshots().owner_ids("self").send().await?; - let snapshots = resp.snapshots.unwrap(); - let length = snapshots.len(); - - for snapshot in snapshots { - println!( - "ID: {}", - snapshot.snapshot_id.as_deref().unwrap_or_default() - ); - println!( - "Description: {}", - snapshot.description.as_deref().unwrap_or_default() - ); - println!("State: {}", snapshot.state.unwrap().as_ref()); - println!(); - } - - println!(); - println!("Found {} snapshot(s)", length); - println!(); - - Ok(()) -} diff --git a/aws/sdk/examples/ec2/Cargo.toml b/aws/sdk/examples/ec2/Cargo.toml deleted file mode 100644 index 747e9b7aa2..0000000000 --- a/aws/sdk/examples/ec2/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "ec2-code-examples" -version = "0.1.0" -authors = ["Russell Cohen ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-ec2 = { package = "aws-sdk-ec2", path = "../../build/aws-sdk/sdk/ec2" } -tokio = { version = "1", features = ["full"]} -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/ec2/README.md b/aws/sdk/examples/ec2/README.md deleted file mode 100644 index 8021e1f102..0000000000 --- a/aws/sdk/examples/ec2/README.md +++ /dev/null @@ -1,114 +0,0 @@ -# AWS SDK for Rust code examples for Amazon EC2 - -Amazon Elastic Compute Cloud (Amazon EC2) is a web service that provides resizable computing capacity—literally, servers in Amazon's data centers—that you use to build and host your software systems. - -## Purpose - -These examples demonstrate how to perform several Amazon EC2 operations using the alpha version of the AWS SDK for Rust. - -## Prerequisites - -You must have an AWS account, and have configured your default credentials and AWS Region as described in [https://github.com/awslabs/aws-sdk-rust](https://github.com/awslabs/aws-sdk-rust). - -## Running the code - -### describe-instances - -This example lists the state of one or all of your Amazon EC2 instances - -`cargo run --bin describe-instances -- [-i INSTANCE-ID] [-d DEFAULT-REGION] [-v]` - -- _INSTANCE-ID_ is the ID of an instance to describe. - If this argument is not supplied, the state of all instances is shown. -- _DEFAULT-REGION_ is optional name of a region, such as __us-east-1__. - If this value is not supplied, the region defaults to __us-west-2__. -- __-v__ display additional information. - -### ec2-helloworld - -This example describes the AWS Regions that are enabled for your account. - -`cargo run --bin ec2-helloworld -- [-d DEFAULT-REGION] [-v]` - - If this argument is not supplied, the state of all instances is shown. -- _DEFAULT-REGION_ is optional name of a region, such as __us-east-1__. - If this value is not supplied, the region defaults to __us-west-2__. -- __-v__ display additional information. - -### list-all-instance-events - -This example shows the scheduled events for the Amazon Elastic Compute Cloud (Amazon EC2) instances in the Region. - -`cargo run --bin list-all-instance-events -- [-d DEFAULT-REGION] [-v]` - -- _DEFAULT-REGION_ is optional name of a region, such as __us-east-1__. - If this value is not supplied, the region defaults to __us-west-2__. -- __-v__ display additional information. - -### monitor-instance - -This example enables monitoring on an Amazon EC2 instance. - -`cargo run --bin monitor-instance -- -i INSTANCE-ID [-d DEFAULT-REGION] [-v]` - -- _INSTANCE-ID_ is the ID of an instance to monitor. - If this argument is not supplied, the state of all instances is shown. -- _DEFAULT-REGION_ is optional name of a region, such as __us-east-1__. - If this value is not supplied, the region defaults to __us-west-2__. -- __-v__ display additional information. - -### reboot-instance - -This example reboots an Amazon EC2 instance. - -`cargo run --bin reboot-instance -- -i INSTANCE-ID [-d DEFAULT-REGION] [-v]` - -- _INSTANCE-ID_ is the ID of an instance to reboot. - If this argument is not supplied, the state of all instances is shown. -- _DEFAULT-REGION_ is optional name of a region, such as __us-east-1__. - If this value is not supplied, the region defaults to __us-west-2__. -- __-v__ display additional information. - -### start-instance - -This example starts an Amazon EC2 instance. - -`cargo run --bin start-instance -- -i INSTANCE-ID [-d DEFAULT-REGION] [-v]` - -- _INSTANCE-ID_ is the ID of an instance to start. - If this argument is not supplied, the state of all instances is shown. -- _DEFAULT-REGION_ is optional name of a region, such as __us-east-1__. - If this value is not supplied, the region defaults to __us-west-2__. -- __-v__ display additional information. - -### stop-instance - -This example stops an Amazon EC2 instance. - -`cargo run --bin stop-instance -- -i INSTANCE-ID [-d DEFAULT-REGION] [-v]` - -- _INSTANCE-ID_ is the ID of an instance to stop. - If this argument is not supplied, the state of all instances is shown. -- _DEFAULT-REGION_ is optional name of a region, such as __us-east-1__. - If this value is not supplied, the region defaults to __us-west-2__. -- __-v__ display additional information. - -### Running the unit tests - -To run the unit tests, enter the following command: - -`cargo test` - -## Notes - -- We recommend that you grant this code least privilege, - or at most the minimum permissions required to perform the task. - For more information, see - [Grant Least Privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege) - in the AWS Identity and Access Management User Guide. -- This code has not been tested in all AWS Regions. - Some AWS services are available only in specific - [Regions](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). -- Running this code might result in charges to your AWS account. - -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 diff --git a/aws/sdk/examples/ec2/src/bin/describe-instances.rs b/aws/sdk/examples/ec2/src/bin/describe-instances.rs deleted file mode 100644 index 59660f1861..0000000000 --- a/aws/sdk/examples/ec2/src/bin/describe-instances.rs +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// To get info about one instance. - #[structopt(short, long)] - instance_id: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Lists the state of an instance. -async fn show_state( - client: &aws_sdk_ec2::Client, - ids: Vec, -) -> Result<(), aws_sdk_ec2::Error> { - let resp = client - .describe_instances() - .set_instance_ids(Some(ids)) - .send() - .await?; - - for reservation in resp.reservations.unwrap_or_default() { - for instance in reservation.instances.unwrap_or_default() { - println!("Instance ID: {}", instance.instance_id.unwrap()); - println!("State: {:?}", instance.state.unwrap().name.unwrap()); - println!(); - } - } - - Ok(()) -} - -/// Lists the state of one or all of your Amazon EC2 instances. -/// # Arguments -/// -/// * `[-i INSTANCE-ID]` - The ID of an instance. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { - region, - instance_id, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("EC2 client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - - if instance_id.is_some() { - println!("Instance ID: {:?}", instance_id); - } - - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - let mut ids: Vec = Vec::new(); - let id_opt: std::option::Option>; - - match instance_id { - None => id_opt = None, - Some(i) => { - ids.push(i); - id_opt = Some(ids); - } - } - - show_state(&client, id_opt.unwrap()).await -} diff --git a/aws/sdk/examples/ec2/src/bin/ec2-helloworld.rs b/aws/sdk/examples/ec2/src/bin/ec2-helloworld.rs deleted file mode 100644 index 936626feca..0000000000 --- a/aws/sdk/examples/ec2/src/bin/ec2-helloworld.rs +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Describes the regions. -async fn show_regions(client: &aws_sdk_ec2::Client) -> Result<(), aws_sdk_ec2::Error> { - let rsp = client.describe_regions().send().await?; - - println!("Regions:"); - for region in rsp.regions.unwrap_or_default() { - println!(" {}", region.region_name.unwrap()); - } - - Ok(()) -} - -/// Describes the AWS Regions that are enabled for your account. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("EC2 client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - show_regions(&client).await -} diff --git a/aws/sdk/examples/ec2/src/bin/list-all-instance-events.rs b/aws/sdk/examples/ec2/src/bin/list-all-instance-events.rs deleted file mode 100644 index 2872da87b3..0000000000 --- a/aws/sdk/examples/ec2/src/bin/list-all-instance-events.rs +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional runtime information. - #[structopt(short, long)] - verbose: bool, -} - -// Shows the events for every Region. -async fn show_all_events(client: &aws_sdk_ec2::Client) -> Result<(), aws_sdk_ec2::Error> { - let resp = client.describe_regions().send().await?; - - for region in resp.regions.unwrap_or_default() { - let reg: &'static str = Box::leak(region.region_name.unwrap().into_boxed_str()); - show_events(reg).await; - } - - Ok(()) -} - -/// Shows the scheduled events for the Amazon Elastic Compute Cloud (Amazon EC2) instances in the Region. -async fn show_events(reg: &'static str) { - let region_provider = RegionProviderChain::default_provider().or_else(reg); - let config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&config); - - let resp = client.describe_instance_status().send().await; - - println!("Instances in region {}:", reg); - println!(); - - for status in resp.unwrap().instance_statuses.unwrap_or_default() { - println!( - " Events scheduled for instance ID: {}", - status.instance_id.as_deref().unwrap_or_default() - ); - for event in status.events.unwrap_or_default() { - println!(" Event ID: {}", event.instance_event_id.unwrap()); - println!(" Description: {}", event.description.unwrap()); - println!(" Event code: {}", event.code.unwrap().as_ref()); - println!(); - } - } -} - -/// Lists the events of your EC2 instances in all available regions. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("EC2 client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - show_all_events(&client).await -} diff --git a/aws/sdk/examples/ec2/src/bin/monitor-instance.rs b/aws/sdk/examples/ec2/src/bin/monitor-instance.rs deleted file mode 100644 index b4b9b27406..0000000000 --- a/aws/sdk/examples/ec2/src/bin/monitor-instance.rs +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The ID of the instance to monitor. - #[structopt(short, long)] - instance_id: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Enables monitoring for an instance. -async fn enable_monitoring( - client: &aws_sdk_ec2::Client, - id: &str, -) -> Result<(), aws_sdk_ec2::Error> { - client.monitor_instances().instance_ids(id).send().await?; - - println!("Enabled monitoring"); - - Ok(()) -} - -/// Enables monitoring for an Amazon EC2 instance. -/// # Arguments -/// -/// * `-i INSTANCE-ID` - The ID of the instances to monitor. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { - region, - instance_id, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("EC2 client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("Instance ID: {}", instance_id); - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - enable_monitoring(&client, &instance_id).await -} diff --git a/aws/sdk/examples/ec2/src/bin/reboot-instance.rs b/aws/sdk/examples/ec2/src/bin/reboot-instance.rs deleted file mode 100644 index 9bfdcefee3..0000000000 --- a/aws/sdk/examples/ec2/src/bin/reboot-instance.rs +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The ID of the instance to reboot. - #[structopt(short, long)] - instance_id: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Reboots an instance. -async fn reboot_instance(client: &aws_sdk_ec2::Client, id: &str) -> Result<(), aws_sdk_ec2::Error> { - client.reboot_instances().instance_ids(id).send().await?; - - println!("Rebooted instance."); - Ok(()) -} - -/// Reboots an Amazon EC2 instance. -/// # Arguments -/// -/// * `-i INSTANCE-ID` - The ID of the instances to reboot. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { - region, - instance_id, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("EC2 client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("Instance ID: {}", instance_id); - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - reboot_instance(&client, &instance_id).await -} diff --git a/aws/sdk/examples/ec2/src/bin/start-instance.rs b/aws/sdk/examples/ec2/src/bin/start-instance.rs deleted file mode 100644 index 59ad2952bf..0000000000 --- a/aws/sdk/examples/ec2/src/bin/start-instance.rs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The ID of the instance to stop. - #[structopt(short, long)] - instance_id: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Starts an instance. -async fn start_instance(client: &aws_sdk_ec2::Client, id: &str) -> Result<(), aws_sdk_ec2::Error> { - client.start_instances().instance_ids(id).send().await?; - - println!("Started instance."); - - Ok(()) -} - -/// Starts an Amazon EC2 instance. -/// # Arguments -/// -/// * `-i INSTANCE-ID` - The ID of the instances to start. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { - region, - instance_id, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("EC2 client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("Instance ID: {}", instance_id); - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - start_instance(&client, &instance_id).await -} diff --git a/aws/sdk/examples/ec2/src/bin/stop-instance.rs b/aws/sdk/examples/ec2/src/bin/stop-instance.rs deleted file mode 100644 index b1f15c83a3..0000000000 --- a/aws/sdk/examples/ec2/src/bin/stop-instance.rs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The ID of the instance to stop. - #[structopt(short, long)] - instance_id: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -// Stops an instance. -async fn stop_instance(client: &aws_sdk_ec2::Client, id: &str) -> Result<(), aws_sdk_ec2::Error> { - client.stop_instances().instance_ids(id).send().await?; - - println!("Stopped instance."); - - Ok(()) -} - -/// Stops an Amazon EC2 instance. -/// # Arguments -/// -/// * `-i INSTANCE-ID` - The ID of the instances to stop. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { - region, - instance_id, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - println!(); - - if verbose { - println!("EC2 client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("Instance ID: {}", instance_id); - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - stop_instance(&client, &instance_id).await -} diff --git a/aws/sdk/examples/ecr/Cargo.toml b/aws/sdk/examples/ecr/Cargo.toml deleted file mode 100644 index 3e5f783fbf..0000000000 --- a/aws/sdk/examples/ecr/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "ecr-examples" -version = "0.1.0" -authors = ["Russell Cohen "] -edition = "2018" - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-ecr = { path = "../../build/aws-sdk/sdk/ecr" } -tokio = { version = "1", features = ["full"]} -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } diff --git a/aws/sdk/examples/ecr/src/main.rs b/aws/sdk/examples/ecr/src/main.rs deleted file mode 100644 index 661a459ba9..0000000000 --- a/aws/sdk/examples/ecr/src/main.rs +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ecr::Region; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The region - #[structopt(short, long)] - region: Option, - - #[structopt(long)] - repository: String, - - #[structopt(short, long)] - verbose: bool, -} -#[tokio::main] -async fn main() -> Result<(), aws_sdk_ecr::Error> { - let Opt { - region, - repository, - verbose, - } = Opt::from_args(); - if verbose { - tracing_subscriber::fmt::init(); - } - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = aws_sdk_ecr::Client::new(&shared_config); - let rsp = client - .list_images() - .repository_name(&repository) - .send() - .await?; - let images = rsp.image_ids.unwrap_or_default(); - println!("found {} images", images.len()); - for image in images { - println!( - "image: {}:{}", - image.image_tag.unwrap(), - image.image_digest.unwrap() - ); - } - Ok(()) -} diff --git a/aws/sdk/examples/ecs/Cargo.toml b/aws/sdk/examples/ecs/Cargo.toml deleted file mode 100644 index d94e65d4ab..0000000000 --- a/aws/sdk/examples/ecs/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "ecs" -version = "0.1.0" -authors = ["Russell Cohen "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -tokio = { version = "1", features = ["full"]} -aws-sdk-ecs = { path = "../../build/aws-sdk/sdk/ecs" } diff --git a/aws/sdk/examples/ecs/src/main.rs b/aws/sdk/examples/ecs/src/main.rs deleted file mode 100644 index 0f88ffcec6..0000000000 --- a/aws/sdk/examples/ecs/src/main.rs +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -#[tokio::main] -async fn main() -> Result<(), aws_sdk_ecs::Error> { - let shared_config = aws_config::load_from_env().await; - let client = aws_sdk_ecs::Client::new(&shared_config); - let cluster = client - .create_cluster() - .cluster_name("test_cluster") - .send() - .await?; - println!("cluster created: {:?}", cluster); - - let cluster_deleted = client - .delete_cluster() - .cluster("test_cluster") - .send() - .await?; - println!("cluster deleted: {:?}", cluster_deleted); - Ok(()) -} diff --git a/aws/sdk/examples/eks/Cargo.toml b/aws/sdk/examples/eks/Cargo.toml deleted file mode 100644 index 7068ba597c..0000000000 --- a/aws/sdk/examples/eks/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "eks" -version = "0.1.0" -authors = ["Russell Cohen "] -edition = "2018" - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -structopt = { version = "0.3", default-features = false } -tokio = { version = "1", features = ["full"]} -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -aws-sdk-eks = { path = "../../build/aws-sdk/sdk/eks" } diff --git a/aws/sdk/examples/eks/src/bin/create-cluster.rs b/aws/sdk/examples/eks/src/bin/create-cluster.rs deleted file mode 100644 index 5a43f42fb3..0000000000 --- a/aws/sdk/examples/eks/src/bin/create-cluster.rs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_eks::model::VpcConfigRequest; -use aws_sdk_eks::Region; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The region - #[structopt(short, long)] - region: Option, - - #[structopt(short, long)] - cluster_name: String, - - /// Role ARN for the cluster - /// To create a role-arn: - /// - /// 1. Follow instructions to create an IAM role: - /// https://docs.aws.amazon.com/eks/latest/userguide/service_IAM_role.html - /// - /// 2. Copy role arn - #[structopt(long)] - role_arn: String, - - /// subnet id - /// - /// At least two subnet ids must be specified. The subnet ids must be in two separate AZs - #[structopt(short, long)] - subnet_id: Vec, -} - -#[tokio::main] -async fn main() -> Result<(), aws_sdk_eks::Error> { - let Opt { - region, - cluster_name, - role_arn, - subnet_id, - } = Opt::from_args(); - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = aws_sdk_eks::Client::new(&shared_config); - - let cluster = client - .create_cluster() - .name(&cluster_name) - .role_arn(role_arn) - .resources_vpc_config( - VpcConfigRequest::builder() - .set_subnet_ids(Some(subnet_id)) - .build(), - ) - .send() - .await?; - println!("cluster created: {:?}", cluster); - - let cluster_deleted = client.delete_cluster().name(&cluster_name).send().await?; - println!("cluster deleted: {:?}", cluster_deleted); - Ok(()) -} diff --git a/aws/sdk/examples/iam/Cargo.toml b/aws/sdk/examples/iam/Cargo.toml deleted file mode 100644 index ab2e7ea99b..0000000000 --- a/aws/sdk/examples/iam/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "iam-code-examples" -version = "0.1.0" -authors = ["Russell Cohen "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-iam = { path = "../../build/aws-sdk/sdk/iam" } -tokio = { version = "1", features = ["full"] } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/iam/src/bin/iam-hello-world.rs b/aws/sdk/examples/iam/src/bin/iam-hello-world.rs deleted file mode 100644 index 2e9a23bace..0000000000 --- a/aws/sdk/examples/iam/src/bin/iam-hello-world.rs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_sdk_iam as iam; - -#[tokio::main] -async fn main() -> Result<(), iam::Error> { - tracing_subscriber::fmt::init(); - let shared_config = aws_config::load_from_env().await; - let client = iam::Client::new(&shared_config); - let rsp = client.list_policies().send().await?; - for policy in rsp.policies.unwrap_or_default() { - println!( - "arn: {}; description: {}", - policy.arn.unwrap(), - policy.description.unwrap_or_default() - ); - } - Ok(()) -} diff --git a/aws/sdk/examples/kinesis/Cargo.toml b/aws/sdk/examples/kinesis/Cargo.toml deleted file mode 100644 index f52fccb7bb..0000000000 --- a/aws/sdk/examples/kinesis/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "kinesis-code-examples" -version = "0.1.0" -authors = ["Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-kinesis = { path = "../../build/aws-sdk/sdk/kinesis" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/kinesis/src/bin/create-stream.rs b/aws/sdk/examples/kinesis/src/bin/create-stream.rs deleted file mode 100644 index d804f7477f..0000000000 --- a/aws/sdk/examples/kinesis/src/bin/create-stream.rs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_kinesis::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// THe name of the stream. - #[structopt(short, long)] - stream_name: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Creates an Amazon Kinesis data stream. -/// # Arguments -/// -/// * `-s STREAM-NAME` - The name of the stream. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { - stream_name, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Kinesis client version: {}", PKG_VERSION); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - println!("Stream name: {}", &stream_name); - println!(); - } - - client - .create_stream() - .stream_name(stream_name) - .shard_count(4) - .send() - .await?; - - println!("Created stream"); - - Ok(()) -} diff --git a/aws/sdk/examples/kinesis/src/bin/delete-stream.rs b/aws/sdk/examples/kinesis/src/bin/delete-stream.rs deleted file mode 100644 index 1342bc6523..0000000000 --- a/aws/sdk/examples/kinesis/src/bin/delete-stream.rs +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_kinesis::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the stream to delete. - #[structopt(short, long)] - stream_name: String, - - /// Whether to display additional information - #[structopt(short, long)] - verbose: bool, -} - -/// Deletes an Amazon Kinesis data stream. -/// # Arguments -/// -/// * `-s STREAM-NAME` - The name of the stream. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { - stream_name, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Kinesis version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Stream name: {}", &stream_name); - println!(); - } - - client - .delete_stream() - .stream_name(stream_name) - .send() - .await?; - - println!("Deleted stream."); - - Ok(()) -} diff --git a/aws/sdk/examples/kinesis/src/bin/describe-stream.rs b/aws/sdk/examples/kinesis/src/bin/describe-stream.rs deleted file mode 100644 index ae8064c4eb..0000000000 --- a/aws/sdk/examples/kinesis/src/bin/describe-stream.rs +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_kinesis::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the stream. - #[structopt(short, long)] - stream_name: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your Amazon Kinesis data streams in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { - stream_name, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Kinesis version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Stream name: {}", &stream_name); - println!(); - } - - let resp = client - .describe_stream() - .stream_name(stream_name) - .send() - .await?; - - let desc = resp.stream_description.unwrap(); - - println!("Stream description:"); - println!(" Name: {}:", desc.stream_name.unwrap()); - println!(" Status: {:?}", desc.stream_status.unwrap()); - println!(" Open shards: {:?}", desc.shards.unwrap().len()); - println!( - " Retention (hours): {}", - desc.retention_period_hours.unwrap() - ); - println!(" Encryption: {:?}", desc.encryption_type.unwrap()); - - Ok(()) -} diff --git a/aws/sdk/examples/kinesis/src/bin/list-streams.rs b/aws/sdk/examples/kinesis/src/bin/list-streams.rs deleted file mode 100644 index a862374c44..0000000000 --- a/aws/sdk/examples/kinesis/src/bin/list-streams.rs +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_kinesis::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information - #[structopt(short, long)] - verbose: bool, -} - -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Kinesis version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!(); - } - - let resp = client.list_streams().send().await?; - - println!("Stream names:"); - - let streams = resp.stream_names.unwrap_or_default(); - for stream in &streams { - println!(" {}", stream); - } - - println!("Found {} stream(s)", streams.len()); - - Ok(()) -} diff --git a/aws/sdk/examples/kinesis/src/bin/put-record.rs b/aws/sdk/examples/kinesis/src/bin/put-record.rs deleted file mode 100644 index 53067cb6f0..0000000000 --- a/aws/sdk/examples/kinesis/src/bin/put-record.rs +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_kinesis::{Blob, Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The data to add to the stream. - #[structopt(short, long)] - data: String, - - /// The name of the partition key. - #[structopt(short, long)] - key: String, - - /// The name of the stream. - #[structopt(short, long)] - stream_name: String, - - #[structopt(short, long)] - verbose: bool, -} - -/// Adds a record to an Amazon Kinesis data stream. -/// # Arguments -/// -/// * `-s STREAM-NAME` - The name of the stream. -/// * `-k KEY-NAME` - The name of the partition key. -/// * `-d DATA` - The data to add. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - data, - key, - stream_name, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Kinesis version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Data:"); - println!(); - println!("{}", &data); - println!(); - println!("Partition key: {}", &key); - println!("Stream name: {}", &stream_name); - println!(); - } - - let blob = Blob::new(data); - - client - .put_record() - .data(blob) - .partition_key(key) - .stream_name(stream_name) - .send() - .await?; - - println!("Put data into stream."); - - Ok(()) -} diff --git a/aws/sdk/examples/kms/Cargo.toml b/aws/sdk/examples/kms/Cargo.toml deleted file mode 100644 index 754a528433..0000000000 --- a/aws/sdk/examples/kms/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "kms-code-examples" -version = "0.1.0" -authors = ["Russell Cohen ", "Doug Schwartz , - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} -/// Creates an AWS KMS key. -/// # Arguments -/// -/// * `[-d DEFAULT-REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("KMS version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!(); - } - - let resp = client.create_key().send().await?; - - let id = resp - .key_metadata - .unwrap() - .key_id - .unwrap_or_else(|| String::from("No ID!")); - - println!("Key: {}", id); - - Ok(()) -} diff --git a/aws/sdk/examples/kms/src/bin/decrypt.rs b/aws/sdk/examples/kms/src/bin/decrypt.rs deleted file mode 100644 index f7b0547a59..0000000000 --- a/aws/sdk/examples/kms/src/bin/decrypt.rs +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_kms::{Blob, Client, Error, Region, PKG_VERSION}; -use std::fs; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// The encryption key. - #[structopt(short, long)] - key: String, - - /// The name of the input file with encrypted text to decrypt. - #[structopt(short, long)] - input_file: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Decrypts a string encrypted by AWS KMS. -/// # Arguments -/// -/// * `-k KEY` - The encryption key. -/// * `-i INPUT-FILE` - The name of the file containing the encrypted string. -/// * `[-d DEFAULT-REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - key, - input_file, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("KMS version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Key: {}", &key); - println!("Input: {}", &input_file); - println!(); - } - - // Open input text file and get contents as a string - // input is a base-64 encoded string, so decode it: - let data = fs::read_to_string(input_file) - .map(|input| { - base64::decode(input).expect("Input file does not contain valid base 64 characters.") - }) - .map(Blob::new); - - let resp = client - .decrypt() - .key_id(key) - .ciphertext_blob(data.unwrap()) - .send() - .await?; - - let inner = resp.plaintext.unwrap(); - let bytes = inner.as_ref(); - - let s = String::from_utf8(bytes.to_vec()).expect("Could not convert to UTF-8"); - - println!(); - println!("Decoded string:"); - println!("{}", s); - - Ok(()) -} diff --git a/aws/sdk/examples/kms/src/bin/encrypt.rs b/aws/sdk/examples/kms/src/bin/encrypt.rs deleted file mode 100644 index f7d4482143..0000000000 --- a/aws/sdk/examples/kms/src/bin/encrypt.rs +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_kms::{Blob, Client, Error, Region, PKG_VERSION}; -use std::fs::File; -use std::io::Write; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// The encryption key. - #[structopt(short, long)] - key: String, - - /// The text to encrypt. - #[structopt(short, long)] - text: String, - - /// The name of the file to store the encrypted text in. - #[structopt(short, long)] - out_file: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Encrypts a string using an AWS KMS key. -/// # Arguments -/// -/// * `-k KEY` - The KMS key. -/// * `-o OUT-FILE` - The name of the file to store the encryped key in. -/// * `-t TEXT` - The string to encrypt. -/// * `[-d DEFAULT-REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - key, - out_file, - region, - text, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("KMS version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Key: {}", &key); - println!("Text: {}", &text); - println!("Output file: {}", &out_file); - println!(); - } - - let blob = Blob::new(text.as_bytes()); - - let resp = client.encrypt().key_id(key).plaintext(blob).send().await?; - - // Did we get an encrypted blob? - let blob = resp.ciphertext_blob.expect("Could not get encrypted text"); - let bytes = blob.as_ref(); - - let s = base64::encode(&bytes); - - let mut ofile = File::create(&out_file).expect("unable to create file"); - ofile.write_all(s.as_bytes()).expect("unable to write"); - ofile.flush().expect("failed to flush"); - - if verbose { - println!("Wrote the following to {:?}", out_file); - println!("{}", s); - } - - Ok(()) -} diff --git a/aws/sdk/examples/kms/src/bin/generate-data-key-without-plaintext.rs b/aws/sdk/examples/kms/src/bin/generate-data-key-without-plaintext.rs deleted file mode 100644 index 95a6974def..0000000000 --- a/aws/sdk/examples/kms/src/bin/generate-data-key-without-plaintext.rs +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_kms::model::DataKeySpec; -use aws_sdk_kms::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// The encryption key. - #[structopt(short, long)] - key: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Creates an AWS KMS data key without plaintext. -/// # Arguments -/// -/// * `[-k KEY]` - The name of the data key. -/// * `[-d DEFAULT-REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - key, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("KMS version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("KMS key: {}", &key); - println!(); - } - - let resp = client - .generate_data_key_without_plaintext() - .key_id(key) - .key_spec(DataKeySpec::Aes256) - .send() - .await?; - - // Did we get an encrypted blob? - let blob = resp.ciphertext_blob.expect("Could not get encrypted text"); - let bytes = blob.as_ref(); - - let s = base64::encode(&bytes); - - println!(); - println!("Data key:"); - println!("{}", s); - - Ok(()) -} diff --git a/aws/sdk/examples/kms/src/bin/generate-data-key.rs b/aws/sdk/examples/kms/src/bin/generate-data-key.rs deleted file mode 100644 index 8fd38896fb..0000000000 --- a/aws/sdk/examples/kms/src/bin/generate-data-key.rs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_kms::model::DataKeySpec; -use aws_sdk_kms::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// The encryption key. - #[structopt(short, long)] - key: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Creates an AWS KMS data key. -/// # Arguments -/// -/// * `[-k KEY]` - The name of the key. -/// * `[-d DEFAULT-REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - key, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("KMS version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Key: {}", &key); - println!(); - } - - let resp = client - .generate_data_key() - .key_id(key) - .key_spec(DataKeySpec::Aes256) - .send() - .await?; - - // Did we get an encrypted blob? - let blob = resp.ciphertext_blob.expect("Could not get encrypted text"); - let bytes = blob.as_ref(); - - let s = base64::encode(&bytes); - - println!(); - println!("Data key:"); - println!("{}", s); - - Ok(()) -} diff --git a/aws/sdk/examples/kms/src/bin/generate-random.rs b/aws/sdk/examples/kms/src/bin/generate-random.rs deleted file mode 100644 index c4f64a3ccd..0000000000 --- a/aws/sdk/examples/kms/src/bin/generate-random.rs +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_kms::{Client, Error, Region, PKG_VERSION}; -use std::process; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// The # of bytes. Must be less than 1024. - #[structopt(short, long)] - length: i32, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Creates a random byte string that is cryptographically secure. -/// # Arguments -/// -/// * `[-l LENGTH]` - The number of bytes to generate. Must be less than 1024. -/// * `[-d DEFAULT-REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - length, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - // Trap out-of-range-values: - match length { - 1...1024 => { - println!("Generating a {} byte random string", length); - } - _ => { - println!("Length {} is not within range 1-1024", length); - process::exit(1); - } - } - - if verbose { - println!("KMS version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Length: {}", &length); - println!(); - } - - let resp = client - .generate_random() - .number_of_bytes(length) - .send() - .await?; - - // Did we get an encrypted blob? - let blob = resp.plaintext.expect("Could not get encrypted text"); - let bytes = blob.as_ref(); - - let s = base64::encode(&bytes); - - println!(); - println!("Data key:"); - println!("{}", s); - - Ok(()) -} diff --git a/aws/sdk/examples/kms/src/bin/reencrypt-data.rs b/aws/sdk/examples/kms/src/bin/reencrypt-data.rs deleted file mode 100644 index ed70c473b2..0000000000 --- a/aws/sdk/examples/kms/src/bin/reencrypt-data.rs +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_kms::{Blob, Client, Error, Region, PKG_VERSION}; -use std::fs; -use std::fs::File; -use std::io::Write; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// The original encryption key. - #[structopt(short, long)] - first_key: String, - - /// The new encryption key. - #[structopt(short, long)] - new_key: String, - - /// The name of the input file containing the text to reencrypt. - #[structopt(short, long)] - input_file: String, - - /// The name of the output file containing the reencrypted text. - #[structopt(short, long)] - output_file: String, - - /// Whether to display additional runtime information. - #[structopt(short, long)] - verbose: bool, -} - -/// Re-encrypts a string with an AWS KMS key. -/// # Arguments -/// -/// * `[-f FIRST-KEY]` - The first key used to originally encrypt the string. -/// * `[-n NEW-KEY]` - The new key used to re-encrypt the string. -/// * `[-i INPUT-FILE]` - The file containing the encrypted string. -/// * `[-o OUTPUT-FILE]` - The file containing the re-encrypted string. -/// * `[-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> { - tracing_subscriber::fmt::init(); - - let Opt { - first_key, - new_key, - input_file, - output_file, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("KMS version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Input key: {}", &first_key); - println!("Output key: {}", &new_key); - println!("Input filename: {}", &input_file); - println!("Output filename: {}", &output_file); - println!(); - } - - // Get blob from input file - // Open input text file and get contents as a string - // input is a base-64 encoded string, so decode it: - let data = fs::read_to_string(input_file) - .map(|input_file| base64::decode(input_file).expect("invalid base 64")) - .map(Blob::new); - - let resp = client - .re_encrypt() - .ciphertext_blob(data.unwrap()) - .source_key_id(first_key) - .destination_key_id(new_key) - .send() - .await?; - - // Did we get an encrypted blob? - let blob = resp.ciphertext_blob.expect("Could not get encrypted text"); - let bytes = blob.as_ref(); - - let s = base64::encode(&bytes); - let o = &output_file; - - let mut ofile = File::create(o).expect("unable to create file"); - ofile.write_all(s.as_bytes()).expect("unable to write"); - ofile.flush().expect("failed to flush"); - - if verbose { - println!("Wrote the following to {}:", output_file); - println!("{}", s); - } else { - println!("Wrote base64-encoded output to {}", output_file); - } - - Ok(()) -} diff --git a/aws/sdk/examples/lambda/Cargo.toml b/aws/sdk/examples/lambda/Cargo.toml deleted file mode 100644 index e908b62916..0000000000 --- a/aws/sdk/examples/lambda/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "lambda-code-examples" -version = "0.1.0" -authors = ["Richard H. Boyd ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-ec2 = { package = "aws-sdk-ec2", path = "../../build/aws-sdk/sdk/ec2" } -aws-sdk-lambda = { package = "aws-sdk-lambda", path = "../../build/aws-sdk/sdk/lambda" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/lambda/src/bin/change-java-runtime.rs b/aws/sdk/examples/lambda/src/bin/change-java-runtime.rs deleted file mode 100644 index e4f9acb00a..0000000000 --- a/aws/sdk/examples/lambda/src/bin/change-java-runtime.rs +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_lambda::model::Runtime; -use aws_sdk_lambda::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The Lambda function's ARN. - #[structopt(short, long)] - arn: String, - - /// Whether to display additional runtime information. - #[structopt(short, long)] - verbose: bool, -} - -/// Sets a Lambda function's Java runtime to Corretto. -/// # Arguments -/// -/// * `-a ARN` - The ARN of the Lambda function. -/// * `[-r -REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - arn, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("Lambda version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!("Lambda function ARN: {}", &arn); - println!(); - } - - let client = Client::new(&shared_config); - - // Get function's runtime - let resp = client.list_functions().send().await?; - - for function in resp.functions.unwrap_or_default() { - // We only change the runtime for the specified function. - if arn == function.function_arn.unwrap() { - let rt = function.runtime.unwrap(); - // We only change the Java runtime. - if rt == Runtime::Java11 || rt == Runtime::Java8 { - // Change it to Java8a12 (Corretto). - println!("Original runtime: {:?}", rt); - let result = client - .update_function_configuration() - .function_name(function.function_name.unwrap()) - .runtime(Runtime::Java8al2) - .send() - .await?; - - let result_rt = result.runtime.unwrap(); - println!("New runtime: {:?}", result_rt); - } - } - } - - Ok(()) -} diff --git a/aws/sdk/examples/lambda/src/bin/invoke-function.rs b/aws/sdk/examples/lambda/src/bin/invoke-function.rs deleted file mode 100644 index 8fc4a88d1f..0000000000 --- a/aws/sdk/examples/lambda/src/bin/invoke-function.rs +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_lambda::{Client, Error, Region, PKG_VERSION}; -use std::str; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The Lambda function's ARN. - #[structopt(short, long)] - arn: String, - - /// Whether to display additional runtime information. - #[structopt(short, long)] - verbose: bool, -} - -/// Invokes a Lambda function by its ARN. -/// # Arguments -/// -/// * `-a ARN` - The ARN of the Lambda function. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - let Opt { - arn, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!("Lambda version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!("Function ARN: {}", arn); - println!(); - } - - let client = Client::new(&shared_config); - - let resp = client.invoke().function_name(arn).send().await?; - if let Some(blob) = resp.payload { - let s = str::from_utf8(blob.as_ref()).expect("invalid utf-8"); - println!("Response: {:?}", s); - } - - Ok(()) -} diff --git a/aws/sdk/examples/lambda/src/bin/list-all-function-runtimes.rs b/aws/sdk/examples/lambda/src/bin/list-all-function-runtimes.rs deleted file mode 100644 index 89c0470a3e..0000000000 --- a/aws/sdk/examples/lambda/src/bin/list-all-function-runtimes.rs +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ec2 as ec2; -use aws_sdk_lambda as lambda; -use aws_types::region::Region; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region in which the client is created. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional runtime information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the Lambda ARNs and runtimes in the given AWS Region. -async fn show_lambdas(verbose: bool, region: &str) { - let shared_config = aws_config::from_env() - .region(Region::new(region.to_string())) - .load() - .await; - let client = lambda::Client::new(&shared_config); - - let resp = client.list_functions().send().await; - let functions = resp.unwrap().functions.unwrap_or_default(); - let num_functions = functions.len(); - - if num_functions > 0 || verbose { - println!("Found {} functions in {}:", num_functions, region); - println!(); - } - - for function in functions { - println!(" ARN: {}", function.function_arn.unwrap()); - println!(" Runtime: {:?}", function.runtime.unwrap()); - println!(); - } -} - -/// Lists the ARNs and runtimes of your Lambda functions in all available regions. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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<(), lambda::Error> { - tracing_subscriber::fmt::init(); - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(ec2::Region::new)) - .or_default_provider() - .or_else(ec2::Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("EC2 client version: {}", ec2::PKG_VERSION); - println!("Lambda client version: {}", lambda::PKG_VERSION); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - println!(); - } - - // Get list of available regions. - let ec2_client = ec2::Client::new(&shared_config); - let resp = ec2_client.describe_regions().send().await; - - for region in resp.unwrap().regions.unwrap_or_default() { - show_lambdas(verbose, ®ion.region_name.unwrap()).await; - } - - Ok(()) -} diff --git a/aws/sdk/examples/lambda/src/bin/list-functions.rs b/aws/sdk/examples/lambda/src/bin/list-functions.rs deleted file mode 100644 index a15cfab8d5..0000000000 --- a/aws/sdk/examples/lambda/src/bin/list-functions.rs +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_lambda::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the ARNs of your Lambda functions in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("Lambda version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!(); - } - - let client = Client::new(&shared_config); - - let resp = client.list_functions().send().await?; - - println!("Function ARNs:"); - - let functions = resp.functions.unwrap_or_default(); - let len = functions.len(); - - for function in functions { - println!(" {}", function.function_arn.unwrap_or_default()); - } - - println!(); - println!("Found {} functions", len); - - Ok(()) -} diff --git a/aws/sdk/examples/medialive/Cargo.toml b/aws/sdk/examples/medialive/Cargo.toml deleted file mode 100644 index 4b411852f5..0000000000 --- a/aws/sdk/examples/medialive/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "medialive-code-examples" -version = "0.1.0" -authors = ["Alistair McLean ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-medialive = { path = "../../build/aws-sdk/sdk/medialive" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/medialive/src/bin/medialive-helloworld.rs b/aws/sdk/examples/medialive/src/bin/medialive-helloworld.rs deleted file mode 100644 index 398d71aeb9..0000000000 --- a/aws/sdk/examples/medialive/src/bin/medialive-helloworld.rs +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_medialive::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your AWS Elemental MediaLive input names and ARNs in the Region. -/// # Arguments -/// -/// * `[-d DEFAULT-REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("MediaLive version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!(); - } - - let input_list = client.list_inputs().send().await?; - - for i in input_list.inputs.unwrap_or_default() { - let input_arn = i.arn.as_deref().unwrap_or_default(); - let input_name = i.name.as_deref().unwrap_or_default(); - - println!("Input Name : {}, Input ARN : {}", input_name, input_arn); - } - - Ok(()) -} diff --git a/aws/sdk/examples/mediapackage/Cargo.toml b/aws/sdk/examples/mediapackage/Cargo.toml deleted file mode 100644 index d1d4c8d93f..0000000000 --- a/aws/sdk/examples/mediapackage/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "mediapackage-code-examples" -version = "0.1.0" -authors = ["Alistair McLean ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-mediapackage = { path = "../../build/aws-sdk/sdk/mediapackage" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/mediapackage/src/bin/list-endpoints.rs b/aws/sdk/examples/mediapackage/src/bin/list-endpoints.rs deleted file mode 100644 index 1c75d3ccef..0000000000 --- a/aws/sdk/examples/mediapackage/src/bin/list-endpoints.rs +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -/// Lists your AWS Elemental MediaPackage endpoint URLs. -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_mediapackage::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your AWS Elemental MediaPackage endpoint descriptions and URLs. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("MediaPackage version: {}", PKG_VERSION); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - println!(); - } - - let or_endpoints = client.list_origin_endpoints().send().await?; - - for e in or_endpoints.origin_endpoints.unwrap_or_default() { - let endpoint_url = e.url.as_deref().unwrap_or_default(); - let endpoint_description = e.description.as_deref().unwrap_or_default(); - println!( - "Endpoint Description: {}, Endpoint URL : {}", - endpoint_description, endpoint_url - ); - } - - Ok(()) -} diff --git a/aws/sdk/examples/mediapackage/src/bin/mediapackage-helloworld.rs b/aws/sdk/examples/mediapackage/src/bin/mediapackage-helloworld.rs deleted file mode 100644 index c95ed9e191..0000000000 --- a/aws/sdk/examples/mediapackage/src/bin/mediapackage-helloworld.rs +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_mediapackage::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your AWS Elemental MediaPackage channel ARNs and descriptions. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("MediaPackage version: {}", PKG_VERSION); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - println!(); - } - - let list_channels = client.list_channels().send().await?; - - for c in list_channels.channels.unwrap_or_default() { - let description = c.description.as_deref().unwrap_or_default(); - let arn = c.arn.as_deref().unwrap_or_default(); - - println!( - "Channel Description : {}, Channel ARN : {}", - description, arn - ); - } - - Ok(()) -} diff --git a/aws/sdk/examples/polly/Cargo.toml b/aws/sdk/examples/polly/Cargo.toml deleted file mode 100644 index 79f187f6bd..0000000000 --- a/aws/sdk/examples/polly/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "polly-code-examples" -version = "0.1.0" -authors = ["Russell Cohen ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-polly = { path = "../../build/aws-sdk/sdk/polly" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/polly/src/bin/describe-voices.rs b/aws/sdk/examples/polly/src/bin/describe-voices.rs deleted file mode 100644 index 10f038e789..0000000000 --- a/aws/sdk/examples/polly/src/bin/describe-voices.rs +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_polly::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to isplay additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Displays a list of the voices in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Polly version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!(); - } - - let resp = client.describe_voices().send().await?; - - println!("Voices:"); - - let voices = resp.voices.unwrap_or_default(); - for voice in &voices { - println!( - " Name: {}", - voice.name.as_deref().unwrap_or("No name!") - ); - println!( - " Language: {}", - voice.language_name.as_deref().unwrap_or("No language!") - ); - } - - println!(); - println!("Found {} voices", voices.len()); - println!(); - - Ok(()) -} diff --git a/aws/sdk/examples/polly/src/bin/list-lexicons.rs b/aws/sdk/examples/polly/src/bin/list-lexicons.rs deleted file mode 100644 index d865993596..0000000000 --- a/aws/sdk/examples/polly/src/bin/list-lexicons.rs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_polly::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Displays a list of the lexicons in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Polly version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!(); - } - - let resp = client.list_lexicons().send().await?; - - println!("Lexicons:"); - - let lexicons = resp.lexicons.unwrap_or_default(); - - for lexicon in &lexicons { - println!( - " Name: {}", - lexicon.name.as_deref().unwrap_or_default() - ); - println!( - " Language: {:?}\n", - lexicon - .attributes - .as_ref() - .map(|attrib| attrib - .language_code - .as_ref() - .expect("languages must have language codes")) - .expect("languages must have attributes") - ); - } - - println!(); - println!("Found {} lexicons.", lexicons.len()); - println!(); - - Ok(()) -} diff --git a/aws/sdk/examples/polly/src/bin/polly-helloworld.rs b/aws/sdk/examples/polly/src/bin/polly-helloworld.rs deleted file mode 100644 index 3a018cb0ec..0000000000 --- a/aws/sdk/examples/polly/src/bin/polly-helloworld.rs +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_polly::model::{Engine, Voice}; -use aws_sdk_polly::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Displays a list of the voices and their language, and those supporting a neural engine, in the region. -/// # Arguments -/// -/// * `[-r 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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Polly version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!(); - } - - let mut tok = None; - let mut voices: Vec = vec![]; - - // Below is an an example of how pagination can be implemented manually. - loop { - let mut req = client.describe_voices(); - - if let Some(tok) = tok { - req = req.next_token(tok); - } - - let resp = req.send().await?; - - for voice in resp.voices.unwrap_or_default() { - println!( - "I can speak as: {} in {:?}", - voice.name.as_ref().unwrap(), - voice.language_name.as_ref().unwrap() - ); - voices.push(voice); - } - - tok = match resp.next_token { - Some(next) => Some(next), - None => break, - }; - } - - let neural_voices = voices - .iter() - .filter(|voice| { - voice - .supported_engines - .as_deref() - .unwrap_or_default() - .contains(&Engine::Neural) - }) - .map(|voice| voice.id.as_ref().unwrap()) - .collect::>(); - - println!(); - println!("Voices supporting a neural engine: {:?}", neural_voices); - println!(); - - Ok(()) -} diff --git a/aws/sdk/examples/polly/src/bin/put-lexicon.rs b/aws/sdk/examples/polly/src/bin/put-lexicon.rs deleted file mode 100644 index 531dc4947b..0000000000 --- a/aws/sdk/examples/polly/src/bin/put-lexicon.rs +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_polly::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the lexicon. - #[structopt(short, long)] - name: String, - - /// The word to replace. - #[structopt(short, long)] - from: String, - - /// The replacement. - #[structopt(short, long)] - to: String, - - /// Whether to show additional output. - #[structopt(short, long)] - verbose: bool, -} - -/// Stores a pronunciation lexicon in a Region. -/// # Arguments -/// -/// * `-f FROM` - The original text to customize. -/// * `-n NAME` - The name of the lexicon. -/// * `-t TO` - The customized version of the original text. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - from, - name, - region, - to, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Polly version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Lexicon name: {}", &name); - println!("Text to replace: {}", &from); - println!("Replacement text: {}", &to); - println!(); - } - - let content = format!(" - - {}{} - ", from, to); - - client - .put_lexicon() - .name(name) - .content(content) - .send() - .await?; - - println!("Added lexicon"); - - Ok(()) -} diff --git a/aws/sdk/examples/polly/src/bin/synthesize-speech-presigned.rs b/aws/sdk/examples/polly/src/bin/synthesize-speech-presigned.rs deleted file mode 100644 index 6aab27ca6f..0000000000 --- a/aws/sdk/examples/polly/src/bin/synthesize-speech-presigned.rs +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_polly::input::SynthesizeSpeechInput; -use aws_sdk_polly::model::{OutputFormat, VoiceId}; -use aws_sdk_polly::presigning::config::PresigningConfig; -use aws_sdk_polly::{Client, Config, Region, PKG_VERSION}; -use std::error::Error; -use std::fs; -use std::time::Duration; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// The file containing the text to synthesize. - #[structopt(short, long)] - filename: String, - - /// How long in seconds before the presigned request should expire. - #[structopt(short, long)] - expires_in: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Generates a presigned request to synthesize UTF-8 input, plain text or SSML, to a stream of bytes in a file. -/// # Arguments -/// -/// * `-f FILENAME` - The name of the file containing the text to synthesize. -/// The output is saved in MP3 format in a file with the same basename, but with an __mp3__ extension. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-e EXPIRES_IN]` - The amount of time the presigned request should be valid for. -/// If not given, this defaults to 15 minutes. -/// * `[-v]` - Whether to display additional information. -#[tokio::main] -async fn main() -> Result<(), Box> { - tracing_subscriber::fmt::init(); - - let Opt { - filename, - region, - expires_in, - verbose, - } = Opt::from_args(); - let expires_in = Duration::from_secs(expires_in.unwrap_or(900)); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Polly version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Filename: {}", &filename); - println!(); - } - - let content = fs::read_to_string(&filename).unwrap(); - - // Presigned requests can be made with the client directly - let presigned_request = client - .synthesize_speech() - .output_format(OutputFormat::Mp3) - .text(content.clone()) - .voice_id(VoiceId::Joanna) - .presigned(PresigningConfig::expires_in(expires_in)?) - .await?; - println!("From client: {:?}", presigned_request); - - // Or, they can be made directly from an operation input - let presigned_request = SynthesizeSpeechInput::builder() - .output_format(OutputFormat::Mp3) - .text(content) - .voice_id(VoiceId::Joanna) - .build()? - .presigned( - &Config::from(&shared_config), - PresigningConfig::expires_in(expires_in)?, - ) - .await?; - println!("From operation input: {:?}", presigned_request); - - Ok(()) -} diff --git a/aws/sdk/examples/polly/src/bin/synthesize-speech.rs b/aws/sdk/examples/polly/src/bin/synthesize-speech.rs deleted file mode 100644 index 55d999f19c..0000000000 --- a/aws/sdk/examples/polly/src/bin/synthesize-speech.rs +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_polly::model::{OutputFormat, VoiceId}; -use aws_sdk_polly::{Client, Error, Region, PKG_VERSION}; -use std::fs; -use structopt::StructOpt; -use tokio::io::AsyncWriteExt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// The file containing the text to synthesize. - #[structopt(short, long)] - filename: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Synthesizes UTF-8 input, plain text or SSML, to a stream of bytes in a file. -/// # Arguments -/// -/// * `-f FILENAME` - The name of the file containing the text to synthesize. -/// The output is saved in MP3 format in a file with the same basename, but with an __mp3__ extension. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - filename, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("Polly version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Filename: {}", &filename); - println!(); - } - - let content = fs::read_to_string(&filename); - - let resp = client - .synthesize_speech() - .output_format(OutputFormat::Mp3) - .text(content.unwrap()) - .voice_id(VoiceId::Joanna) - .send() - .await?; - - // Get MP3 data from response and save it - let mut blob = resp - .audio_stream - .collect() - .await - .expect("failed to read data"); - - let parts: Vec<&str> = filename.split('.').collect(); - let out_file = format!("{}{}", String::from(parts[0]), ".mp3"); - - let mut file = tokio::fs::File::create(out_file) - .await - .expect("failed to create file"); - - file.write_all_buf(&mut blob) - .await - .expect("failed to write to file"); - - Ok(()) -} diff --git a/aws/sdk/examples/qldb/Cargo.toml b/aws/sdk/examples/qldb/Cargo.toml deleted file mode 100644 index 6ae7ff7ab7..0000000000 --- a/aws/sdk/examples/qldb/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "qldb-code-examples" -version = "0.1.0" -authors = ["Russell Cohen ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-qldb = { path = "../../build/aws-sdk/sdk/qldb" } -aws-sdk-qldbsession = { path = "../../build/aws-sdk/sdk/qldbsession" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/qldb/README.md b/aws/sdk/examples/qldb/README.md deleted file mode 100644 index 49b61fb6a4..0000000000 --- a/aws/sdk/examples/qldb/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# AWS SDK for Rust code examples for Amazon QLDB - -Amazon Quantum Ledger Database (Amazon QLDB) is a fully managed ledger database that provides a transparent, immutable, and cryptographically verifiable transaction log owned by a central trusted authority. - -## create-ledger - -This code example creates an Amazon QLDB ledger. - -### Usage - -```cargo run --bin create-ledger -l LEDGER [-r REGION] [-v]``` - -where: - -- _LEDGER_ is the name of the ledger to create. -- _REGION_ is 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__ enables displaying additional information. - -## list-ledgers - -This code example lists your Amazon QLDB ledgers. - -### Usage - -```cargo run --bin list-ledgers [-r REGION] [-v]``` - -where: - -- _REGION_ is 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__ enables displaying additional information. - -## qldb-helloworld - -This code example creates a low-level Amazon QLDB session against a ledger. - -The QldbSession API is not intended to be used directly. Instead, we recommend using a higher-level driver, such as the Amazon QLDB Driver for Rust. - -### Usage - -cargo run --bin qldb-helloworld -l LEDGER [-r REGION] [-v] - -where: - -- _LEDGER_ is the name of the ledger to create the session against. -- _REGION_ is 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__ enables displaying additional information. - -## diff --git a/aws/sdk/examples/qldb/src/bin/create-ledger.rs b/aws/sdk/examples/qldb/src/bin/create-ledger.rs deleted file mode 100644 index 99f24e9fe4..0000000000 --- a/aws/sdk/examples/qldb/src/bin/create-ledger.rs +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_qldb::model::PermissionsMode; -use aws_sdk_qldb::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// 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. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - ledger, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("QLDB version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!(); - } - - let result = client - .create_ledger() - .name(ledger) - .permissions_mode(PermissionsMode::AllowAll) - .send() - .await?; - - println!("ARN: {}", result.arn.unwrap()); - - Ok(()) -} diff --git a/aws/sdk/examples/qldb/src/bin/list-ledgers.rs b/aws/sdk/examples/qldb/src/bin/list-ledgers.rs deleted file mode 100644 index b35ed7dbee..0000000000 --- a/aws/sdk/examples/qldb/src/bin/list-ledgers.rs +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_qldb::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your Amazon QLDB ledgers. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("OLDB version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!(); - } - - 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(()) -} diff --git a/aws/sdk/examples/qldb/src/bin/qldb-helloworld.rs b/aws/sdk/examples/qldb/src/bin/qldb-helloworld.rs deleted file mode 100644 index a1a4f6523d..0000000000 --- a/aws/sdk/examples/qldb/src/bin/qldb-helloworld.rs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_qldbsession::model::StartSessionRequest; -use aws_sdk_qldbsession::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the ledger. - #[structopt(short, long)] - ledger: String, - - /// Whether to display additional 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. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - ledger, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("OLDB version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Ledger: {}", ledger); - println!(); - } - - let result = client - .send_command() - .start_session(StartSessionRequest::builder().ledger_name(ledger).build()) - .send() - .await?; - - println!( - "Session id: {:?}", - result.start_session.unwrap().session_token - ); - - Ok(()) -} diff --git a/aws/sdk/examples/rds/Cargo.toml b/aws/sdk/examples/rds/Cargo.toml deleted file mode 100644 index b21130e9ac..0000000000 --- a/aws/sdk/examples/rds/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "rds-code-examples" -authors = ["LMJW ", "Doug Schwartz "] -edition = "2018" -version = "0.1.0" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -aws-sdk-rds = { path = "../../build/aws-sdk/sdk/rds" } -structopt = { version = "0.3", default-features = false } -tokio = {version = "1", features = ["full"]} -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/rds/src/bin/rds-helloworld.rs b/aws/sdk/examples/rds/src/bin/rds-helloworld.rs deleted file mode 100644 index a3256cd536..0000000000 --- a/aws/sdk/examples/rds/src/bin/rds-helloworld.rs +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_rds::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Displays information about your RDS instances. -/// # Arguments -/// -/// * `[-r 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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("RDS version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!(); - } - - let result = client.describe_db_instances().send().await?; - - for db_instance in result.db_instances.unwrap_or_default() { - println!( - "DB instance identifier: {:?}", - db_instance - .db_instance_identifier - .expect("instance should have identifiers") - ); - println!( - "DB instance class: {:?}", - db_instance - .db_instance_class - .expect("instance should have class") - ); - println!( - "DB instance engine: {:?}", - db_instance.engine.expect("instance should have engine") - ); - println!( - "DB instance status: {:?}", - db_instance - .db_instance_status - .expect("instance should have status") - ); - println!( - "DB instance endpoint: {:?}", - db_instance.endpoint.expect("instance should have endpoint") - ); - } - - Ok(()) -} diff --git a/aws/sdk/examples/rdsdata/Cargo.toml b/aws/sdk/examples/rdsdata/Cargo.toml deleted file mode 100644 index 647f03370c..0000000000 --- a/aws/sdk/examples/rdsdata/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "rdsdata-code-examples" -authors = ["LMJW ", "Doug Schwartz "] -edition = "2018" -version = "0.1.0" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-rdsdata = { path = "../../build/aws-sdk/sdk/rdsdata"} -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = {version = "1", features = ["full"]} -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/rdsdata/src/bin/rdsdata-helloworld.rs b/aws/sdk/examples/rdsdata/src/bin/rdsdata-helloworld.rs deleted file mode 100644 index cf0c372c4f..0000000000 --- a/aws/sdk/examples/rdsdata/src/bin/rdsdata-helloworld.rs +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_rdsdata::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The default AWS Region. - #[structopt(short, long)] - default_region: Option, - - /// The SQL query string. - #[structopt(short, long)] - query: String, - - /// The ARN of your Aurora serverless DB cluster. - #[structopt(short, long)] - resource_arn: String, - - /// The ARN of the Secrets Manager secret. - #[structopt(short, long)] - secret_arn: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Sends a query to an Aurora serverless cluster. -/// # Arguments -/// -/// * `-q QUERY` - The SQL query to run against the cluster. -/// It should look something like: __"SELECT * FROM pg_catalog.pg_tables limit 1"__. -/// Don't forget you'll likely have to escape some characters. -/// * `-r RESOURCE_ARN` - The ARN of your Aurora serverless DB cluster. -/// It should look something like __arn:aws:rds:us-west-2:AWS_ACCOUNT:cluster:database-2__. -/// * `-s SECRET_ARN` - The ARN of the Secrets Manager secret. -/// It should look something like: __arn:aws:secretsmanager:us-west-2:AWS_ACCOUNT:secret:database2/test/postgres-b8maVb__. -/// * `[-d DEFAULT-REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - default_region, - query, - resource_arn, - secret_arn, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(default_region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("RDS data version: {}", PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Resource ARN: {}", &resource_arn); - println!("Secrets ARN: {}", &secret_arn); - println!("Query:"); - println!(" {}", &query); - println!(); - } - - let st = client - .execute_statement() - .resource_arn(resource_arn) - .database("postgres") // Do not confuse this with db instance name - .sql(query) - .secret_arn(secret_arn); - - let result = st.send().await?; - - println!("{:?}", result); - println!(); - - Ok(()) -} diff --git a/aws/sdk/examples/route53/Cargo.toml b/aws/sdk/examples/route53/Cargo.toml deleted file mode 100644 index e938108783..0000000000 --- a/aws/sdk/examples/route53/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "route53-code-examples" -version = "0.1.0" -authors = ["Alistair McLean ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-route53 = { path = "../../build/aws-sdk/sdk/route53" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } - -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/route53/src/bin/route53-helloworld.rs b/aws/sdk/examples/route53/src/bin/route53-helloworld.rs deleted file mode 100644 index 933e097369..0000000000 --- a/aws/sdk/examples/route53/src/bin/route53-helloworld.rs +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_route53::{Client, 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, - - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Displays the IDs and names of the hosted zones in the region. -/// # 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<(), aws_sdk_route53::Error> { - let Opt { - default_region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(default_region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("Route53 client version: {}\n", aws_sdk_route53::PKG_VERSION); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - - SubscriberBuilder::default() - .with_env_filter("info") - .with_span_events(FmtSpan::CLOSE) - .init(); - } - - let hosted_zone_count = client.get_hosted_zone_count().send().await?; - - println!( - "\nNumber of hosted zones in region : {}", - hosted_zone_count.hosted_zone_count.unwrap_or_default(), - ); - - let hosted_zones = client.list_hosted_zones().send().await?; - - for hz in hosted_zones.hosted_zones.unwrap_or_default() { - let zone_name = hz.name.as_deref().unwrap_or_default(); - let zone_id = hz.id.as_deref().unwrap_or_default(); - - println!("Zone ID : {}, Zone Name : {}", zone_id, zone_name); - - let record_sets = client - .list_resource_record_sets() - .hosted_zone_id(zone_id) - .send() - .await?; - println!(" Record sets:"); - for set in record_sets.resource_record_sets().unwrap_or_default() { - println!(" {:?}: {:?}", set.name, set.r#type) - } - } - - Ok(()) -} diff --git a/aws/sdk/examples/s3/Cargo.toml b/aws/sdk/examples/s3/Cargo.toml deleted file mode 100644 index 5411e8c688..0000000000 --- a/aws/sdk/examples/s3/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "s3-code-examples" -version = "0.1.0" -authors = ["Russell Cohen ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-s3 = { package = "aws-sdk-s3", path = "../../build/aws-sdk/sdk/s3" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } - -tokio = { version = "1", features = ["full"] } - -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/s3/src/bin/create-bucket.rs b/aws/sdk/examples/s3/src/bin/create-bucket.rs deleted file mode 100644 index bbe30e18fe..0000000000 --- a/aws/sdk/examples/s3/src/bin/create-bucket.rs +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_s3::model::{BucketLocationConstraint, CreateBucketConfiguration}; -use aws_sdk_s3::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the bucket. - #[structopt(short, long)] - bucket: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Creates an Amazon S3 bucket in the Region. -/// # Arguments -/// -/// * `-b BUCKET` - The name of the bucket. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - bucket, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("S3 client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!("Bucket: {}", &bucket); - println!(); - } - - let constraint = BucketLocationConstraint::from(shared_config.region().unwrap().as_ref()); - let cfg = CreateBucketConfiguration::builder() - .location_constraint(constraint) - .build(); - - client - .create_bucket() - .create_bucket_configuration(cfg) - .bucket(bucket) - .send() - .await?; - println!("Created bucket."); - - Ok(()) -} diff --git a/aws/sdk/examples/s3/src/bin/delete-object.rs b/aws/sdk/examples/s3/src/bin/delete-object.rs deleted file mode 100644 index 63827072e3..0000000000 --- a/aws/sdk/examples/s3/src/bin/delete-object.rs +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_s3::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the bucket. - #[structopt(short, long)] - bucket: String, - - /// The object to delete. - #[structopt(short, long)] - key: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Deletes an object in an Amazon S3 bucket. -/// # Arguments -/// -/// * `-b BUCKET` - The name of the bucket. -/// * `-k KEY` - The names of the object to delete. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - bucket, - key, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("S3 client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!("Bucket: {}", &bucket); - println!("Key: {}", &key); - println!(); - } - - client - .delete_object() - .bucket(&bucket) - .key(key) - .send() - .await?; - - println!("Object deleted."); - - Ok(()) -} diff --git a/aws/sdk/examples/s3/src/bin/get-object-presigned.rs b/aws/sdk/examples/s3/src/bin/get-object-presigned.rs deleted file mode 100644 index 4d567ac828..0000000000 --- a/aws/sdk/examples/s3/src/bin/get-object-presigned.rs +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_s3::input::GetObjectInput; -use aws_sdk_s3::presigning::config::PresigningConfig; -use aws_sdk_s3::{Client, Config, Region, PKG_VERSION}; -use std::error::Error; -use std::time::Duration; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the bucket. - #[structopt(short, long)] - bucket: String, - - /// The object key. - #[structopt(short, long)] - object: String, - - /// How long in seconds before the presigned request should expire. - #[structopt(short, long)] - expires_in: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Generates a presigned request for S3 GetObject. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-e EXPIRES_IN]` - The amount of time the presigned request should be valid for. -/// If not given, this defaults to 15 minutes. -/// * `[-v]` - Whether to display additional information. -#[tokio::main] -async fn main() -> Result<(), Box> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - bucket, - object, - expires_in, - verbose, - } = Opt::from_args(); - let expires_in = Duration::from_secs(expires_in.unwrap_or(900)); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("S3 client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!(); - } - - // Presigned requests can be made with the client directly - let presigned_request = client - .get_object() - .bucket(&bucket) - .key(&object) - .presigned(PresigningConfig::expires_in(expires_in)?) - .await?; - println!("From client: {:?}", presigned_request.uri()); - - // Or, they can be made directly from an operation input - let presigned_request = GetObjectInput::builder() - .bucket(bucket) - .key(object) - .build()? - .presigned( - &Config::from(&shared_config), - PresigningConfig::expires_in(expires_in)?, - ) - .await?; - println!("From operation input: {:?}", presigned_request.uri()); - - Ok(()) -} diff --git a/aws/sdk/examples/s3/src/bin/list-buckets.rs b/aws/sdk/examples/s3/src/bin/list-buckets.rs deleted file mode 100644 index bcea1c6f56..0000000000 --- a/aws/sdk/examples/s3/src/bin/list-buckets.rs +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_s3::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your Amazon S3 buckets in the Region. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("S3 client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!(); - } - - let resp = client.list_buckets().send().await?; - let buckets = resp.buckets().unwrap_or_default(); - let num_buckets = buckets.len(); - - for bucket in buckets { - println!("{}", bucket.name().unwrap_or_default()); - } - - println!(); - println!("Found {} buckets", num_buckets); - - Ok(()) -} diff --git a/aws/sdk/examples/s3/src/bin/list-object-versions.rs b/aws/sdk/examples/s3/src/bin/list-object-versions.rs deleted file mode 100644 index 74ae19b972..0000000000 --- a/aws/sdk/examples/s3/src/bin/list-object-versions.rs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_s3::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the bucket. - #[structopt(short, long)] - bucket: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the versions of the objects in an Amazon S3 bucket. -/// # Arguments -/// -/// * `-b BUCKET` - The name of the bucket. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - bucket, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("S3 client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!("Bucket: {}", &bucket); - println!(); - } - - let resp = client.list_object_versions().bucket(&bucket).send().await?; - - for version in resp.versions().unwrap_or_default() { - println!(" {}", version.key().unwrap_or_default()); - println!(" version ID: {}", version.version_id().unwrap_or_default()); - } - - Ok(()) -} diff --git a/aws/sdk/examples/s3/src/bin/list-objects.rs b/aws/sdk/examples/s3/src/bin/list-objects.rs deleted file mode 100644 index dbcd4eeaa9..0000000000 --- a/aws/sdk/examples/s3/src/bin/list-objects.rs +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_s3::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the bucket. - #[structopt(short, long)] - bucket: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the objects in an Amazon S3 bucket. -/// # Arguments -/// -/// * `-b BUCKET` - The name of the bucket. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - bucket, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("S3 client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!("Bucket: {}", &bucket); - println!(); - } - - let resp = client.list_objects_v2().bucket(&bucket).send().await?; - - println!("Objects:"); - - for object in resp.contents().unwrap_or_default() { - println!(" {}", object.key().unwrap_or_default()); - } - - Ok(()) -} diff --git a/aws/sdk/examples/s3/src/bin/put-object-presigned.rs b/aws/sdk/examples/s3/src/bin/put-object-presigned.rs deleted file mode 100644 index 0282856b9d..0000000000 --- a/aws/sdk/examples/s3/src/bin/put-object-presigned.rs +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_s3::input::PutObjectInput; -use aws_sdk_s3::presigning::config::PresigningConfig; -use aws_sdk_s3::{Client, Config, Region, PKG_VERSION}; -use std::error::Error; -use std::time::Duration; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the bucket. - #[structopt(short, long)] - bucket: String, - - /// The object key. - #[structopt(short, long)] - object: String, - - /// How long in seconds before the presigned request should expire. - #[structopt(short, long)] - expires_in: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Generates a presigned request for S3 PutObject. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `[-e EXPIRES_IN]` - The amount of time the presigned request should be valid for. -/// If not given, this defaults to 15 minutes. -/// * `[-v]` - Whether to display additional information. -#[tokio::main] -async fn main() -> Result<(), Box> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - bucket, - object, - expires_in, - verbose, - } = Opt::from_args(); - let expires_in = Duration::from_secs(expires_in.unwrap_or(900)); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("S3 client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!(); - } - - // Presigned requests can be made with the client directly - let presigned_request = client - .put_object() - .bucket(&bucket) - .key(&object) - .presigned(PresigningConfig::expires_in(expires_in)?) - .await?; - println!("From client: {:?}", presigned_request.uri()); - - // Or, they can be made directly from an operation input - let presigned_request = PutObjectInput::builder() - .bucket(bucket) - .key(object) - .build()? - .presigned( - &Config::from(&shared_config), - PresigningConfig::expires_in(expires_in)?, - ) - .await?; - println!("From operation input: {:?}", presigned_request.uri()); - - Ok(()) -} diff --git a/aws/sdk/examples/s3/src/bin/s3-helloworld.rs b/aws/sdk/examples/s3/src/bin/s3-helloworld.rs deleted file mode 100644 index 3e6cbd17f7..0000000000 --- a/aws/sdk/examples/s3/src/bin/s3-helloworld.rs +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_s3::{ByteStream, Client, Error, Region, PKG_VERSION}; - -use std::path::Path; -use std::process; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the bucket. - #[structopt(short, long)] - bucket: String, - - /// The name of the object in the bucket. - #[structopt(short, long)] - key: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your buckets and uploads a file to a bucket. -/// # Arguments -/// -/// * `-b BUCKET` - The bucket to which the file is uploaded. -/// * `-k KEY` - The name of the file to upload to the bucket. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - bucket, - region, - key, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("S3 client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!("Bucket: {}", &bucket); - println!("Key: {}", &key); - println!(); - } - - let resp = client.list_buckets().send().await?; - - for bucket in resp.buckets.unwrap_or_default() { - println!("bucket: {:?}", bucket.name.as_deref().unwrap_or_default()) - } - - let body = ByteStream::from_path(Path::new("Cargo.toml")).await; - - match body { - Ok(b) => { - let resp = client - .put_object() - .bucket(&bucket) - .key(&key) - .body(b) - .send() - .await?; - - println!("Upload success. Version: {:?}", resp.version_id); - - let resp = client.get_object().bucket(bucket).key(key).send().await?; - let data = resp.body.collect().await; - println!("data: {:?}", data.unwrap().into_bytes()); - } - Err(e) => { - println!("Got an error DOING SOMETHING:"); - println!("{}", e); - process::exit(1); - } - } - - Ok(()) -} diff --git a/aws/sdk/examples/s3/src/bin/select-object-content.rs b/aws/sdk/examples/s3/src/bin/select-object-content.rs deleted file mode 100644 index b818f01730..0000000000 --- a/aws/sdk/examples/s3/src/bin/select-object-content.rs +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_s3::model::{ - CompressionType, CsvInput, CsvOutput, ExpressionType, FileHeaderInfo, InputSerialization, - OutputSerialization, SelectObjectContentEventStream, -}; -use aws_sdk_s3::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The bucket name to select from. - #[structopt(short, long)] - bucket: String, - - /// The object key to scan. This example expects the object to be an uncompressed CSV file with: - /// ```csv - /// Name,PhoneNumber,City,Occupation - /// Sam,(949) 555-6701,Irvine,Solutions Architect - /// Vinod,(949) 555-6702,Los Angeles,Solutions Architect - /// Jeff,(949) 555-6703,Seattle,AWS Evangelist - /// Jane,(949) 555-6704,Chicago,Developer - /// Sean,(949) 555-6705,Chicago,Developer - /// Mary,(949) 555-6706,Chicago,Developer - /// Kate,(949) 555-6707,Chicago,Developer - /// ``` - #[structopt(short, long)] - object: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - bucket, - object, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-east-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("S3 client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!(); - } - - let mut output = client - .select_object_content() - .bucket(bucket) - .key(object) - .expression_type(ExpressionType::Sql) - .expression("SELECT * FROM s3object s WHERE s.\"Name\" = 'Jane'") - .input_serialization( - InputSerialization::builder() - .csv( - CsvInput::builder() - .file_header_info(FileHeaderInfo::Use) - .build(), - ) - .compression_type(CompressionType::None) - .build(), - ) - .output_serialization( - OutputSerialization::builder() - .csv(CsvOutput::builder().build()) - .build(), - ) - .send() - .await?; - - while let Some(event) = output.payload.recv().await? { - match event { - SelectObjectContentEventStream::Records(records) => { - println!( - "Record: {}", - records - .payload() - .map(|p| std::str::from_utf8(p.as_ref()).unwrap()) - .unwrap_or("") - ); - } - SelectObjectContentEventStream::Stats(stats) => { - println!("Stats: {:?}", stats.details().unwrap()); - } - SelectObjectContentEventStream::Progress(progress) => { - println!("Progress: {:?}", progress.details().unwrap()); - } - SelectObjectContentEventStream::Cont(_) => { - println!("Continuation Event"); - } - SelectObjectContentEventStream::End(_) => { - println!("End Event"); - } - otherwise => panic!("Unknown event type: {:?}", otherwise), - } - } - - Ok(()) -} diff --git a/aws/sdk/examples/sagemaker/Cargo.toml b/aws/sdk/examples/sagemaker/Cargo.toml deleted file mode 100644 index 10ff411d56..0000000000 --- a/aws/sdk/examples/sagemaker/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "sagemaker-code-examples" -version = "0.1.0" -authors = ["Alistair McLean ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-sagemaker = { path = "../../build/aws-sdk/sdk/sagemaker" } -aws-smithy-types-convert = { path = "../../build/aws-sdk/sdk/aws-smithy-types-convert", features = ["convert-chrono"] } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -env_logger = "0.8.2" -chrono = "0.4.19" -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/sagemaker/src/bin/list-training-jobs.rs b/aws/sdk/examples/sagemaker/src/bin/list-training-jobs.rs deleted file mode 100644 index 618cfbd1eb..0000000000 --- a/aws/sdk/examples/sagemaker/src/bin/list-training-jobs.rs +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_sagemaker as sagemaker; -use aws_smithy_types_convert::date_time::DateTimeExt; -use sagemaker::{Client, Region}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. Overrides environment variable AWS_DEFAULT_REGION. - #[structopt(short, long)] - default_region: Option, - - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the your SageMaker jobs in an AWS Region. -/// /// # 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<(), sagemaker::Error> { - tracing_subscriber::fmt::init(); - - let Opt { - default_region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(default_region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("SageMaker client version: {}", sagemaker::PKG_VERSION); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - println!(); - } - - let job_details = client.list_training_jobs().send().await?; - - println!("Job Name\tCreation DateTime\tDuration\tStatus"); - for j in job_details.training_job_summaries().unwrap_or_default() { - let name = j.training_job_name().unwrap_or_default(); - let creation_time = j.creation_time().unwrap().to_chrono_utc(); - let training_end_time = j.training_end_time().unwrap().to_chrono_utc(); - - let status = j.training_job_status().unwrap(); - let duration = training_end_time - creation_time; - - println!( - "{}\t{}\t{}\t{:#?}", - name, - creation_time.format("%Y-%m-%d@%H:%M:%S"), - duration.num_seconds(), - status - ); - } - - Ok(()) -} diff --git a/aws/sdk/examples/sagemaker/src/bin/sagemaker-helloworld.rs b/aws/sdk/examples/sagemaker/src/bin/sagemaker-helloworld.rs deleted file mode 100644 index b5f65d4dd9..0000000000 --- a/aws/sdk/examples/sagemaker/src/bin/sagemaker-helloworld.rs +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_sagemaker as sagemaker; -use sagemaker::{Client, Region}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The region. Overrides environment variable AWS_DEFAULT_REGION. - #[structopt(short, long)] - default_region: Option, - - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the name, status, and type of your SageMaker instances in an AWS Region. -/// /// # 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<(), sagemaker::Error> { - tracing_subscriber::fmt::init(); - - let Opt { - default_region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(default_region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("SageMaker client version: {}", sagemaker::PKG_VERSION); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - } - - let notebooks = client.list_notebook_instances().send().await?; - - for n in notebooks.notebook_instances().unwrap_or_default() { - let n_instance_type = n.instance_type().unwrap(); - let n_status = n.notebook_instance_status().unwrap(); - let n_name = n.notebook_instance_name().unwrap_or_default(); - - println!( - "Notebook Name : {}, Notebook Status : {:#?}, Notebook Instance Type : {:#?}", - n_name, n_status, n_instance_type - ); - } - - Ok(()) -} diff --git a/aws/sdk/examples/secretsmanager/Cargo.toml b/aws/sdk/examples/secretsmanager/Cargo.toml deleted file mode 100644 index 3cb5e008d5..0000000000 --- a/aws/sdk/examples/secretsmanager/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "secretsmanager-code-examples" -version = "0.1.0" -authors = ["AWS Rust SDK Team ", "Doug Schwartz "] -edition = "2018" -description = "Example usage of the SecretManager service" - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-secretsmanager = { path = "../../build/aws-sdk/sdk/secretsmanager" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } - -tokio = { version = "1", features = ["full"]} - -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/secretsmanager/src/bin/create-secret.rs b/aws/sdk/examples/secretsmanager/src/bin/create-secret.rs deleted file mode 100644 index 178b1be22b..0000000000 --- a/aws/sdk/examples/secretsmanager/src/bin/create-secret.rs +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_secretsmanager::{Client, Region}; -use structopt::StructOpt; -use tracing_subscriber::fmt::format::FmtSpan; -use tracing_subscriber::fmt::SubscriberBuilder; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The region - #[structopt(short, long)] - region: Option, - - /// The name of the secret - #[structopt(short, long)] - name: String, - - /// The value of the secret - #[structopt(short, long)] - secret_value: String, - - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Creates a secret. -/// # Arguments -/// -/// * `-n NAME` - The name of the secret. -/// * `-s SECRET_VALUE` - The secret value. -/// * `[-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() { - let Opt { - name, - region, - secret_value, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!( - "SecretsManager client version: {}\n", - aws_sdk_secretsmanager::PKG_VERSION - ); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Secret name: {}", name); - println!("Secret value: {}", secret_value); - - SubscriberBuilder::default() - .with_env_filter("info") - .with_span_events(FmtSpan::CLOSE) - .init(); - } - - match client - .create_secret() - .name(name) - .secret_string(secret_value) - .send() - .await - { - Ok(_) => println!("Created secret"), - Err(e) => panic!("Failed to create secret: {}", e), - }; -} diff --git a/aws/sdk/examples/secretsmanager/src/bin/get-secret-value.rs b/aws/sdk/examples/secretsmanager/src/bin/get-secret-value.rs deleted file mode 100644 index a8c7367136..0000000000 --- a/aws/sdk/examples/secretsmanager/src/bin/get-secret-value.rs +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_secretsmanager::{Client, Region}; -use std::process; -use structopt::StructOpt; -use tracing_subscriber::fmt::format::FmtSpan; -use tracing_subscriber::fmt::SubscriberBuilder; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The region - #[structopt(short, long)] - region: Option, - - /// The name of the secret - #[structopt(short, long)] - name: String, - - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Retrieves the value of a secret. -/// # Arguments -/// -/// * `-n NAME` - The name of the secret. -/// * `-s SECRET_VALUE` - The secret value. -/// * `[-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() { - let Opt { - name, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!( - "SecretsManager client version: {}\n", - aws_sdk_secretsmanager::PKG_VERSION - ); - println!("Region: {:?}", shared_config.region()); - println!("Secret name: {}", name); - - SubscriberBuilder::default() - .with_env_filter("info") - .with_span_events(FmtSpan::CLOSE) - .init(); - } - - let client = Client::new(&shared_config); - - match client.get_secret_value().secret_id(name).send().await { - Ok(resp) => { - println!( - "Value: {}", - resp.secret_string.as_deref().unwrap_or("No value!") - ); - } - Err(e) => { - println!("Got an error while getting a secret value: {}", e); - process::exit(1); - } - }; -} diff --git a/aws/sdk/examples/secretsmanager/src/bin/list-secrets.rs b/aws/sdk/examples/secretsmanager/src/bin/list-secrets.rs deleted file mode 100644 index ba3a4348d3..0000000000 --- a/aws/sdk/examples/secretsmanager/src/bin/list-secrets.rs +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_secretsmanager::{Client, Region}; -use std::process; -use structopt::StructOpt; -use tracing_subscriber::fmt::format::FmtSpan; -use tracing_subscriber::fmt::SubscriberBuilder; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The region - #[structopt(short, long)] - region: Option, - - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the names of your secrets. -/// # 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() { - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let _client = Client::new(&shared_config); - - if verbose { - println!( - "SecretsManager client version: {}", - aws_sdk_secretsmanager::PKG_VERSION - ); - println!("Region: {:?}", shared_config.region().unwrap()); - - SubscriberBuilder::default() - .with_env_filter("info") - .with_span_events(FmtSpan::CLOSE) - .init(); - } - - let client = Client::new(&shared_config); - - match client.list_secrets().send().await { - Ok(resp) => { - println!("Secret names:"); - - let secrets = resp.secret_list.unwrap_or_default(); - for secret in &secrets { - println!(" {}", secret.name.as_deref().unwrap_or("No name!")); - } - - println!("Found {} secrets", secrets.len()); - } - Err(e) => { - println!("Got an error listing secrets:"); - println!("{}", e); - process::exit(1); - } - }; -} diff --git a/aws/sdk/examples/ses/Cargo.toml b/aws/sdk/examples/ses/Cargo.toml deleted file mode 100644 index 7411f13919..0000000000 --- a/aws/sdk/examples/ses/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "ses-code-examples" -version = "0.1.0" -authors = ["Russell Cohen ", "Doug Schwartz "] -edition = "2018" - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-sesv2 = { path = "../../build/aws-sdk/sdk/sesv2" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } - -tokio = { version = "1", features = ["full"] } - -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/ses/src/bin/create-contact-list.rs b/aws/sdk/examples/ses/src/bin/create-contact-list.rs deleted file mode 100644 index 7abe91b79c..0000000000 --- a/aws/sdk/examples/ses/src/bin/create-contact-list.rs +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_sesv2::{Client, Error, Region}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The name of the contact list. - #[structopt(short, long)] - contact_list: String, - - /// The AWS Region. - #[structopt(short, long)] - default_region: Option, - - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Creates a new contact list. -/// # Arguments -/// -/// * `-c CONTACT-LIST` - The name of the contact list. -/// * `[-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 { - contact_list, - default_region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(default_region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!("SES client version: {}", aws_sdk_sesv2::PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Contact list: {}", &contact_list); - println!(); - } - - let client = Client::new(&shared_config); - - let resp = client - .create_contact_list() - .contact_list_name(contact_list) - .send() - .await; - - match resp { - Ok(_) => println!("Created contact list."), - Err(e) => eprintln!("Got an error attempting to create contact list: {}", e), - }; - - Ok(()) -} diff --git a/aws/sdk/examples/ses/src/bin/create-contact.rs b/aws/sdk/examples/ses/src/bin/create-contact.rs deleted file mode 100644 index 520ad6eb6b..0000000000 --- a/aws/sdk/examples/ses/src/bin/create-contact.rs +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_sesv2::{Client, Error, Region}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The name of the contact list. - #[structopt(short, long)] - contact_list: String, - - /// The AWS Region. - #[structopt(short, long)] - default_region: Option, - - /// The email address of the contact to add to the contact list. - #[structopt(short, long)] - email_address: String, - - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Adds a new contact to the contact list. -/// # Arguments -/// -/// * `-c CONTACT-LIST` - The name of the contact list. -/// * `-e EMAIL-ADDRESS` - The email address of the contact to add to the contact list. -/// * `[-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 { - contact_list, - default_region, - email_address, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(default_region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!("SES client version: {}", aws_sdk_sesv2::PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Contact list: {}", &contact_list); - println!("Email address: {}", &email_address); - println!(); - } - - let client = Client::new(&shared_config); - - let new_contact = client - .create_contact() - .contact_list_name(contact_list) - .email_address(email_address) - .send() - .await; - match new_contact { - Ok(_) => println!("Created contact"), - Err(e) => eprintln!("Got error attempting to create contact: {}", e), - }; - - Ok(()) -} diff --git a/aws/sdk/examples/ses/src/bin/email-contact-list.rs b/aws/sdk/examples/ses/src/bin/email-contact-list.rs deleted file mode 100644 index 558c5b99b7..0000000000 --- a/aws/sdk/examples/ses/src/bin/email-contact-list.rs +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_sesv2::model::{Body, Content, Destination, EmailContent, Message}; -use aws_sdk_sesv2::{Client, Error, Region}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The contact list containing email addresses to send the message to. - #[structopt(short, long)] - contact_list: String, - - /// The AWS Region. - #[structopt(short, long)] - default_region: Option, - - /// The email address of the sender. - #[structopt(short, long)] - from_address: String, - - /// The message of the email. - #[structopt(short, long)] - message: String, - - /// The subject of the email. - #[structopt(short, long)] - subject: String, - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Sends a message to the email addresses in the contact list. -/// # Arguments -/// -/// * `-f FROM-ADDRESS` - The email address of the sender. -/// * `-m MESSAGE` - The email message that is sent. -/// * `-s SUBJECT` - The subject of the email message. -/// * `-c CONTACT-LIST` - The contact list with the email addresses of the recepients. -/// * `[-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 { - contact_list, - default_region, - from_address, - message, - subject, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(default_region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!("SES client version: {}", aws_sdk_sesv2::PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("From address: {}", &from_address); - println!("Contact list: {}", &contact_list); - println!("Subject: {}", &subject); - println!("Message: {}", &message); - println!(); - } - - let client = Client::new(&shared_config); - - // Get list of email addresses from contact list. - let resp = client - .list_contacts() - .contact_list_name(contact_list) - .send() - .await; - - let contacts = resp.unwrap().contacts.unwrap_or_default(); - - let cs: String = contacts - .into_iter() - .map(|i| i.email_address.unwrap_or_default()) - .collect(); - - let dest = Destination::builder().to_addresses(cs).build(); - let subject_content = Content::builder().data(subject).charset("UTF-8").build(); - let body_content = Content::builder().data(message).charset("UTF-8").build(); - let body = Body::builder().text(body_content).build(); - - let msg = Message::builder() - .subject(subject_content) - .body(body) - .build(); - - let email_content = EmailContent::builder().simple(msg).build(); - - match client - .send_email() - .from_email_address(from_address) - .destination(dest) - .content(email_content) - .send() - .await - { - Ok(_) => {} - Err(e) => { - println!("Got an error sending email: {}", e); - } - } - - Ok(()) -} diff --git a/aws/sdk/examples/ses/src/bin/list-contact-lists.rs b/aws/sdk/examples/ses/src/bin/list-contact-lists.rs deleted file mode 100644 index e6652bc9fe..0000000000 --- a/aws/sdk/examples/ses/src/bin/list-contact-lists.rs +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_sesv2::{Client, Error, Region}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - default_region: Option, - - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your contact lists (there should only be one). -/// # 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_provider = RegionProviderChain::first_try(default_region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!("SES client version: {}", aws_sdk_sesv2::PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!(); - } - - let client = Client::new(&shared_config); - - let resp = client.list_contact_lists().send().await; - - for list in resp.unwrap().contact_lists.unwrap_or_default() { - println!("{}", list.contact_list_name.as_deref().unwrap_or_default()); - } - - Ok(()) -} diff --git a/aws/sdk/examples/ses/src/bin/list-contacts.rs b/aws/sdk/examples/ses/src/bin/list-contacts.rs deleted file mode 100644 index fd246dbec5..0000000000 --- a/aws/sdk/examples/ses/src/bin/list-contacts.rs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_sesv2::{Client, Error, Region}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The name of the contact list. - #[structopt(short, long)] - contact_list: String, - - /// The AWS Region. - #[structopt(short, long)] - default_region: Option, - - /// Whether to display additional runtime information - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the contacts in a contact list. -/// # Arguments -/// -/// * `-c CONTACT-LIST` - The name of the contact list. -/// * `[-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 { - contact_list, - default_region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(default_region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!("SES client version: {}", aws_sdk_sesv2::PKG_VERSION); - println!("Region: {:?}", shared_config.region().unwrap()); - println!("Contact list: {}", &contact_list); - println!(); - } - - let client = Client::new(&shared_config); - - let resp = client - .list_contacts() - .contact_list_name(contact_list) - .send() - .await; - - for contact in resp.unwrap().contacts.unwrap_or_default() { - println!("{}", contact.email_address.as_deref().unwrap_or_default()); - } - - Ok(()) -} diff --git a/aws/sdk/examples/setting_timeouts/Cargo.toml b/aws/sdk/examples/setting_timeouts/Cargo.toml deleted file mode 100644 index a9f553caf4..0000000000 --- a/aws/sdk/examples/setting_timeouts/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "setting_timeouts" -version = "0.1.0" -authors = ["Zelda Hessler zhessler@amazon.com>"] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-s3 = { package = "aws-sdk-s3", path = "../../build/aws-sdk/sdk/s3" } -aws-smithy-client = { path = "../../build/aws-sdk/sdk/aws-smithy-client", features = ["rustls"] } -tokio = { version = "1", features = ["full"] } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/setting_timeouts/src/main.rs b/aws/sdk/examples/setting_timeouts/src/main.rs deleted file mode 100644 index 988c9519d1..0000000000 --- a/aws/sdk/examples/setting_timeouts/src/main.rs +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::TimeoutConfig; -use aws_smithy_client::{conns, erase::DynConnector, hyper_ext, timeout}; -use std::time::Duration; - -/// The SDK divides timeouts into two groups: -/// -/// - Timeouts that occur at the client level _(outside of a `Connector`)_, hereafter referred to -/// as "first group" timeouts -/// - Timeouts that occur at the connector level _(inside a `Connector`)_, hereafter referred to -/// as "second group" timeouts -/// -/// In the future, all timeouts will be set in the same way. In the present, these two groups of -/// timeouts must be set separately. This app provides an example of how to set both groups of -/// timeouts. -/// -/// **TLS negotiation timeouts will eventually be included with the second group but are -/// not yet supported** -/// -/// The timeouts in this example are set to one second which may or may not be fast enough to -/// trigger them based on your connection speeds. If you want to ensure a timeout gets triggered -/// so you can see what the resulting error looks like, change the durations from -/// `Duration::from_secs(2)` to `Duration::from_millis(2)`. -/// -/// You could _also_ trigger the timeouts by replacing the HTTPS connector _(`conns::https()`)_ -/// with a `NeverConnector`. That's how we manually trigger timeouts when writing tests. -#[tokio::main] -async fn main() -> Result<(), aws_sdk_s3::Error> { - tracing_subscriber::fmt::init(); - - // Here we set our "first group" timeouts - let request_timeout_config = TimeoutConfig::new() - // This timeout acts at the "Request to a service" level. When the SDK makes a request to a - // service, that "request" may actually comprise of several HTTP requests in order to retry - // failures that are likely spurious or to refresh credentials. - .with_api_call_timeout(Some(Duration::from_secs(2))) - // This timeout acts at the "HTTP request" level and will set a separate timeout for each - // HTTP request made as part of a "service request" - .with_api_call_attempt_timeout(Some(Duration::from_secs(2))); - - // Timeouts can also be defined in your environment or AWS profile but in this example we - // overrule any that happen to be set - let shared_config = aws_config::from_env() - .timeout_config(request_timeout_config) - .load() - .await; - - // Here we set our "second group" timeouts - let http_timeout_config = timeout::Settings::new() - // A limit on the amount of time an application takes to attempt to read the first byte over - // an established, open connection after write request. - // Also known as the "time to first byte" timeout - .with_read_timeout(Duration::from_secs(2)) - // A limit on the amount of time after making an initial connect attempt on a socket to - // complete the connect-handshake - .with_connect_timeout(Duration::from_secs(2)); - - // These timeouts must be passed to create the `Connector` that will handle our HTTP requests. - // If a timeout needs to be changed after this, we'd have to create a new `Connector`. - let conn = DynConnector::new( - hyper_ext::Adapter::builder() - .timeout(&http_timeout_config) - .build(conns::https()), - ); - let s3_config = aws_sdk_s3::Config::from(&shared_config); - let client = aws_sdk_s3::Client::from_conf_conn(s3_config, conn); - - let resp = client.list_buckets().send().await?; - - for bucket in resp.buckets().unwrap_or_default() { - println!("bucket: {:?}", bucket.name().unwrap_or_default()) - } - - Ok(()) -} diff --git a/aws/sdk/examples/snowball/Cargo.toml b/aws/sdk/examples/snowball/Cargo.toml deleted file mode 100644 index d018e4d5df..0000000000 --- a/aws/sdk/examples/snowball/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "snowball-code-examples" -version = "0.1.0" -authors = ["Landon James ", "Doug Schwartz , - - // Address information. - #[structopt(long)] - city: String, - - #[structopt(long)] - company: Option, - - #[structopt(long)] - country: String, - - #[structopt(long)] - landmark: Option, - - #[structopt(long)] - name: String, - - #[structopt(long)] - phone_number: String, - - #[structopt(long)] - postal_code: String, - - #[structopt(long)] - prefecture_or_district: Option, - - #[structopt(long)] - state: String, - - #[structopt(long)] - street1: String, - - #[structopt(long)] - street2: Option, - - #[structopt(long)] - street3: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Creates an AWS Snowball address. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_REGION** environment variable. -/// If the environment variable is not set, defaults to **us-west-2**. -/// * `--city CITY` - The required city portion of the address. -/// * `[--company COMPANY]` - The company portion of the address. -/// * `--country COUNTRY` - The required country portion of the address. -/// * `[--landmark LANDMARK]` - The landmark portion of the address. -/// * `--name NAME` - The required name portion of the address. -/// * `--phone-number PHONE-NUMBER` - The required phone number portion of the address. -/// * `--postal-code POSTAL-CODE` - The required postal code (zip in USA) portion of the address. -/// * `[--prefecture-or-district PREFECTURE-OR-DISTRICT]` - The prefecture or district portion of the address. -/// * `--state STATE` - The required state portion of the address. It must be (two is best) upper-case letters. -/// * `--street1 STREET1` - The required first street portion of the address. -/// * `[--street2 STREET2]` - The second street portion of the address. -/// * `[--street3 STREET3]` - The third street portion of the address. -/// * `[-v]` - Whether to display additional information. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - city, - company, - country, - landmark, - name, - phone_number, - postal_code, - prefecture_or_district, - state, - street1, - street2, - street3, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("Snowball version: {}", PKG_VERSION); - println!( - "Region: {}", - shared_config.region().unwrap() - ); - println!("City: {}", &city); - println!("Company: {:?}", &company); - println!("Country: {}", &country); - println!("Landmark: {:?}", &landmark); - println!("Name: {}", &name); - println!("Phone number: {}", &phone_number); - println!("Postal code: {}", &postal_code); - println!("Prefecture or district: {:?}", &prefecture_or_district); - println!("State: {}", &state); - println!("Street1: {}", &street1); - println!("Street2: {:?}", &street2); - println!("Street3: {:?}", &street3); - } - - let new_address = Address::builder() - .set_address_id(None) - .name(name) - .set_company(company) - .street1(street1) - .set_street2(street2) - .set_street3(street3) - .city(city) - .state_or_province(state) - .set_prefecture_or_district(prefecture_or_district) - .set_landmark(landmark) - .country(country) - .postal_code(postal_code) - .phone_number(phone_number) - .set_is_restricted(Some(false)) - .build(); - - let client = Client::new(&shared_config); - - let result = client.create_address().address(new_address).send().await?; - - println!(); - println!("Address: {:?}", result.address_id.unwrap()); - - Ok(()) -} diff --git a/aws/sdk/examples/snowball/src/bin/describe-addresses.rs b/aws/sdk/examples/snowball/src/bin/describe-addresses.rs deleted file mode 100644 index 361e778b9c..0000000000 --- a/aws/sdk/examples/snowball/src/bin/describe-addresses.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_snowball::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your AWS Snowball addresses. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("Snowball version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - } - - let client = Client::new(&shared_config); - - let addresses = client.describe_addresses().send().await?; - for address in addresses.addresses.unwrap() { - println!("Address: {:?}", address); - } - - Ok(()) -} diff --git a/aws/sdk/examples/snowball/src/bin/list-jobs.rs b/aws/sdk/examples/snowball/src/bin/list-jobs.rs deleted file mode 100644 index 0f2696f76c..0000000000 --- a/aws/sdk/examples/snowball/src/bin/list-jobs.rs +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_snowball::{Client, Error, Region, PKG_VERSION}; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your AWS Snowball jobs. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - println!(); - - if verbose { - println!("Snowball version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!(); - } - - let client = Client::new(&shared_config); - - println!("Jobs:"); - - let jobs = client.list_jobs().send().await?; - for job in jobs.job_list_entries.unwrap() { - println!(" JobId: {:?}", job.job_id); - } - - Ok(()) -} diff --git a/aws/sdk/examples/sns/Cargo.toml b/aws/sdk/examples/sns/Cargo.toml deleted file mode 100644 index 97bc7b0a54..0000000000 --- a/aws/sdk/examples/sns/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "sns-code-examples" -version = "0.1.0" -authors = ["Russell Cohen ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-sns = { package = "aws-sdk-sns", path = "../../build/aws-sdk/sdk/sns" } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } -tokio = { version = "1", features = ["full"] } -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/sns/src/bin/create-topic.rs b/aws/sdk/examples/sns/src/bin/create-topic.rs deleted file mode 100644 index e47821c49d..0000000000 --- a/aws/sdk/examples/sns/src/bin/create-topic.rs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_sns::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Specifies the topic name. - #[structopt(short, long)] - topic: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Creates an Amazon SNS topic. -/// # Arguments -/// -/// * `-t TOPIC` - The name of the topic. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - topic, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("SNS client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!("Topic: {}", &topic); - println!(); - } - - let resp = client.create_topic().name(topic).send().await?; - - println!( - "Created topic with ARN: {}", - resp.topic_arn.as_deref().unwrap_or_default() - ); - - Ok(()) -} diff --git a/aws/sdk/examples/sns/src/bin/list-topics.rs b/aws/sdk/examples/sns/src/bin/list-topics.rs deleted file mode 100644 index af9a66af7a..0000000000 --- a/aws/sdk/examples/sns/src/bin/list-topics.rs +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_sns::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Lists your Amazon SNS topics in the region. -/// # Arguments -/// -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("SNS client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - - println!(); - } - - let resp = client.list_topics().send().await?; - - println!("Topic ARNs:"); - - for topic in resp.topics.unwrap_or_default() { - println!("{}", topic.topic_arn.as_deref().unwrap_or_default()); - } - Ok(()) -} diff --git a/aws/sdk/examples/sns/src/bin/sns-hello-world.rs b/aws/sdk/examples/sns/src/bin/sns-hello-world.rs deleted file mode 100644 index 7cfd67b441..0000000000 --- a/aws/sdk/examples/sns/src/bin/sns-hello-world.rs +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_sns::{Client, Error, Region, PKG_VERSION}; - -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The email address to subscribe to the topic. - #[structopt(short, long)] - email_address: String, - - /// The ARN of the topic. - #[structopt(short, long)] - topic_arn: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -/// Subscribes an email address and publishes a message to a topic. -/// If the email address has not been confirmed for the topic, -/// a confirmation request is also sent to the email address. -/// # Arguments -/// -/// * `-e EMAIL_ADDRESS` - The email address of a user subscribing to the topic. -/// * `-t TOPIC_ARN` - The ARN of the topic. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - email_address, - topic_arn, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - println!(); - - if verbose { - println!("SNS client version: {}", PKG_VERSION); - println!("Region: {}", shared_config.region().unwrap()); - println!("Email address: {}", &email_address); - println!("Topic ARN: {}", &topic_arn); - println!(); - } - - println!("Receiving on topic with ARN: `{}`", topic_arn); - - let rsp = client - .subscribe() - .topic_arn(&topic_arn) - .protocol("email") - .endpoint(email_address) - .send() - .await?; - - println!("Added a subscription: {:?}", rsp); - - let rsp = client - .publish() - .topic_arn(&topic_arn) - .message("hello sns!") - .send() - .await?; - - println!("Published message: {:?}", rsp); - - Ok(()) -} diff --git a/aws/sdk/examples/sqs/Cargo.toml b/aws/sdk/examples/sqs/Cargo.toml deleted file mode 100644 index 429e8409a8..0000000000 --- a/aws/sdk/examples/sqs/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "sqs-code-examples" -version = "0.1.0" -authors = ["Russell Cohen ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-sqs = { path = "../../build/aws-sdk/sdk/sqs" } -tokio = { version = "1", features = ["full"] } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/sqs/src/bin/sqs-hello-world.rs b/aws/sdk/examples/sqs/src/bin/sqs-hello-world.rs deleted file mode 100644 index 5b891dc253..0000000000 --- a/aws/sdk/examples/sqs/src/bin/sqs-hello-world.rs +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_sdk_sqs::{Client, Error}; -use std::process::exit; - -/// Sends a message to and receives the message from a FIFO queue. -#[tokio::main] -async fn main() -> Result<(), Error> { - tracing_subscriber::fmt::init(); - let shared_config = aws_config::load_from_env().await; - let client = Client::new(&shared_config); - let queues = client.list_queues().send().await?; - let mut queue_urls = queues.queue_urls.unwrap_or_default(); - let queue_url = match queue_urls.pop() { - Some(url) => url, - None => { - eprintln!("No queues in this account. Please create a queue to proceed"); - exit(1); - } - }; - - println!( - "Sending and receiving messages on with URL: `{}`", - queue_url - ); - - let rsp = client - .send_message() - .queue_url(&queue_url) - .message_body("hello from my queue") - // message group id required for FIFO Queue - // comment out ".message_group_id("MyGroup")" for standard queues - .message_group_id("MyGroup") - .send() - .await?; - - println!("Response from sending a message: {:#?}", rsp); - - let rcv_message_output = client - .receive_message() - .queue_url(&queue_url) - .send() - .await?; - - for message in rcv_message_output.messages.unwrap_or_default() { - println!("Got the message: {:#?}", message); - } - - Ok(()) -} diff --git a/aws/sdk/examples/ssm/Cargo.toml b/aws/sdk/examples/ssm/Cargo.toml deleted file mode 100644 index f66110747a..0000000000 --- a/aws/sdk/examples/ssm/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "ssm-code-examples" -version = "0.1.0" -authors = ["John DiSanti ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-ssm = { path = "../../build/aws-sdk/sdk/ssm" } -tokio = { version = "1", features = ["full"] } -aws-types = { path = "../../build/aws-sdk/sdk/aws-types" } - -structopt = { version = "0.3", default-features = false } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/ssm/src/bin/create-parameter.rs b/aws/sdk/examples/ssm/src/bin/create-parameter.rs deleted file mode 100644 index 2ca27f57d8..0000000000 --- a/aws/sdk/examples/ssm/src/bin/create-parameter.rs +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ssm::model::ParameterType; -use aws_sdk_ssm::{Client, Region}; -use std::process; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The region - #[structopt(short, long)] - region: Option, - - /// The parameter name - #[structopt(short, long)] - name: String, - - /// The parameter value - #[structopt(short, long)] - parameter_value: String, - - /// The parameter description - #[structopt(short, long)] - description: String, - - /// Whether to display additional information - #[structopt(short, long)] - verbose: bool, -} - -/// Creates a new AWS Systems Manager parameter. -/// # Arguments -/// -/// * `-n NAME` - The name of the parameter. -/// * `-p PARAMETER_VALUE` - The value of the parameter. -/// * `-d DESCRIPTION` - The description of the parameter. -/// * `[-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() { - let Opt { - name, - parameter_value, - description, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!("SSM client version: {}", aws_sdk_ssm::PKG_VERSION); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - println!("Parameter name: {}", name); - println!("Parameter value: {}", parameter_value); - println!("Parameter description: {}", description); - - tracing_subscriber::fmt::init(); - } - - let client = Client::new(&shared_config); - - match client - .put_parameter() - .overwrite(true) - .r#type(ParameterType::String) - .name(name) - .value(parameter_value) - .description(description) - .send() - .await - { - Ok(response) => { - println!("Success! Parameter now has version: {}", response.version) - } - Err(error) => { - println!("Got an error putting the parameter: {}", error); - process::exit(1); - } - } -} diff --git a/aws/sdk/examples/ssm/src/bin/describe-parameters.rs b/aws/sdk/examples/ssm/src/bin/describe-parameters.rs deleted file mode 100644 index a84026e7f3..0000000000 --- a/aws/sdk/examples/ssm/src/bin/describe-parameters.rs +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ssm::{Client, Region}; -use std::process; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The region - #[structopt(short, long)] - region: Option, - - /// Whether to display additional information - #[structopt(short, long)] - verbose: bool, -} - -/// Lists the names of your AWS Systems Manager parameters. -/// # 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() { - let Opt { region, verbose } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - - if verbose { - println!("SSM client version: {}", aws_sdk_ssm::PKG_VERSION); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - - tracing_subscriber::fmt::init(); - } - - let client = Client::new(&shared_config); - - println!("Parameter names:"); - - match client.describe_parameters().send().await { - Ok(response) => { - for param in response.parameters.unwrap().iter() { - match ¶m.name { - None => {} - Some(n) => { - println!(" {}", n); - } - } - } - } - Err(error) => { - println!("Got an error listing the parameter names: {}", error); - process::exit(1); - } - } - - println!(); -} diff --git a/aws/sdk/examples/ssm/src/bin/ssm-helloworld.rs b/aws/sdk/examples/ssm/src/bin/ssm-helloworld.rs deleted file mode 100644 index 493e8ac977..0000000000 --- a/aws/sdk/examples/ssm/src/bin/ssm-helloworld.rs +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_ssm::model::ParameterType; -use aws_sdk_ssm::{Client, Region}; -use std::process; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The region - #[structopt(short, long)] - region: Option, - - /// The parameter name - #[structopt(short, long)] - name: String, - - /// The parameter value - #[structopt(short, long)] - parameter_value: String, - - /// The parameter description - #[structopt(short, long)] - description: String, - - /// Whether to display additional information - #[structopt(short, long)] - verbose: bool, -} - -/// Creates a new AWS Systems Manager parameter. -/// # Arguments -/// -/// * `-n NAME` - The name of the parameter. -/// * `-p PARAMETER_VALUE` - The value of the parameter. -/// * `-d DESCRIPTION` - The description of the parameter. -/// * `[-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() { - let Opt { - name, - parameter_value, - description, - region, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - if verbose { - println!("SSM client version: {}", aws_sdk_ssm::PKG_VERSION); - println!( - "Region: {:?}", - shared_config.region().unwrap() - ); - println!("Parameter name: {}", name); - println!("Paramter value: {}", parameter_value); - println!("Paramter description: {}", description); - - tracing_subscriber::fmt::init(); - } - - match client - .put_parameter() - .overwrite(true) - .r#type(ParameterType::String) - .name(name) - .value(parameter_value) - .description(description) - .send() - .await - { - Ok(response) => { - println!("Success! Parameter now has version: {}", response.version) - } - Err(error) => { - println!("Got an error putting the parameter: {}", error); - process::exit(1); - } - } -} diff --git a/aws/sdk/examples/transcribestreaming/Cargo.toml b/aws/sdk/examples/transcribestreaming/Cargo.toml deleted file mode 100644 index bae494afde..0000000000 --- a/aws/sdk/examples/transcribestreaming/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "transcribestreaming_code_example" -version = "0.1.0" -authors = ["John DiSanti ", "Doug Schwartz "] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -aws-config = { path = "../../build/aws-sdk/sdk/aws-config" } -aws-sdk-transcribestreaming = { package = "aws-sdk-transcribestreaming", path = "../../build/aws-sdk/sdk/transcribestreaming"} -async-stream = "0.3" -bytes = "1" -hound = "3.4" -structopt = { version = "0.3", default-features = false } -tokio = { version = "1", features = ["full"] } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/transcribestreaming/README.md b/aws/sdk/examples/transcribestreaming/README.md deleted file mode 100644 index 9294a26b20..0000000000 --- a/aws/sdk/examples/transcribestreaming/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# AWS SDK for Rust code examples for Amazon Transcribe - -Amazon Transcribe provides transcription services for audio files. - -## Purpose - -This example demonstrate how to perform an Amazon Transcribe operation using the alpha version of the AWS SDK for Rust. - -## Prerequisites - -You must have an AWS account, and have configured your default credentials and AWS Region as described in [https://github.com/awslabs/aws-sdk-rust](https://github.com/awslabs/aws-sdk-rust). - -## Running the code - -### transcribestreaming - -This example displays a transcription of a WAV audio file. - -` cargo run -- -a AUDIO-FILE [-r REGION] [-v]` - -- _AUDIO-FILE_ is the name of the audio file to transcribe. It must be in WAV format; the example converts the WAV file content to __pcm__ format for Amazon Transcribe. - Note that Amazon Transcribe supports encoding in __pcm__, __ogg-opus__, and __flac__ formats. -- _REGION_ is the Region in which the client is created. - If not supplied, uses the value of the __AWS_REGION__ environment variable. - If the environment variable is not set, defaults to __us-west-2__. -- __-v__ displays additional information. - -If you run it with the WAV file in __audio/hello-transcribe-8000.wav__, you should see the following transcribed text: - -``` -Good day to you transcribe. -This is Polly talking to you from the Rust ST K. -``` - -### Notes - -- We recommend that you grant this code least privilege, - or at most the minimum permissions required to perform the task. - For more information, see - [Grant Least Privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege) - in the AWS Identity and Access Management User Guide. -- This code has not been tested in all AWS Regions. - Some AWS services are available only in specific - [Regions](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services). -- Running this code might result in charges to your AWS account. - -Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0 diff --git a/aws/sdk/examples/transcribestreaming/audio/hello-transcribe-8000.wav b/aws/sdk/examples/transcribestreaming/audio/hello-transcribe-8000.wav deleted file mode 100644 index 3df88f806a..0000000000 Binary files a/aws/sdk/examples/transcribestreaming/audio/hello-transcribe-8000.wav and /dev/null differ diff --git a/aws/sdk/examples/transcribestreaming/src/main.rs b/aws/sdk/examples/transcribestreaming/src/main.rs deleted file mode 100644 index e38dce29a4..0000000000 --- a/aws/sdk/examples/transcribestreaming/src/main.rs +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -use async_stream::stream; -use aws_config::meta::region::RegionProviderChain; -use aws_sdk_transcribestreaming::model::{ - AudioEvent, AudioStream, LanguageCode, MediaEncoding, TranscriptResultStream, -}; -use aws_sdk_transcribestreaming::{Blob, Client, Error, Region, PKG_VERSION}; -use bytes::BufMut; -use std::time::Duration; -use structopt::StructOpt; - -#[derive(Debug, StructOpt)] -struct Opt { - /// The AWS Region. - #[structopt(short, long)] - region: Option, - - /// The name of the audio file. - #[structopt(short, long)] - audio_file: String, - - /// Whether to display additional information. - #[structopt(short, long)] - verbose: bool, -} - -const CHUNK_SIZE: usize = 8192; - -/// Transcribes an audio file to text. -/// # Arguments -/// -/// * `-a AUDIO_FILE` - The name of the audio file. -/// It must be a WAV file, which is converted to __pcm__ format for Amazon Transcribe. -/// Amazon transcribe also supports __ogg-opus__ and __flac__ formats. -/// * `[-r REGION]` - The Region in which the client is created. -/// If not supplied, uses the value of the **AWS_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> { - tracing_subscriber::fmt::init(); - - let Opt { - region, - audio_file, - verbose, - } = Opt::from_args(); - - let region_provider = RegionProviderChain::first_try(region.map(Region::new)) - .or_default_provider() - .or_else(Region::new("us-west-2")); - - println!(); - - if verbose { - println!("Transcribe client version: {}", PKG_VERSION); - println!( - "Region: {}", - region_provider.region().await.unwrap().as_ref() - ); - println!("Audio filename: {}", &audio_file); - println!(); - } - - let shared_config = aws_config::from_env().region(region_provider).load().await; - let client = Client::new(&shared_config); - - let input_stream = stream! { - let pcm = pcm_data(&*audio_file); - for chunk in pcm.chunks(CHUNK_SIZE) { - // Sleeping isn't necessary, but emphasizes the streaming aspect of this - tokio::time::sleep(Duration::from_millis(100)).await; - yield Ok(AudioStream::AudioEvent(AudioEvent::builder().audio_chunk(Blob::new(chunk)).build())); - } - }; - - let mut output = client - .start_stream_transcription() - .language_code(LanguageCode::EnGb) - .media_sample_rate_hertz(8000) - .media_encoding(MediaEncoding::Pcm) - .audio_stream(input_stream.into()) - .send() - .await?; - - let mut full_message = String::new(); - while let Some(event) = output.transcript_result_stream.recv().await? { - match event { - TranscriptResultStream::TranscriptEvent(transcript_event) => { - let transcript = transcript_event.transcript.unwrap(); - for result in transcript.results.unwrap_or_else(|| Vec::new()) { - if result.is_partial { - if verbose { - println!("Partial: {:?}", result); - } - } else { - let first_alternative = &result.alternatives.as_ref().unwrap()[0]; - full_message += first_alternative.transcript.as_ref().unwrap(); - full_message.push('\n'); - } - } - } - otherwise => panic!("received unexpected event type: {:?}", otherwise), - } - } - println!("\nFully transcribed message:\n\n{}", full_message); - - Ok(()) -} - -fn pcm_data(audio_file: &str) -> Vec { - let reader = hound::WavReader::open(audio_file).unwrap(); - let samples_result: hound::Result> = reader.into_samples::().collect(); - - let mut pcm: Vec = Vec::new(); - for sample in samples_result.unwrap() { - pcm.put_i16_le(sample); - } - pcm -} diff --git a/aws/sdk/examples/using_native_tls_instead_of_rustls/Cargo.toml b/aws/sdk/examples/using_native_tls_instead_of_rustls/Cargo.toml deleted file mode 100644 index ba4505bcf0..0000000000 --- a/aws/sdk/examples/using_native_tls_instead_of_rustls/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "using_native_tls_instead_of_rustls" -version = "0.1.0" -authors = ["Zelda Hessler zhessler@amazon.com>"] -edition = "2018" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -# aws-config pulls in rustls and several other things by default. We have to disable defaults in order to use native-tls -# and then manually bring the other defaults back -aws-config = { path = "../../build/aws-sdk/sdk/aws-config", default-features = false, features = ["native-tls", "rt-tokio"] } -# aws-sdk-s3 brings in rustls by default so we disable that in order to use native-tls only -aws-sdk-s3 = { package = "aws-sdk-s3", path = "../../build/aws-sdk/sdk/s3", default-features = false, features = ["native-tls"] } -# aws-sdk-sts is the same as aws-sdk-s3 -aws-sdk-sts = { package = "aws-sdk-sts", path = "../../build/aws-sdk/sdk/sts", default-features = false, features = ["native-tls"] } -tokio = { version = "1", features = ["full"] } -tracing-subscriber = { version = "0.3.5", features = ["env-filter"] } diff --git a/aws/sdk/examples/using_native_tls_instead_of_rustls/additional-ci b/aws/sdk/examples/using_native_tls_instead_of_rustls/additional-ci deleted file mode 100644 index a9bf588e2f..0000000000 --- a/aws/sdk/examples/using_native_tls_instead_of_rustls/additional-ci +++ /dev/null @@ -1 +0,0 @@ -#!/bin/bash diff --git a/aws/sdk/examples/using_native_tls_instead_of_rustls/src/main.rs b/aws/sdk/examples/using_native_tls_instead_of_rustls/src/main.rs deleted file mode 100644 index bb99a1b5db..0000000000 --- a/aws/sdk/examples/using_native_tls_instead_of_rustls/src/main.rs +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0. - */ - -/// The SDK defaults to using RusTLS by default but you can also use [`native_tls`](https://github.com/sfackler/rust-native-tls) -/// which will choose a TLS implementation appropriate for your platform. This example looks much like -/// any other. Activating and deactivating `features` in your app's `Cargo.toml` is all that's needed. -#[tokio::main] -async fn main() -> Result<(), aws_sdk_s3::Error> { - tracing_subscriber::fmt::init(); - list_buckets().await -} - -async fn list_buckets() -> Result<(), aws_sdk_s3::Error> { - let shared_config = aws_config::load_from_env().await; - - let s3_config = aws_sdk_s3::Config::from(&shared_config); - let client = aws_sdk_s3::Client::from_conf(s3_config); - - let resp = client.list_buckets().send().await?; - - for bucket in resp.buckets().unwrap_or_default() { - println!("bucket: {:?}", bucket.name().unwrap_or_default()) - } - - Ok(()) -} - -#[cfg(test)] -mod tests { - use crate::list_buckets; - - /// You can run this test to ensure that this example is only using `native-tls` - /// and that nothing is pulling in `rustls` as a dependency - #[test] - #[should_panic = "error: package ID specification `rustls` did not match any packages"] - fn test_rustls_is_not_in_dependency_tree() { - let cargo_location = std::env::var("CARGO").unwrap(); - let cargo_command = std::process::Command::new(&cargo_location) - .arg("tree") - .arg("--invert") - .arg("rustls") - .output() - .expect("failed to run 'cargo tree'"); - - let stderr = String::from_utf8_lossy(&cargo_command.stderr); - - // We expect the call to `cargo tree` to error out. If it did, we panic with the resulting - // message here. In the case that no error message is set, that's bad. - if !stderr.is_empty() { - panic!("{}", stderr); - } - - // Uh oh. We expected an error message but got none, likely because `cargo tree` found - // `rustls` in our dependencies. We'll print out the message we got to see what went wrong. - let stdout = String::from_utf8_lossy(&cargo_command.stdout); - - println!("{}", stdout) - } - - // NOTE: not currently run in CI, separate PR will set up a with-creds CI runner - #[tokio::test] - #[ignore] - async fn needs_creds_native_tls_works() { - list_buckets().await.expect("should succeed") - } -} diff --git a/tools/sdk-versioner/src/main.rs b/tools/sdk-versioner/src/main.rs index 2db20a6b98..533b4d60ac 100644 --- a/tools/sdk-versioner/src/main.rs +++ b/tools/sdk-versioner/src/main.rs @@ -117,13 +117,23 @@ fn update_dependencies(dependencies: &mut Table, opt: &Opt) -> anyhow::Result bool { - name.starts_with(SDK_PREFIX) || name == AWS_CONFIG + is_service_crate(name) || name == AWS_CONFIG || AWS_RUNTIME_CRATES.iter().any(|&k| k == name) } fn is_sdk_or_runtime_crate(name: &str) -> bool { - is_sdk_crate(name) - || name.starts_with(SMITHY_PREFIX) - || AWS_RUNTIME_CRATES.iter().any(|&k| k == name) + is_sdk_crate(name) || name.starts_with(SMITHY_PREFIX) +} + +fn is_service_crate(name: &str) -> bool { + name.starts_with(SDK_PREFIX) +} + +fn crate_path_name(name: &str) -> &str { + if is_service_crate(name) { + &name[SDK_PREFIX.len()..] + } else { + name + } } fn update_dependency_value(crate_name: &str, value: &mut Table, opt: &Opt) { @@ -135,11 +145,7 @@ fn update_dependency_value(crate_name: &str, value: &mut Table, opt: &Opt) { // Set the `path` if one was given if let Some(path) = &opt.sdk_path { - let crate_path = if is_sdk_crate && crate_name != AWS_CONFIG { - path.join(&crate_name[SDK_PREFIX.len()..]) - } else { - path.join(crate_name) - }; + let crate_path = path.join(crate_path_name(crate_name)); value.insert( "path".to_string(), Value::String(