Commit 421e5b1a authored by Doug's avatar Doug Committed by John DiSanti
Browse files

Refactored Application Auto Scaling code example (#739)

* Refactored Application Auto Scaling code example to move operation out of main and into separate function.

* Updated Application Auto Scaling code example to include unit test and readme

* Updated change log with info about latest changes to Application Auto Scaling code example

* Removed unit test from Application Auto Scaling code example.

* Updated Application Auto Scaling code example--edited readme, reset args to separate function.

* Remove `actix-rt` dependency

* Fix typo
parent 170145c5
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -13,7 +13,6 @@ vNext (Month Day, Year)
- :tada: Add presigned request support and example for Polly SynthesizeSpeech (smithy-rs#735, aws-sdk-rust#139)
- :bug: Fix error when receiving `Cont` event from S3 SelectObjectContent (smithy-rs#736)
- :bug: Fix bug in event stream receiver that could cause the last events in the response stream to be lost when using S3 SelectObjectContent (smithy-rs#736)
- Updated Transcribe code example to take an audio file as a command-line option and added readme.
- Updated Auto Scaling code example to move operation from main to separate function; added readme.
- :tada: Add support for 6 new AWS services:
    - Wisdom
+3 −3
Original line number Diff line number Diff line
[package]
name = "applicationautoscaling"
name = "applicationautoscaling-code-examples"
version = "0.1.0"
authors = ["John DiSanti <jdisanti@amazon.com>"]
authors = ["John DiSanti <jdisanti@amazon.com>, Doug Schwartz <dougsch@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/aws-config" }
applicationautoscaling = { package = "aws-sdk-applicationautoscaling", path = "../../build/aws-sdk/applicationautoscaling" }
aws-sdk-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 }
+38 −0
Original line number Diff line number Diff line
# 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
+25 −23
Original line number Diff line number Diff line
@@ -3,23 +3,41 @@
 * SPDX-License-Identifier: Apache-2.0.
 */

use applicationautoscaling::model::ServiceNamespace;
use applicationautoscaling::{Client, Error, Region};
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 region
    /// The AWS Region.
    #[structopt(short, long)]
    region: Option<String>,

    /// Whether to display additional information
    /// Whether to display additional information.
    #[structopt(short, long)]
    verbose: bool,
}

/// Lists your Amazon Cognito identities
// 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.
@@ -38,10 +56,7 @@ async fn main() -> Result<(), Error> {
    let shared_config = aws_config::from_env().region(region_provider).load().await;

    if verbose {
        println!(
            "Application Auto Scaling client version: {}",
            applicationautoscaling::PKG_VERSION
        );
        println!("Application Auto Scaling client version: {}", PKG_VERSION);
        println!(
            "Region:                                  {:?}",
            shared_config.region().unwrap()
@@ -51,18 +66,5 @@ async fn main() -> Result<(), Error> {

    let client = Client::new(&shared_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(())
    show_policies(&client).await
}