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

Updated Snowball code examples to use -v (verbose) option. (#585)



* Updated Snowball code examples to use -v (verbose) option.

* Updated Snowball code examples based on feedback

Co-authored-by: default avatarRussell Cohen <rcoh@amazon.com>
parent 346cdfe9
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
[package]
name = "snowball-code-examples"
version = "0.1.0"
authors = ["Landon James <lnj@amazon.com>"]
authors = ["Landon James <lnj@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]
tokio = { version = "1", features = ["full"]}
aws-sdk-snowball = { path = "../../build/aws-sdk/snowball" }
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"] }
tracing-subscriber = "0.2.18"
 No newline at end of file
+67 −20
Original line number Diff line number Diff line
@@ -4,56 +4,79 @@
 */

use aws_sdk_snowball::model::Address;
use aws_sdk_snowball::{Config, Region};
use aws_types::region;
use aws_sdk_snowball::{Client, Config, Error, Region, PKG_VERSION};
use aws_types::region::{self, ProvideRegion};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct Opt {
    /// The default region
    /// The AWS Region.
    #[structopt(short, long)]
    region: Option<String>,

    // Address information
    // Address information.
    #[structopt(long)]
    city: Option<String>,
    city: String,

    #[structopt(long)]
    company: Option<String>,

    #[structopt(long)]
    country: Option<String>,
    country: String,

    #[structopt(long)]
    landmark: Option<String>,

    #[structopt(long)]
    name: Option<String>,
    name: String,

    #[structopt(long)]
    phone_number: Option<String>,
    phone_number: String,

    #[structopt(long)]
    postal_code: Option<String>,
    postal_code: String,

    #[structopt(long)]
    prefecture_or_district: Option<String>,

    #[structopt(long)]
    state: Option<String>,
    state: String,

    #[structopt(long)]
    street1: Option<String>,
    street1: String,

    #[structopt(long)]
    street2: Option<String>,

    #[structopt(long)]
    street3: Option<String>,

    /// 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<(), aws_sdk_snowball::Error> {
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt::init();

    let Opt {
@@ -70,34 +93,58 @@ async fn main() -> Result<(), aws_sdk_snowball::Error> {
        street1,
        street2,
        street3,
        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"));

    println!();

    if verbose {
        println!("Snowball version:       {}", PKG_VERSION);
        println!(
            "Region:                 {}",
            region_provider.region().unwrap().as_ref()
        );
        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)
        .set_name(name)
        .name(name)
        .set_company(company)
        .set_street1(street1)
        .street1(street1)
        .set_street2(street2)
        .set_street3(street3)
        .set_city(city)
        .set_state_or_province(state)
        .city(city)
        .state_or_province(state)
        .set_prefecture_or_district(prefecture_or_district)
        .set_landmark(landmark)
        .set_country(country)
        .set_postal_code(postal_code)
        .set_phone_number(phone_number)
        .country(country)
        .postal_code(postal_code)
        .phone_number(phone_number)
        .set_is_restricted(Some(false))
        .build();

    let conf = Config::builder().region(region_provider).build();
    let client = aws_sdk_snowball::Client::from_conf(conf);
    let client = Client::from_conf(conf);

    let result = client.create_address().address(new_address).send().await?;

    println!();
    println!("Address: {:?}", result.address_id.unwrap());

    Ok(())
+28 −7
Original line number Diff line number Diff line
@@ -3,29 +3,50 @@
 * SPDX-License-Identifier: Apache-2.0.
 */

use aws_sdk_snowball::{Config, Region};
use aws_types::region;
use aws_sdk_snowball::{Client, Config, Error, Region, PKG_VERSION};
use aws_types::region::{self, ProvideRegion};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct Opt {
    /// The region
    /// The AWS Region.
    #[structopt(short, long)]
    region: Option<String>,

    /// 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<(), aws_sdk_snowball::Error> {
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt::init();

    let Opt { region } = Opt::from_args();
    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-east-1"));
        .or_else(Region::new("us-west-2"));

    println!();

    if verbose {
        println!("Snowball version: {}", PKG_VERSION);
        println!(
            "Region:           {}",
            region_provider.region().unwrap().as_ref()
        );
    }

    let conf = Config::builder().region(region_provider).build();
    let client = aws_sdk_snowball::Client::from_conf(conf);
    let client = Client::from_conf(conf);

    let addresses = client.describe_addresses().send().await?;
    for address in addresses.addresses.unwrap() {
+32 −8
Original line number Diff line number Diff line
@@ -3,29 +3,53 @@
 * SPDX-License-Identifier: Apache-2.0.
 */

use aws_sdk_snowball::{Config, Region};
use aws_types::region;
use aws_sdk_snowball::{Client, Config, Error, Region, PKG_VERSION};
use aws_types::region::{self, ProvideRegion};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
struct Opt {
    /// The region
    /// The AWS Region.
    #[structopt(short, long)]
    region: Option<String>,

    /// 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<(), aws_sdk_snowball::Error> {
async fn main() -> Result<(), Error> {
    tracing_subscriber::fmt::init();

    let Opt { region } = Opt::from_args();
    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-east-1"));
        .or_else(Region::new("us-west-2"));

    println!();

    if verbose {
        println!("Snowball version: {}", PKG_VERSION);
        println!(
            "Region:           {}",
            region_provider.region().unwrap().as_ref()
        );
        println!();
    }

    let conf = Config::builder().region(region_provider).build();
    let client = aws_sdk_snowball::Client::from_conf(conf);
    let client = Client::from_conf(conf);

    println!("Jobs:");

    let jobs = client.list_jobs().send().await?;
    for job in jobs.job_list_entries.unwrap() {