Skip to content

Commit d1d1f40

Browse files
authored
Python: Default to on-demand tables in Python DynamoDB examples. (#7264)
* Updates to Python DynamoDB provisioning settings.
1 parent 9645480 commit d1d1f40

File tree

7 files changed

+17
-33
lines changed

7 files changed

+17
-33
lines changed

python/example_code/dynamodb/GettingStarted/scenario_getting_started_movies.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ def create_table(self, table_name):
118118
{"AttributeName": "year", "AttributeType": "N"},
119119
{"AttributeName": "title", "AttributeType": "S"},
120120
],
121-
ProvisionedThroughput={
122-
"ReadCapacityUnits": 10,
123-
"WriteCapacityUnits": 10,
124-
},
121+
BillingMode='PAY_PER_REQUEST',
125122
)
126123
self.table.wait_until_exists()
127124
except ClientError as err:

python/example_code/dynamodb/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ Code excerpts that show you how to call individual service functions.
5252

5353
- [BatchExecuteStatement](partiql/scenario_partiql_batch.py#L44)
5454
- [BatchGetItem](batching/dynamo_batching.py#L64)
55-
- [BatchWriteItem](GettingStarted/scenario_getting_started_movies.py#L164)
55+
- [BatchWriteItem](GettingStarted/scenario_getting_started_movies.py#L161)
5656
- [CreateTable](GettingStarted/scenario_getting_started_movies.py#L100)
57-
- [DeleteItem](GettingStarted/scenario_getting_started_movies.py#L342)
58-
- [DeleteTable](GettingStarted/scenario_getting_started_movies.py#L363)
57+
- [DeleteItem](GettingStarted/scenario_getting_started_movies.py#L339)
58+
- [DeleteTable](GettingStarted/scenario_getting_started_movies.py#L360)
5959
- [DescribeTable](GettingStarted/scenario_getting_started_movies.py#L70)
6060
- [ExecuteStatement](partiql/scenario_partiql_single.py#L43)
61-
- [GetItem](GettingStarted/scenario_getting_started_movies.py#L223)
62-
- [ListTables](GettingStarted/scenario_getting_started_movies.py#L140)
63-
- [PutItem](GettingStarted/scenario_getting_started_movies.py#L193)
64-
- [Query](GettingStarted/scenario_getting_started_movies.py#L280)
65-
- [Scan](GettingStarted/scenario_getting_started_movies.py#L303)
66-
- [UpdateItem](GettingStarted/scenario_getting_started_movies.py#L248)
61+
- [GetItem](GettingStarted/scenario_getting_started_movies.py#L220)
62+
- [ListTables](GettingStarted/scenario_getting_started_movies.py#L137)
63+
- [PutItem](GettingStarted/scenario_getting_started_movies.py#L190)
64+
- [Query](GettingStarted/scenario_getting_started_movies.py#L277)
65+
- [Scan](GettingStarted/scenario_getting_started_movies.py#L300)
66+
- [UpdateItem](GettingStarted/scenario_getting_started_movies.py#L245)
6767

6868
### Scenarios
6969

python/example_code/dynamodb/TryDax/01-create-table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def create_dax_table(dyn_resource=None):
3333
{"AttributeName": "partition_key", "AttributeType": "N"},
3434
{"AttributeName": "sort_key", "AttributeType": "N"},
3535
],
36-
"ProvisionedThroughput": {"ReadCapacityUnits": 10, "WriteCapacityUnits": 10},
36+
"BillingMode": "PAY_PER_REQUEST",
3737
}
3838
table = dyn_resource.create_table(**params)
3939
print(f"Creating {table_name}...")

python/example_code/dynamodb/batching/dynamo_batching.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def create_table(table_name, schema):
5050
{"AttributeName": item["name"], "AttributeType": item["type"]}
5151
for item in schema
5252
],
53-
ProvisionedThroughput={"ReadCapacityUnits": 10, "WriteCapacityUnits": 10},
53+
BillingMode='PAY_PER_REQUEST',
5454
)
5555
table.wait_until_exists()
5656
logger.info("Created table %s.", table.name)
@@ -194,14 +194,7 @@ def archive_movies(movie_table, movie_data):
194194
TableName=f"{movie_table.name}-archive",
195195
KeySchema=movie_table.key_schema,
196196
AttributeDefinitions=movie_table.attribute_definitions,
197-
ProvisionedThroughput={
198-
"ReadCapacityUnits": movie_table.provisioned_throughput[
199-
"ReadCapacityUnits"
200-
],
201-
"WriteCapacityUnits": movie_table.provisioned_throughput[
202-
"WriteCapacityUnits"
203-
],
204-
},
197+
BillingMode='PAY_PER_REQUEST',
205198
)
206199
logger.info("Table %s created, wait until exists.", archive_table.name)
207200
archive_table.wait_until_exists()

python/example_code/dynamodb/batching/test/test_dynamo_batching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_create_table(
2727

2828
with stub_runner(error_code, stop_on_method) as runner:
2929
runner.add(
30-
dyn_stubber.stub_create_table, table_name, schema, {"read": 10, "write": 10}
30+
dyn_stubber.stub_create_table, table_name, schema
3131
)
3232
runner.add(dyn_stubber.stub_describe_table, table_name)
3333

python/example_code/dynamodb/partiql/scaffold.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ def create_table(self, table_name):
4646
{"AttributeName": "year", "AttributeType": "N"},
4747
{"AttributeName": "title", "AttributeType": "S"},
4848
],
49-
ProvisionedThroughput={
50-
"ReadCapacityUnits": 10,
51-
"WriteCapacityUnits": 10,
52-
},
49+
BillingMode='PAY_PER_REQUEST',
5350
)
5451
self.table.wait_until_exists()
5552
except ClientError as err:

python/test_tools/dynamodb_stubber.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,9 @@ def _build_out_item(self, in_item):
7777
out_item[key] = {value_type: out_val}
7878
return out_item
7979

80-
def stub_create_table(self, table_name, schema, throughput, error_code=None):
80+
def stub_create_table(self, table_name, schema, error_code=None):
8181
table_input = {
82-
"ProvisionedThroughput": {
83-
"ReadCapacityUnits": throughput["read"],
84-
"WriteCapacityUnits": throughput["write"],
85-
}
82+
"BillingMode": "PAY_PER_REQUEST",
8683
}
8784
self._add_table_schema(table_input, table_name, schema)
8885

0 commit comments

Comments
 (0)