Skip to content

Commit

Permalink
Merge branch 'main' into testing-add-sos
Browse files Browse the repository at this point in the history
  • Loading branch information
shepazon authored Nov 8, 2023
2 parents fc1e22e + 20ed184 commit 3a18127
Show file tree
Hide file tree
Showing 12 changed files with 274 additions and 23 deletions.
29 changes: 29 additions & 0 deletions .doc_gen/cross-content/cross_FMPlayground_NetV3_block.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "file://zonbook/docbookx.dtd" [
<!ENTITY % phrases-shared SYSTEM "file://AWSShared/common/phrases-shared.ent">
%phrases-shared;
]>
<block>
<para>
.NET Foundation Model (FM) Playground is a .NET MAUI Blazor sample application that showcases how to use &BRlong; from C# code.
This example shows how .NET and C# developers can use &BR;
to build generative AI-enabled applications. You can test and interact with &BR; foundation models by using the following four playgrounds:
</para>
<itemizedlist>
<listitem>
<para>A text playground.</para>
</listitem>
<listitem>
<para>A chat playground.</para>
</listitem>
<listitem>
<para>A voice chat playground.</para>
</listitem>
<listitem>
<para>An image playground.</para>
</listitem>
</itemizedlist>
<para>The example also lists and displays the foundation models you have access to and their characteristics. For source code and deployment
instructions, see the project in <ulink url="https://github.com/build-on-aws/dotnet-fm-playground">GitHub</ulink>.
</para>
</block>
6 changes: 2 additions & 4 deletions .doc_gen/metadata/aurora_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ aurora_Hello:
- sdk_version: 1
github: rust_dev_preview/examples/aurora
excerpts:
- snippet_tags:
- rust.aurora.get_cluster.usage
- rust.aurora.describe_db_clusters.wrapper
- rust.aurora.get_cluster.test
- snippet_files:
- rust_dev_preview/examples/aurora/src/bin/hello-world.rs
services:
aurora: {DescribeDBClusters}
aurora_DescribeDBClusterParameterGroups:
Expand Down
34 changes: 34 additions & 0 deletions .doc_gen/metadata/cross_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -694,3 +694,37 @@ cross_ResilientService:
DescribeLoadBalancers, CreateTargetGroup, DescribeTargetGroups, DeleteTargetGroup,
CreateLoadBalancer, CreateListener, DeleteLoadBalancer, DescribeTargetHealth}
iam: {CreateInstanceProfile, DeleteInstanceProfile}
cross_FMPlayground:
title: Create a sample application that offers playgrounds to interact with &BR; foundation models using an &AWS; SDK
title_abbrev: Create a playground application to interact with &BR; foundation models
synopsis: create playgrounds to interact with &BR; foundation models through different modalities.
category: Scenarios
languages:
.NET:
versions:
- sdk_version: 3
block_content: cross_FMPlayground_NetV3_block.xml
service_main: bedrock-runtime
services:
bedrock-runtime:
cross_Testing:
title: Example approaches for unit and integration testing with an &AWS; SDK
title_abbrev: Unit and integration test with an SDK
synopsis: examples for best-practice techniques when writing unit and integration tests using an &AWS; SDK.
languages:
Rust:
versions:
- sdk_version: 1
github: rust_dev_preview/examples/testing
excerpts:
- description: Cargo.toml for testing examples.
snippet_files:
- rust_dev_preview/examples/testing/Cargo.toml
- description: Unit testing example using automock and a service wrapper.
snippet_files:
- rust_dev_preview/examples/testing/src/wrapper.rs
- description: Integration testing example using StaticReplayClient.
snippet_files:
- rust_dev_preview/examples/testing/src/replay.rs
services:
s3:
10 changes: 5 additions & 5 deletions .doc_gen/metadata/s3_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2373,15 +2373,15 @@ s3_Scenario_PresignedUrl:
github: kotlin/services/s3
sdkguide: sdk-for-kotlin/latest/developer-guide/presign-requests.html
excerpts:
- description: Create a GetObject presigned request and use the URL to download an object.
- description: Create a <code>GetObject</code> presigned request and use the URL to download an object.
snippet_tags:
- s3.kotlin.presign_getObject.main
- description: Create a GetObject presigned request with advanced options and use the URL to download an object.
snippet_tags:
- s3.kotlin.presign_putObject.main
- description: Create a PutObject presigned request and use it to upload an object.
- description: Create a <code>GetObject</code> presigned request with advanced options and use the URL to download an object.
snippet_tags:
- s3.kotlin.presign_getObjectMoreOptions.main
- description: Create a <code>PutObject</code> presigned request and use it to upload an object.
snippet_tags:
- s3.kotlin.presign_putObject.main
Rust:
versions:
- sdk_version: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ permissions:
jobs:
check:
name: Check
runs-on: temporary-sizing-testing_ubuntu-latest_32-core
runs-on: aws-doc-sdk-examples_ubuntu-latest_16-core
steps:
- name: setup
run: >
Expand Down
19 changes: 14 additions & 5 deletions kotlin/services/s3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ repositories {
mavenCentral()
jcenter()
}

