diff --git a/aws/sdk/examples/apigateway/Cargo.toml b/aws/sdk/examples/apigateway/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..35906c338ad4fb928340ec479c78b0efddca8bb5 --- /dev/null +++ b/aws/sdk/examples/apigateway/Cargo.toml @@ -0,0 +1,13 @@ +[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/aws-config" } +aws-sdk-apigateway = { path = "../../build/aws-sdk/apigateway", package = "aws-sdk-apigateway" } +tokio = { version = "1", features = ["full"] } +structopt = { version = "0.3", default-features = false } +tracing-subscriber = "0.2.18" diff --git a/aws/sdk/examples/apigateway/src/bin/get_rest_apis.rs b/aws/sdk/examples/apigateway/src/bin/get_rest_apis.rs new file mode 100644 index 0000000000000000000000000000000000000000..ab5e652835bd6ef2040cef78b923ac878fa0af8c --- /dev/null +++ b/aws/sdk/examples/apigateway/src/bin/get_rest_apis.rs @@ -0,0 +1,70 @@ +/* + * 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 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 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); + + let resp = client.get_rest_apis().send().await?; + + for api in resp.items.unwrap_or_default() { + println!("ID: {}", api.id.as_deref().unwrap_or_default()); + println!("Name: {}", api.name.as_deref().unwrap_or_default()); + println!( + "Description: {}", + api.description.as_deref().unwrap_or_default() + ); + println!( + "Version: {}", + api.version.as_deref().unwrap_or_default() + ); + println!("Created: {}", api.created_date.unwrap().to_chrono()); + println!(); + } + + Ok(()) +}