Skip to content

Commit 60dcd5d

Browse files
authored
Dynamodb updates (#7267)
* test * Update JS DynamoDB examples to use on-demand rather than provisioned * Update Rust and Ruby DynamoDB examples to use on-demand rather than provisioned * Update Rust and Ruby DynamoDB examples to use on-demand rather than provisioned * Update Rust and Ruby DynamoDB examples to use on-demand rather than provisioned * Update Rust and Ruby DynamoDB examples to use on-demand rather than provisioned
1 parent 87cc429 commit 60dcd5d

File tree

12 files changed

+25
-68
lines changed

12 files changed

+25
-68
lines changed

javascriptv3/example_code/dynamodb/actions/create-table.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ export const main = async () => {
2626
KeyType: "HASH",
2727
},
2828
],
29-
ProvisionedThroughput: {
30-
ReadCapacityUnits: 1,
31-
WriteCapacityUnits: 1,
32-
},
29+
BillingMode: "PAY_PER_REQUEST",
3330
});
3431

3532
const response = await client.send(command);

javascriptv3/example_code/dynamodb/tests/delete-table.integration.test.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ describe("delete-table", () => {
2828
KeyType: "HASH",
2929
},
3030
],
31-
ProvisionedThroughput: {
32-
ReadCapacityUnits: 1,
33-
WriteCapacityUnits: 1,
34-
},
31+
BillingMode: "PAY_PER_REQUEST",
3532
});
3633

3734
await client.send(createTableCommand);

ruby/Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
source 'https://rubygems.org'
2-
ruby '3.1.2'
2+
ruby '3.3.7'
33

44
gem 'aws-sdk'
55
gem 'cli-ui'

ruby/Gemfile.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,7 @@ GEM
15201520

15211521
PLATFORMS
15221522
arm64-darwin-22
1523+
x64-mingw-ucrt
15231524
x86_64-linux
15241525

15251526
DEPENDENCIES
@@ -1545,7 +1546,7 @@ DEPENDENCIES
15451546
zip
15461547

15471548
RUBY VERSION
1548-
ruby 3.1.2p20
1549+
ruby 3.3.7p123
15491550

15501551
BUNDLED WITH
15511552
2.3.7

ruby/example_code/dynamodb/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,4 @@ To learn more about the contributing process, see [CONTRIBUTING.md](../../../CON
184184

185185
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
186186

187-
SPDX-License-Identifier: Apache-2.0
187+
SPDX-License-Identifier: Apache-2.0

ruby/example_code/dynamodb/scaffold.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def create_table(table_name)
6868
{ attribute_name: 'year', attribute_type: 'N' },
6969
{ attribute_name: 'title', attribute_type: 'S' }
7070
],
71-
provisioned_throughput: { read_capacity_units: 10, write_capacity_units: 10 }
71+
billing_mode: 'PAY_PER_REQUEST'
7272
)
7373
@dynamo_resource.client.wait_until(:table_exists, table_name: table_name)
7474
@table

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

+3-8
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()

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

+2-8
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
{

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

+2-8
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!(

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

+3-9
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
{

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

+3-9
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

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

+5-14
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

0 commit comments

Comments
 (0)