apply(plugin = "org.jlleitschuh.gradle.ktlint")

dependencies {
implementation("aws.sdk.kotlin:s3:0.30.1-beta")
implementation("aws.sdk.kotlin:secretsmanager:0.30.1-beta")
implementation("com.google.code.gson:gson:2.10")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("aws.sdk.kotlin:s3-jvm:0.26.0-beta")
implementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.20.0")
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("aws.smithy.kotlin:aws-signing-crt:0.21.0")
testImplementation(kotlin("test"))
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
implementation("com.fasterxml.jackson.core:jackson-databind:2.14.2")
}

tasks.withType<KotlinCompile>() {
kotlinOptions.jvmTarget = "1.8"
}

tasks.test {
useJUnitPlatform()
}
1 change: 1 addition & 0 deletions kotlin/services/s3/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "s3"
39 changes: 39 additions & 0 deletions rust_dev_preview/examples/aurora/src/bin/hello-world.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
use aws_sdk_rds::Client;

#[derive(Debug)]
struct Error(String);
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl std::error::Error for Error {}

#[tokio::main]
async fn main() -> Result<(), Error> {
tracing_subscriber::fmt::init();
let sdk_config = aws_config::from_env().load().await;
let client = Client::new(&sdk_config);

let describe_db_clusters_output = client
.describe_db_clusters()
.send()
.await
.map_err(|e| Error(e.to_string()))?;
println!(
"Found {} clusters:",
describe_db_clusters_output.db_clusters().len()
);
for cluster in describe_db_clusters_output.db_clusters() {
let name = cluster.database_name().unwrap_or("Unknown");
let engine = cluster.engine().unwrap_or("Unknown");
let id = cluster.db_cluster_identifier().unwrap_or("Unknown");
let class = cluster.db_cluster_instance_class().unwrap_or("Unknown");
println!("\tDatabase: {name}",);
println!("\t Engine: {engine}",);
println!("\t ID: {id}",);
println!("\tInstance: {class}",);
}

Ok(())
}
2 changes: 2 additions & 0 deletions rust_dev_preview/examples/sdk-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ version = "0.1.0"
authors = [
"John DiSanti <[email protected]>",
"Doug Schwartz <[email protected]>",
"David Souther <[email protected]>"
]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-config = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-credential-types = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
aws-sdk-s3 = { git = "https://github.com/awslabs/aws-sdk-rust", branch = "next" }
tokio = { version = "1.20.1", features = ["full"] }
clap = { version = "~4.4", features = ["derive"] }
Expand Down
139 changes: 139 additions & 0 deletions rust_dev_preview/examples/sdk-config/src/bin/no_env.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/
#![allow(clippy::result_large_err)]

// File overview: This example shows how to create an SdkConfig without using the
// default AWS environment configuration.

use aws_config::meta::region::RegionProviderChain;
use aws_credential_types::provider::{ProvideCredentials, SharedCredentialsProvider};
use aws_sdk_s3::config::retry::RetryConfig;
use aws_sdk_s3::config::Credentials;
use aws_sdk_s3::{config::Region, meta::PKG_VERSION, Client, Error};
use clap::Parser;

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

