Unverified Commit b0d68dd1 authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Rollup of 4 pull requests (#610)



* Updated EBS code example docs (#587)

* Updated EBS code example docs; added delete-snapshot, get-snapshot-state, and list-snapshots code examples

* Updated EBS code examples based on feedback

* Updated EBS code examples to follow latest code guidelines and proper service naming

* Refactored Kinesis code examples (#549)

* Reordered crates in Cargo.toml; refactored code examples to use common example pattern

* Updated Kinesis code examples to use ? instead of expect()

* Updated Kinesis code examples based on feedback

* Refactored Lambda code examples (#552)

* Re-ordered crates in Cargo.toml; refactored Lambda code examples to use common example pattern; added change-java-runtime and list-all-functin-runtimes code examples

* Updated Lambda code examples to use ? instead of expect()

* Updated Lambda invoke-function code example to use InvokeErrorKind::ResourceNotFoundException

* Updated Lambda code examples to use latest pattern

* Refactored CognitoIdentity code examples (#584)

* Updated CognitoIdentity code examples to use -v (verbose) option; added describe-identity-pool and list-pool-identities

* Updated docs for Cognito identity pool code examples

* Updated CognitoIdentity list-pool-identies code example based on feedback

* Updated Cognito identity pool code examples based on feedback

Co-authored-by: default avatarDoug <dougsch@amazon.com>
parent a88fff1a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
[package]
name = "cognitoidentity-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
@@ -10,5 +10,6 @@ edition = "2018"
cognitoidentity = { package = "aws-sdk-cognitoidentity", path = "../../build/aws-sdk/cognitoidentity" }
aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = { version = "1", features = ["full"] }
chrono = "0.4"
structopt = { version = "0.3", default-features = false }
tracing-subscriber = "0.2.18"
+127 −0
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

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

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

    /// The ID of the identity pool to describe.
    #[structopt(short, long)]
    identity_pool_id: String,

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

/// Displays some information about an Amazon Cognito identitiy pool.
/// # 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<(), Error> {
    tracing_subscriber::fmt::init();

    let Opt {
        identity_pool_id,
        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"));

    println!();

    if verbose {
        println!("Cognito client version: {}", PKG_VERSION);
        println!(
            "Region:                 {}",
            region_provider.region().unwrap().as_ref()
        );
        println!("Identity pool ID:       {}", identity_pool_id);
        println!();
    }

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

    let response = client
        .describe_identity_pool()
        .identity_pool_id(identity_pool_id)
        .send()
        .await?;

    let allow_classic = response.allow_classic_flow.unwrap_or_default();
    let allow_unauth_ids = response.allow_unauthenticated_identities;
    println!("  Allow classic flow                {}", allow_classic);
    println!("  Allow unauthenticated identities: {}", allow_unauth_ids);
    if let Some(providers) = response.cognito_identity_providers {
        println!("  Identity Providers:");
        for provider in providers {
            let client_id = provider.client_id.unwrap_or_default();
            let name = provider.provider_name.unwrap_or_default();
            let server_side_check = provider.server_side_token_check.unwrap_or_default();

            println!("    Client ID:                {}", client_id);
            println!("    Name:                     {}", name);
            println!("    Service-side token check: {}", server_side_check);
            println!();
        }
    }

    let developer_provider = response.developer_provider_name.unwrap_or_default();
    let id = response.identity_pool_id.unwrap_or_default();
    let name = response.identity_pool_name.unwrap_or_default();

    println!("  Developer provider:               {}", developer_provider);
    println!("  Identity pool ID:                 {}", id);
    println!("  Identity pool name:               {}", name);

    if let Some(tags) = response.identity_pool_tags {
        println!("  Tags:");
        for (key, value) in tags {
            println!("    key:   {}", key);
            println!("    value: {}", value);
        }
    }

    if let Some(open_id_arns) = response.open_id_connect_provider_ar_ns {
        println!("  Open ID provider ARNs:");
        for arn in open_id_arns {
            println!("    {}", arn);
        }
    }

    if let Some(saml_arns) = response.saml_provider_ar_ns {
        println!("  SAML provider ARNs:");
        for arn in saml_arns {
            println!("    {}", arn);
        }
    }

    // SupportedLoginProviders
    if let Some(login_providers) = response.supported_login_providers {
        println!("  Supported login providers:");
        for (key, value) in login_providers {
            println!("    key:   {}", key);
            println!("    value: {}", value);
        }
    }

    println!();

    Ok(())
}
+16 −9
Original line number Diff line number Diff line
@@ -4,27 +4,26 @@
 */

use aws_types::region::{self, ProvideRegion};
use cognitoidentity::{Client, Config, Error, Region};
use cognitoidentity::{Client, Config, 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 your Amazon Cognito identity pools in the Region.
/// # Arguments
///
/// * `[-r REGION]` - The region containing the buckets.
///   If not supplied, uses the value of the **AWS_DEFAULT_REGION** environment variable.
/// * `[-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**.
/// * `[-g]` - Whether to display buckets in all regions.
/// * `[-v]` - Whether to display additional information.
#[tokio::main]
async fn main() -> Result<(), Error> {
@@ -36,9 +35,14 @@ async fn main() -> Result<(), Error> {
        .or_default_provider()
        .or_else(Region::new("us-west-2"));

    println!();

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

@@ -46,6 +50,8 @@ async fn main() -> Result<(), Error> {
    let client = Client::from_conf(config);

    let response = client.list_identity_pools().max_results(10).send().await?;

    // Print IDs and names of pools.
    if let Some(pools) = response.identity_pools {
        println!("Identity pools:");
        for pool in pools {
@@ -56,6 +62,7 @@ async fn main() -> Result<(), Error> {
            println!();
        }
    }

    println!("Next token: {:?}", response.next_token);

    Ok(())
+93 −0
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

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

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

    /// The ID of the identity pool to describe.
    #[structopt(short, long)]
    identity_pool_id: String,

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

/// Lists the identities in an Amazon Cognito identity pool.
/// # Arguments
///
/// * `-i IDENTITY-POOL-ID` - The ID of the identity pool.
/// * `[-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<(), Error> {
    tracing_subscriber::fmt::init();

    let Opt {
        identity_pool_id,
        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"));

    println!();

    if verbose {
        println!("Cognito client version: {}", PKG_VERSION);
        println!(
            "Region:                 {}",
            region_provider.region().unwrap().as_ref()
        );
        println!("Identity pool ID:       {}", identity_pool_id);
        println!();
    }

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

    let response = client
        .list_identities()
        .identity_pool_id(identity_pool_id)
        .max_results(10)
        .send()
        .await?;

    if let Some(ids) = response.identities {
        println!("Identitities:");
        for id in ids {
            let creation_timestamp = id.creation_date.unwrap().to_chrono();
            let idid = id.identity_id.unwrap_or_default();
            let mod_timestamp = id.last_modified_date.unwrap().to_chrono();
            println!("  Creation date:      {}", creation_timestamp);
            println!("  ID:                 {}", idid);
            println!("  Last modified date: {}", mod_timestamp);

            println!("  Logins:");
            for login in id.logins.unwrap_or_default() {
                println!("    {}", login);
            }

            println!();
        }
    }

    println!("Next token: {:?}", response.next_token);

    println!();

    Ok(())
}
+7 −5
Original line number Diff line number Diff line
[package]
name = "ebs"
name = "ebs-code-examples"
version = "0.1.0"
authors = ["Russell Cohen <rcoh@amazon.com>"]
edition = "2018"
@@ -7,9 +7,11 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-sdk-ebs = { package = "aws-sdk-ebs", path = "../../build/aws-sdk/ebs" }
aws-sdk-ec2 = { package = "aws-sdk-ec2", path = "../../build/aws-sdk/ec2" }
aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = { version = "1", features = ["full"]}
aws-sdk-ebs = { path = "../../build/aws-sdk/ebs" }
aws-sdk-ec2 = { path = "../../build/aws-sdk/ec2" }
sha2 = "0.9.5"
base64 = "0.13.0"
sha2 = "0.9.5"
structopt = { version = "0.3", default-features = false }
tracing-subscriber = "0.2.19"
 No newline at end of file
Loading