Unverified Commit 66db8dac authored by Doug's avatar Doug Committed by GitHub
Browse files

Updated Auto Scaling group code examples (#601)

* Updated Auto Scaling group code examples to follow latest code guidelines and proper service naming

* Updated autoscaling code examples

* Updated AutoScaling code examples to use asynchronous Config

* Updated Autoscaling code examples to use alpha 0.0.17 bits

* Added readme file for Autoscaling code examples

* Added info about updated AutoScaling code example to change log
parent ada243be
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ v0.0.18-alpha (September 14th, 2021)
**New This Week**
- :bug: Fixes issue where `Content-Length` header could be duplicated leading to signing failure (aws-sdk-rust#220, smithy-rs#697)

- Updated AutoScaling code examples to use asynchronous config; added readme file; tested on 0.0.17 bits

v0.0.17-alpha (September 2nd, 2021)
===================================

+2 −3
Original line number Diff line number Diff line
@@ -8,8 +8,7 @@ edition = "2018"

[dependencies]
aws-config = { path = "../../build/aws-sdk/aws-config" }
autoscaling = { package = "aws-sdk-autoscaling", path = "../../build/aws-sdk/autoscaling" }
aws-types = { path = "../../build/aws-sdk/aws-types" }
aws-sdk-autoscaling = { path = "../../build/aws-sdk/autoscaling", package = "aws-sdk-autoscaling" }
tokio = { version = "1", features = ["full"] }
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
tracing-subscriber = "0.2.18"
+77 −0
Original line number Diff line number Diff line
# 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
+13 −12
Original line number Diff line number Diff line
@@ -3,13 +3,13 @@
 * SPDX-License-Identifier: Apache-2.0.
 */

use autoscaling::{Client, Error, Region, PKG_VERSION};
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 AutoScaling group.
    /// The name of the Amazon EC2 Auto Scaling group.
    #[structopt(short, long)]
    autoscaling_name: String,

@@ -30,7 +30,7 @@ struct Opt {
/// # Arguments
///
/// * `-a AUTOSCALING-NAME` - The name of the Auto Scaling group.
/// * `-i INSTANCE-ID` - The ID of the Ec2 instance to add to the AutoScaling 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**.
@@ -49,21 +49,22 @@ async fn main() -> Result<(), Error> {
    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!("AutoScaling version:    {}", PKG_VERSION);
        println!("Auto Scaling client version: {}", PKG_VERSION);
        println!(
            "Region:                 {:?}",
            shared_config.region().unwrap()
            "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);

    client
+11 −11
Original line number Diff line number Diff line
@@ -3,13 +3,13 @@
 * SPDX-License-Identifier: Apache-2.0.
 */

use autoscaling::{Client, Error, Region, PKG_VERSION};
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 AutoScaling group.
    /// The name of the Amazon EC2 Auto Scaling group.
    #[structopt(short, long)]
    autoscaling_name: String,

@@ -29,7 +29,7 @@ struct Opt {
/// Updates an Auto Scaling group in the Region to the specified maximum size.
/// # Arguments
///
/// * `- AUTOSCALING-NAME` - The name of the AutoScaling group.
/// * `-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.
@@ -49,21 +49,21 @@ async fn main() -> Result<(), Error> {
    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!("AutoScaling version:    {}", PKG_VERSION);
        println!("Auto Scaling client version: {}", PKG_VERSION);
        println!(
            "Region:                 {:?}",
            shared_config.region().unwrap()
            "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);

    client
Loading