From d25be58abd01a57b5addb064d70dba496db35cbb Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Mon, 12 Jul 2021 14:53:46 -0700 Subject: [PATCH] Add Auto Scaling Plans and Application Auto Scaling to Tier-1 (#582) * Add Auto Scaling Plans and Application Auto Scaling to Tier-1 * Apply suggestions from code review --- aws/sdk/build.gradle.kts | 2 + .../applicationautoscaling/Cargo.toml | 14 ++++ .../src/bin/describe-scaling-policies.rs | 68 +++++++++++++++++++ aws/sdk/examples/autoscalingplans/Cargo.toml | 14 ++++ .../src/bin/describe-scaling-plans.rs | 63 +++++++++++++++++ 5 files changed, 161 insertions(+) create mode 100644 aws/sdk/examples/applicationautoscaling/Cargo.toml create mode 100644 aws/sdk/examples/applicationautoscaling/src/bin/describe-scaling-policies.rs create mode 100644 aws/sdk/examples/autoscalingplans/Cargo.toml create mode 100644 aws/sdk/examples/autoscalingplans/src/bin/describe-scaling-plans.rs diff --git a/aws/sdk/build.gradle.kts b/aws/sdk/build.gradle.kts index 3598da840..af581452c 100644 --- a/aws/sdk/build.gradle.kts +++ b/aws/sdk/build.gradle.kts @@ -50,7 +50,9 @@ dependencies { // Tier 1 Services have examples and tests val tier1Services = setOf( "apigateway", + "applicationautoscaling", "autoscaling", + "autoscalingplans", "batch", "cloudformation", "cloudwatch", diff --git a/aws/sdk/examples/applicationautoscaling/Cargo.toml b/aws/sdk/examples/applicationautoscaling/Cargo.toml new file mode 100644 index 000000000..1b56610f0 --- /dev/null +++ b/aws/sdk/examples/applicationautoscaling/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "applicationautoscaling" +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] +applicationautoscaling = { package = "aws-sdk-applicationautoscaling", path = "../../build/aws-sdk/applicationautoscaling" } +aws-types = { path = "../../build/aws-sdk/aws-types" } +tokio = { version = "1", features = ["full"] } +structopt = { version = "0.3", default-features = false } +tracing-subscriber = { version = "0.2.16", features = ["fmt"] } diff --git a/aws/sdk/examples/applicationautoscaling/src/bin/describe-scaling-policies.rs b/aws/sdk/examples/applicationautoscaling/src/bin/describe-scaling-policies.rs new file mode 100644 index 000000000..92968a397 --- /dev/null +++ b/aws/sdk/examples/applicationautoscaling/src/bin/describe-scaling-policies.rs @@ -0,0 +1,68 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +use applicationautoscaling::model::ServiceNamespace; +use applicationautoscaling::{Client, Config, Error, Region}; +use aws_types::region::{self, ProvideRegion}; +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 = region::ChainProvider::first_try(region.map(Region::new)) + .or_default_provider() + .or_else(Region::new("us-west-2")); + + if verbose { + println!( + "Application Auto Scaling client version: {}", + applicationautoscaling::PKG_VERSION + ); + println!( + "Region: {:?}", + region_provider.region() + ); + println!(); + } + + let config = Config::builder().region(region_provider).build(); + let client = Client::from_conf(config); + + 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(()) +} diff --git a/aws/sdk/examples/autoscalingplans/Cargo.toml b/aws/sdk/examples/autoscalingplans/Cargo.toml new file mode 100644 index 000000000..a7644f15d --- /dev/null +++ b/aws/sdk/examples/autoscalingplans/Cargo.toml @@ -0,0 +1,14 @@ +[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] +autoscalingplans = { package = "aws-sdk-autoscalingplans", path = "../../build/aws-sdk/autoscalingplans" } +aws-types = { path = "../../build/aws-sdk/aws-types" } +tokio = { version = "1", features = ["full"] } +structopt = { version = "0.3", default-features = false } +tracing-subscriber = "0.2.18" diff --git a/aws/sdk/examples/autoscalingplans/src/bin/describe-scaling-plans.rs b/aws/sdk/examples/autoscalingplans/src/bin/describe-scaling-plans.rs new file mode 100644 index 000000000..baaef4f01 --- /dev/null +++ b/aws/sdk/examples/autoscalingplans/src/bin/describe-scaling-plans.rs @@ -0,0 +1,63 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +use autoscalingplans::{Client, Config, Error, Region}; +use aws_types::region::{self, ProvideRegion}; +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 = region::ChainProvider::first_try(region.map(Region::new)) + .or_default_provider() + .or_else(Region::new("us-west-2")); + + if verbose { + println!( + "Auto Scaling Plans client version: {}", + autoscalingplans::PKG_VERSION + ); + println!( + "Region: {:?}", + region_provider.region() + ); + println!(); + } + + let config = Config::builder().region(region_provider).build(); + let client = Client::from_conf(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(()) +} -- GitLab