diff --git a/docs/utilities/idempotency.md b/docs/utilities/idempotency.md index 466058dacef..81afa8b0117 100644 --- a/docs/utilities/idempotency.md +++ b/docs/utilities/idempotency.md @@ -1221,7 +1221,7 @@ with a truthy value. If you prefer setting this for specific tests, and are usin ### Testing with DynamoDB Local -To test with [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html), you can replace the `Table` resource used by the persistence layer with one you create inside your tests. This allows you to set the endpoint_url. +To test with [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html), you can replace the `DynamoDB client` used by the persistence layer with one you create inside your tests. This allows you to set the endpoint_url. === "tests.py" @@ -1249,10 +1249,12 @@ To test with [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/ return LambdaContext() def test_idempotent_lambda(lambda_context): - # Create our own Table resource using the endpoint for our DynamoDB Local instance - resource = boto3.resource("dynamodb", endpoint_url='http://localhost:8000') - table = resource.Table(app.persistence_layer.table_name) - app.persistence_layer.table = table + # Configure the boto3 to use the endpoint for the DynamoDB Local instance + dynamodb_local_client = boto3.client("dynamodb", endpoint_url='http://localhost:8000') + app.persistence_layer.client = dynamodb_local_client + + # If desired, you can use a different DynamoDB Local table name than what your code already uses + # app.persistence_layer.table_name = "another table name" result = app.handler({'testkey': 'testvalue'}, lambda_context) assert result['payment_id'] == 12345 @@ -1310,10 +1312,10 @@ This means it is possible to pass a mocked Table resource, or stub various metho def test_idempotent_lambda(lambda_context): - table = MagicMock() - app.persistence_layer.table = table + mock_client = MagicMock() + app.persistence_layer.client = mock_client result = app.handler({'testkey': 'testvalue'}, lambda_context) - table.put_item.assert_called() + mock_client.put_item.assert_called() ... ```