/// The number of (re)tries.
#[structopt(short, long, default_value = "2")]
tries: u32,

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

// Shows your buckets.
async fn show_num_buckets(client: &Client) -> Result<(), Error> {
let resp = client.list_buckets().send().await?;
let buckets = resp.buckets();

println!("Found {} buckets in all regions.", buckets.len());

Ok(())
}

/// A Credentials provider that uses non-standard environment variables `MY_ID`
/// and `MY_KEY` instead of `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. This
/// could alternatively load credentials from another secure source of environment
/// secrets, if traditional AWS SDK for Rust credentials providers do not suit
/// your use case.
///
/// WARNING: This example is for demonstration purposes only. Your code should always
/// load credentials in a secure fashion.
#[derive(Debug)]
struct StaticCredentials {
access_key_id: String,
secret_access_key: String,
}

impl StaticCredentials {
pub fn new() -> Self {
let access_key_id = std::env::var("MY_ID").expect("access key id");
let secret_access_key = std::env::var("MY_KEY").expect("secret access key");
Self {
access_key_id: access_key_id.trim().to_string(),
secret_access_key: secret_access_key.trim().to_string(),
}
}

async fn load_credentials(&self) -> aws_credential_types::provider::Result {
Ok(Credentials::new(
self.access_key_id.clone(),
self.secret_access_key.clone(),
None,
None,
"StaticCredentials",
))
}
}

impl ProvideCredentials for StaticCredentials {
fn provide_credentials<'a>(
&'a self,
) -> aws_credential_types::provider::future::ProvideCredentials<'a>
where
Self: 'a,
{
aws_credential_types::provider::future::ProvideCredentials::new(self.load_credentials())
}
}

/// Displays how many Amazon S3 buckets you have.
/// # 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**.
/// * `[-t TRIES]` - The number of times to (re)try the request.
/// * `[-v]` - Whether to display additional information.
///
/// # Environment
///
/// * MY_ID - an AWS IAM Access Key ID to use for this request.
/// * MY_KEY - an AWS IAM Secret Access Key to use for this request.
#[tokio::main]
async fn main() -> Result<(), Error> {
tracing_subscriber::fmt::init();

let Opt {
region,
tries,
verbose,
} = Opt::parse();

let region = RegionProviderChain::first_try(region.map(Region::new))
.or_else(Region::new("us-west-2"))
.region()
.await
.expect("parsed region");
println!();

if verbose {
println!("S3 client version: {PKG_VERSION}");
println!("Region: {region}");
println!("Retries: {tries}");
println!();
}

assert_ne!(tries, 0, "You cannot set zero retries.");

let shared_config = aws_config::SdkConfig::builder()
.region(region)
.credentials_provider(SharedCredentialsProvider::new(StaticCredentials::new()))
// Set max attempts.
// If tries is 1, there are no retries.
.retry_config(RetryConfig::standard().with_max_attempts(tries))
.build();

// Construct an S3 client with customized retry configuration.
let client = Client::new(&shared_config);

show_num_buckets(&client).await
}
8 changes: 4 additions & 4 deletions rust_dev_preview/examples/testing/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ mod test {
let fake = ListObjects::Test {
expected_bucket: "test-bucket".into(),
expected_prefix: "test-prefix".into(),
pages: vec![[5, 2i64]
.iter()
.map(|size| Object::builder().size(*size).build())
.collect()],
pages: vec![vec![
Object::builder().size(5).build(),
Object::builder().size(2).build(),
]],
};

// Run the code we want to test with it
Expand Down
8 changes: 4 additions & 4 deletions rust_dev_preview/examples/testing/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ mod test {
let fake = TestListObjects {
expected_bucket: "test-bucket".into(),
expected_prefix: "test-prefix".into(),
pages: vec![[5, 2i64]
.iter()
.map(|size| Object::builder().size(*size).build())
.collect()],
pages: vec![vec![
Object::builder().size(5).build(),
Object::builder().size(2).build(),
]],
};

// Run the code we want to test with it
Expand Down

0 comments on commit 3a18127

Please sign in to comment.