From d550dd6c466115a83dff33fc244227843d34c854 Mon Sep 17 00:00:00 2001 From: Rachel Hagerman <110480692+rlhagerm@users.noreply.github.com> Date: Thu, 27 Feb 2025 09:58:57 -0600 Subject: [PATCH 1/2] Updates to Python DynamoDB provisioning settings. --- .../GettingStarted/scenario_getting_started_movies.py | 5 +---- .../example_code/dynamodb/TryDax/01-create-table.py | 2 +- .../example_code/dynamodb/batching/dynamo_batching.py | 11 ++--------- .../dynamodb/batching/test/test_dynamo_batching.py | 2 +- python/example_code/dynamodb/partiql/scaffold.py | 5 +---- python/test_tools/dynamodb_stubber.py | 7 ++----- 6 files changed, 8 insertions(+), 24 deletions(-) diff --git a/python/example_code/dynamodb/GettingStarted/scenario_getting_started_movies.py b/python/example_code/dynamodb/GettingStarted/scenario_getting_started_movies.py index 76a28591386..6471f786a27 100644 --- a/python/example_code/dynamodb/GettingStarted/scenario_getting_started_movies.py +++ b/python/example_code/dynamodb/GettingStarted/scenario_getting_started_movies.py @@ -118,10 +118,7 @@ def create_table(self, table_name): {"AttributeName": "year", "AttributeType": "N"}, {"AttributeName": "title", "AttributeType": "S"}, ], - ProvisionedThroughput={ - "ReadCapacityUnits": 10, - "WriteCapacityUnits": 10, - }, + BillingMode='PAY_PER_REQUEST', ) self.table.wait_until_exists() except ClientError as err: diff --git a/python/example_code/dynamodb/TryDax/01-create-table.py b/python/example_code/dynamodb/TryDax/01-create-table.py index a301a44d086..ec03e9afc16 100644 --- a/python/example_code/dynamodb/TryDax/01-create-table.py +++ b/python/example_code/dynamodb/TryDax/01-create-table.py @@ -33,7 +33,7 @@ def create_dax_table(dyn_resource=None): {"AttributeName": "partition_key", "AttributeType": "N"}, {"AttributeName": "sort_key", "AttributeType": "N"}, ], - "ProvisionedThroughput": {"ReadCapacityUnits": 10, "WriteCapacityUnits": 10}, + "BillingMode": "PAY_PER_REQUEST", } table = dyn_resource.create_table(**params) print(f"Creating {table_name}...") diff --git a/python/example_code/dynamodb/batching/dynamo_batching.py b/python/example_code/dynamodb/batching/dynamo_batching.py index f3bec87811a..f05bb4759c1 100644 --- a/python/example_code/dynamodb/batching/dynamo_batching.py +++ b/python/example_code/dynamodb/batching/dynamo_batching.py @@ -50,7 +50,7 @@ def create_table(table_name, schema): {"AttributeName": item["name"], "AttributeType": item["type"]} for item in schema ], - ProvisionedThroughput={"ReadCapacityUnits": 10, "WriteCapacityUnits": 10}, + BillingMode='PAY_PER_REQUEST', ) table.wait_until_exists() logger.info("Created table %s.", table.name) @@ -194,14 +194,7 @@ def archive_movies(movie_table, movie_data): TableName=f"{movie_table.name}-archive", KeySchema=movie_table.key_schema, AttributeDefinitions=movie_table.attribute_definitions, - ProvisionedThroughput={ - "ReadCapacityUnits": movie_table.provisioned_throughput[ - "ReadCapacityUnits" - ], - "WriteCapacityUnits": movie_table.provisioned_throughput[ - "WriteCapacityUnits" - ], - }, + BillingMode='PAY_PER_REQUEST', ) logger.info("Table %s created, wait until exists.", archive_table.name) archive_table.wait_until_exists() diff --git a/python/example_code/dynamodb/batching/test/test_dynamo_batching.py b/python/example_code/dynamodb/batching/test/test_dynamo_batching.py index 8f032cc8b9a..fc3c65da42b 100644 --- a/python/example_code/dynamodb/batching/test/test_dynamo_batching.py +++ b/python/example_code/dynamodb/batching/test/test_dynamo_batching.py @@ -27,7 +27,7 @@ def test_create_table( with stub_runner(error_code, stop_on_method) as runner: runner.add( - dyn_stubber.stub_create_table, table_name, schema, {"read": 10, "write": 10} + dyn_stubber.stub_create_table, table_name, schema ) runner.add(dyn_stubber.stub_describe_table, table_name) diff --git a/python/example_code/dynamodb/partiql/scaffold.py b/python/example_code/dynamodb/partiql/scaffold.py index d1e5c8cdfbc..db1503042a6 100644 --- a/python/example_code/dynamodb/partiql/scaffold.py +++ b/python/example_code/dynamodb/partiql/scaffold.py @@ -46,10 +46,7 @@ def create_table(self, table_name): {"AttributeName": "year", "AttributeType": "N"}, {"AttributeName": "title", "AttributeType": "S"}, ], - ProvisionedThroughput={ - "ReadCapacityUnits": 10, - "WriteCapacityUnits": 10, - }, + BillingMode='PAY_PER_REQUEST', ) self.table.wait_until_exists() except ClientError as err: diff --git a/python/test_tools/dynamodb_stubber.py b/python/test_tools/dynamodb_stubber.py index c8fd770198a..e698c6ecac9 100644 --- a/python/test_tools/dynamodb_stubber.py +++ b/python/test_tools/dynamodb_stubber.py @@ -77,12 +77,9 @@ def _build_out_item(self, in_item): out_item[key] = {value_type: out_val} return out_item - def stub_create_table(self, table_name, schema, throughput, error_code=None): + def stub_create_table(self, table_name, schema, error_code=None): table_input = { - "ProvisionedThroughput": { - "ReadCapacityUnits": throughput["read"], - "WriteCapacityUnits": throughput["write"], - } + "BillingMode": "PAY_PER_REQUEST", } self._add_table_schema(table_input, table_name, schema) From ca7d657a1748d73dd1347c56045d536bf4920234 Mon Sep 17 00:00:00 2001 From: Rachel Hagerman <110480692+rlhagerm@users.noreply.github.com> Date: Mon, 3 Mar 2025 10:44:09 -0600 Subject: [PATCH 2/2] Update README.md --- python/example_code/dynamodb/README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/python/example_code/dynamodb/README.md b/python/example_code/dynamodb/README.md index b3d81a5cda4..b52cb936492 100644 --- a/python/example_code/dynamodb/README.md +++ b/python/example_code/dynamodb/README.md @@ -52,18 +52,18 @@ Code excerpts that show you how to call individual service functions. - [BatchExecuteStatement](partiql/scenario_partiql_batch.py#L44) - [BatchGetItem](batching/dynamo_batching.py#L64) -- [BatchWriteItem](GettingStarted/scenario_getting_started_movies.py#L164) +- [BatchWriteItem](GettingStarted/scenario_getting_started_movies.py#L161) - [CreateTable](GettingStarted/scenario_getting_started_movies.py#L100) -- [DeleteItem](GettingStarted/scenario_getting_started_movies.py#L342) -- [DeleteTable](GettingStarted/scenario_getting_started_movies.py#L363) +- [DeleteItem](GettingStarted/scenario_getting_started_movies.py#L339) +- [DeleteTable](GettingStarted/scenario_getting_started_movies.py#L360) - [DescribeTable](GettingStarted/scenario_getting_started_movies.py#L70) - [ExecuteStatement](partiql/scenario_partiql_single.py#L43) -- [GetItem](GettingStarted/scenario_getting_started_movies.py#L223) -- [ListTables](GettingStarted/scenario_getting_started_movies.py#L140) -- [PutItem](GettingStarted/scenario_getting_started_movies.py#L193) -- [Query](GettingStarted/scenario_getting_started_movies.py#L280) -- [Scan](GettingStarted/scenario_getting_started_movies.py#L303) -- [UpdateItem](GettingStarted/scenario_getting_started_movies.py#L248) +- [GetItem](GettingStarted/scenario_getting_started_movies.py#L220) +- [ListTables](GettingStarted/scenario_getting_started_movies.py#L137) +- [PutItem](GettingStarted/scenario_getting_started_movies.py#L190) +- [Query](GettingStarted/scenario_getting_started_movies.py#L277) +- [Scan](GettingStarted/scenario_getting_started_movies.py#L300) +- [UpdateItem](GettingStarted/scenario_getting_started_movies.py#L245) ### Scenarios