Skip to content

Commit 65166ab

Browse files
[examples] Sync SDK examples from awsdocs/aws-doc-sdk-examples
Includes commit(s): 60dcd5ddc37395a47c7a717bd1966e3a389fc00c Co-authored-by: Brian Murray <[email protected]>
1 parent 760ae38 commit 65166ab

File tree

11 files changed

+29
-67
lines changed

11 files changed

+29
-67
lines changed

examples/cross_service/photo_asset_management/integration/tests/update_label.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
use std::collections::HashMap;
44

5-
use aws_sdk_dynamodb::types::{AttributeDefinition, KeySchemaElement, ProvisionedThroughput};
5+
use aws_sdk_dynamodb::types::{AttributeDefinition, KeySchemaElement, BillingMode};
66
use aws_sdk_rekognition::types::Label;
77
use photo_asset_management::{
88
common::{init_tracing_subscriber, Common},
@@ -27,13 +27,8 @@ async fn create_table(common: &Common) -> Result<(), impl std::error::Error> {
2727
.attribute_definitions(
2828
AttributeDefinition::builder()
2929
.attribute_name("Label")
30-
.attribute_type(aws_sdk_dynamodb::types::ScalarAttributeType::S)
31-
.build(),
32-
)
33-
.provisioned_throughput(
34-
ProvisionedThroughput::builder()
35-
.write_capacity_units(1)
36-
.read_capacity_units(1)
30+
.attribute_type(aws_sdk_dynamodb::types::ScalarAttributeType::S),
31+
.billing_mode(aws_sdk_dynamodb::types::BillingMode::PayPerRequest)
3732
.build(),
3833
)
3934
.send()

examples/examples/bedrock-runtime/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ edition = "2021"
66
publish = false
77

88
[dependencies]
9+
aws-config = { version = "1.5.17", path = "../../../sdk/aws-config" }
10+
aws-sdk-bedrockruntime = { version = "1.75.0", path = "../../../sdk/bedrockruntime" }
11+
aws-smithy-runtime-api = { version = "1.7.3", path = "../../../sdk/aws-smithy-runtime-api" }
12+
aws-smithy-types = { version = "1.2.13", path = "../../../sdk/aws-smithy-types" }
913
reqwest = "0.12.5"
1014
serde = "1.0.204"
1115
serde_json = "1.0.120"
1216
tracing = "0.1.40"
1317
tracing-subscriber = "0.3.18"
14-
aws-config= { version = "1.5.17", path = "../../../sdk/aws-config" }
15-
aws-sdk-bedrockruntime= { version = "1.75.0", path = "../../../sdk/bedrockruntime" }
16-
aws-smithy-runtime-api= { version = "1.7.3", path = "../../../sdk/aws-smithy-runtime-api" }
17-
aws-smithy-types= { version = "1.2.13", path = "../../../sdk/aws-smithy-types" }
1818

1919
[dependencies.tokio]
2020
version = "1.38.1"

examples/examples/cloudwatchlogs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ path = "../../test-utils"
3232
version = "0.1.0"
3333

3434
[dev-dependencies]
35-
aws-smithy-mocks-experimental= { version = "0.2.3", path = "../../../sdk/aws-smithy-mocks-experimental" }
35+
aws-smithy-mocks-experimental = { version = "0.2.3", path = "../../../sdk/aws-smithy-mocks-experimental" }

examples/examples/dynamodb/src/bin/crud.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use aws_sdk_dynamodb::error::SdkError;
88
use aws_sdk_dynamodb::operation::create_table::CreateTableError;
99
use aws_sdk_dynamodb::operation::put_item::PutItemError;
1010
use aws_sdk_dynamodb::types::{
11-
AttributeDefinition, AttributeValue, KeySchemaElement, KeyType, ProvisionedThroughput,
11+
AttributeDefinition, AttributeValue, BillingMode, KeySchemaElement, KeyType,
1212
ScalarAttributeType, Select, TableStatus,
1313
};
1414
use aws_sdk_dynamodb::{config::Region, meta::PKG_VERSION, Client, Error};
@@ -63,18 +63,12 @@ async fn make_table(
6363
.build()
6464
.expect("creating KeySchemaElement");
6565

66-
let pt = ProvisionedThroughput::builder()
67-
.read_capacity_units(10)
68-
.write_capacity_units(5)
69-
.build()
70-
.expect("creating ProvisionedThroughput");
71-
7266
match client
7367
.create_table()
7468
.table_name(table)
7569
.key_schema(ks)
7670
.attribute_definitions(ad)
77-
.provisioned_throughput(pt)
71+
.billing_mode(BillingMode::PayPerRequest)
7872
.send()
7973
.await
8074
{

examples/examples/dynamodb/src/bin/dynamodb-helloworld.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use aws_config::meta::region::RegionProviderChain;
77
use aws_sdk_dynamodb::types::{
8-
AttributeDefinition, KeySchemaElement, KeyType, ProvisionedThroughput, ScalarAttributeType,
8+
AttributeDefinition, BillingMode, KeySchemaElement, KeyType, ScalarAttributeType,
99
};
1010
use aws_sdk_dynamodb::{config::Region, meta::PKG_VERSION, Client, Error};
1111
use clap::Parser;
@@ -47,18 +47,12 @@ async fn create_table(client: &Client) -> Result<(), Error> {
4747
.build()
4848
.expect("creating AttributeDefinition");
4949

50-
let pt = ProvisionedThroughput::builder()
51-
.write_capacity_units(10)
52-
.read_capacity_units(10)
53-
.build()
54-
.expect("creating ProvisionedThroughput");
55-
5650
let new_table = client
5751
.create_table()
5852
.table_name("test-table")
5953
.key_schema(ks)
6054
.attribute_definitions(ad)
61-
.provisioned_throughput(pt)
55+
.billing_mode(BillingMode::PayPerRequest)
6256
.send()
6357
.await?;
6458
println!(

examples/examples/dynamodb/src/bin/partiql.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use aws_sdk_dynamodb::error::SdkError;
88
use aws_sdk_dynamodb::operation::create_table::CreateTableError;
99
use aws_sdk_dynamodb::operation::execute_statement::ExecuteStatementError;
1010
use aws_sdk_dynamodb::types::{
11-
AttributeDefinition, AttributeValue, KeySchemaElement, KeyType, ProvisionedThroughput,
11+
AttributeDefinition, AttributeValue, BillingMode, KeySchemaElement, KeyType,
1212
ScalarAttributeType, TableStatus,
1313
};
1414
use aws_sdk_dynamodb::{config::Region, meta::PKG_VERSION, Client, Error};
@@ -44,7 +44,7 @@ fn random_string(n: usize) -> String {
4444
.collect()
4545
}
4646

47-
/// Create a new table.
47+
/// Create a new on-demand table.
4848
// snippet-start:[dynamodb.rust.partiql-make_table]
4949
async fn make_table(
5050
client: &Client,
@@ -63,18 +63,12 @@ async fn make_table(
6363
.build()
6464
.expect("creating KeySchemaElement");
6565

66-
let pt = ProvisionedThroughput::builder()
67-
.read_capacity_units(10)
68-
.write_capacity_units(5)
69-
.build()
70-
.expect("creating ProvisionedThroughput");
71-
7266
match client
7367
.create_table()
7468
.table_name(table)
7569
.key_schema(ks)
7670
.attribute_definitions(ad)
77-
.provisioned_throughput(pt)
71+
.billing_mode(BillingMode::PayPerRequest)
7872
.send()
7973
.await
8074
{

examples/examples/dynamodb/src/scenario/create.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
use crate::scenario::error::Error;
55
use aws_sdk_dynamodb::operation::create_table::CreateTableOutput;
66
use aws_sdk_dynamodb::types::{
7-
AttributeDefinition, KeySchemaElement, KeyType, ProvisionedThroughput, ScalarAttributeType,
7+
AttributeDefinition, BillingMode, KeySchemaElement, KeyType, ScalarAttributeType,
88
};
99
use aws_sdk_dynamodb::Client;
1010

11-
// Create a table.
11+
// Create an on-demand table.
1212
// snippet-start:[dynamodb.rust.create-table]
1313
pub async fn create_table(
1414
client: &Client,
@@ -30,18 +30,12 @@ pub async fn create_table(
3030
.build()
3131
.map_err(Error::BuildError)?;
3232

33-
let pt = ProvisionedThroughput::builder()
34-
.read_capacity_units(10)
35-
.write_capacity_units(5)
36-
.build()
37-
.map_err(Error::BuildError)?;
38-
3933
let create_table_response = client
4034
.create_table()
4135
.table_name(table_name)
4236
.key_schema(ks)
4337
.attribute_definitions(ad)
44-
.provisioned_throughput(pt)
38+
.billing_mode(BillingMode::PayPerRequest)
4539
.send()
4640
.await;
4741

examples/examples/dynamodb/src/scenario/movies/startup.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ use crate::scenario::error::Error;
55
use aws_sdk_dynamodb::{
66
operation::create_table::builders::CreateTableFluentBuilder,
77
types::{
8-
AttributeDefinition, KeySchemaElement, KeyType, ProvisionedThroughput, ScalarAttributeType,
9-
TableStatus, WriteRequest,
8+
AttributeDefinition, KeySchemaElement, KeyType, ScalarAttributeType, TableStatus,
9+
WriteRequest,
1010
},
1111
Client,
1212
};
1313
use futures::future::join_all;
1414
use std::{collections::HashMap, time::Duration};
1515
use tracing::{debug, info, trace};
1616

17-
const CAPACITY: i64 = 10;
18-
1917
#[tracing::instrument(level = "trace")]
2018
pub async fn initialize(client: &Client, table_name: &str) -> Result<(), Error> {
2119
info!("Initializing Movies DynamoDB in {table_name}");
@@ -24,7 +22,7 @@ pub async fn initialize(client: &Client, table_name: &str) -> Result<(), Error>
2422
info!("Found existing table {table_name}");
2523
} else {
2624
info!("Table does not exist, creating {table_name}");
27-
create_table(client, table_name, "year", "title", CAPACITY)?
25+
create_table(client, table_name, "year", "title")?
2826
.send()
2927
.await?;
3028
await_table(client, table_name).await?;
@@ -55,9 +53,8 @@ pub fn create_table(
5553
table_name: &str,
5654
primary_key: &str,
5755
sort_key: &str,
58-
capacity: i64,
5956
) -> Result<CreateTableFluentBuilder, Error> {
60-
info!("Creating table: {table_name} with capacity {capacity} and key structure {primary_key}:{sort_key}");
57+
info!("Creating table: {table_name} key structure {primary_key}:{sort_key}");
6158
Ok(client
6259
.create_table()
6360
.table_name(table_name)
@@ -89,13 +86,7 @@ pub fn create_table(
8986
.build()
9087
.expect("Failed to build attribute definition"),
9188
)
92-
.provisioned_throughput(
93-
ProvisionedThroughput::builder()
94-
.read_capacity_units(capacity)
95-
.write_capacity_units(capacity)
96-
.build()
97-
.expect("Failed to specify ProvisionedThroughput"),
98-
))
89+
.billing_mode(aws_sdk_dynamodb::types::BillingMode::PayPerRequest))
9990
}
10091
// snippet-end:[dynamodb.rust.movies-create_table_request]
10192

examples/examples/ec2/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ publish = false
88

99
[dependencies]
1010
tracing = "0.1.40"
11+
aws-smithy-runtime-api = { version = "1.7.3", path = "../../../sdk/aws-smithy-runtime-api" }
1112
mockall = "0.13.0"
1213
inquire = "0.7.5"
1314
reqwest = "0.12.5"
14-
aws-smithy-runtime-api= { version = "1.7.3", path = "../../../sdk/aws-smithy-runtime-api" }
15-
aws-sdk-ssm= { version = "1.66.1", path = "../../../sdk/ssm" }
16-
aws-smithy-async= { version = "1.2.4", path = "../../../sdk/aws-smithy-async" }
15+
aws-sdk-ssm = { version = "1.66.1", path = "../../../sdk/ssm" }
16+
aws-smithy-async = { version = "1.2.4", path = "../../../sdk/aws-smithy-async" }
1717
aws-config= { version = "1.5.17", path = "../../../sdk/aws-config", features = ["behavior-version-latest"] }
1818
aws-sdk-ec2= { version = "1.114.0", path = "../../../sdk/ec2" }
1919
aws-types= { version = "1.3.5", path = "../../../sdk/aws-types" }

examples/examples/ses/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ publish = false
1010
anyhow = "1.0.81"
1111
tracing = "0.1.40"
1212
tmpfile = "0.0.2"
13+
aws-smithy-http = { version = "0.60.12", path = "../../../sdk/aws-smithy-http" }
14+
aws-smithy-mocks-experimental = { version = "0.2.3", path = "../../../sdk/aws-smithy-mocks-experimental" }
1315
open = "5.1.2"
14-
aws-smithy-http= { version = "0.60.12", path = "../../../sdk/aws-smithy-http" }
15-
aws-smithy-mocks-experimental= { version = "0.2.3", path = "../../../sdk/aws-smithy-mocks-experimental" }
1616
aws-config= { version = "1.5.17", path = "../../../sdk/aws-config", features = ["behavior-version-latest"] }
1717
aws-sdk-sesv2= { version = "1.68.0", path = "../../../sdk/sesv2", features = ["test-util"] }
1818

0 commit comments

Comments
 (0)