From 96ca3c31d8a98cbeea233683e5564abcc3a48093 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Fri, 31 Mar 2023 00:51:47 +0100 Subject: [PATCH 1/6] docs(idempotency) - boto3 example --- docs/utilities/idempotency.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/utilities/idempotency.md b/docs/utilities/idempotency.md index 49a028168b3..9241335e122 100644 --- a/docs/utilities/idempotency.md +++ b/docs/utilities/idempotency.md @@ -1087,7 +1087,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 table` used by the persistence layer with one you create inside your tests. This allows you to set the endpoint_url. === "tests.py" @@ -1115,10 +1115,10 @@ 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 + resource = boto3.client("dynamodb", endpoint_url='http://localhost:8000') + # If desired, change the name of the DynamoDB table used by the persistence layer to one you created locally + app.persistence_layer.table_name = "localtable" result = app.handler({'testkey': 'testvalue'}, lambda_context) assert result['payment_id'] == 12345 From cf0b55485735dd3c9dcef39b0a6b252cc33b6889 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Sat, 1 Apr 2023 23:03:33 +0100 Subject: [PATCH 2/6] docs(idempotency) - boto3 example --- docs/utilities/idempotency.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/utilities/idempotency.md b/docs/utilities/idempotency.md index b1caf076e90..72ef795ed87 100644 --- a/docs/utilities/idempotency.md +++ b/docs/utilities/idempotency.md @@ -1251,8 +1251,9 @@ To test with [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/ def test_idempotent_lambda(lambda_context): # Configure the boto3 to use the endpoint for the DynamoDB Local instance resource = boto3.client("dynamodb", endpoint_url='http://localhost:8000') - # If desired, change the name of the DynamoDB table used by the persistence layer to one you created locally - app.persistence_layer.table_name = "localtable" + # If desired, change the value of the table_name variable to set the name of the DynamoDB table used by the persistence layer to one you created locally + table_name = app.persistence_layer.table_name + app.persistence_layer.table_name = table_name result = app.handler({'testkey': 'testvalue'}, lambda_context) assert result['payment_id'] == 12345 From 46bb5c6ad5fcd6a9b011e62c54e61cd10a159d0a Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Mon, 3 Apr 2023 18:55:22 +0100 Subject: [PATCH 3/6] docs(idempotency) - fix dynamodb client object --- docs/utilities/idempotency.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/utilities/idempotency.md b/docs/utilities/idempotency.md index 72ef795ed87..dc75eb90f7f 100644 --- a/docs/utilities/idempotency.md +++ b/docs/utilities/idempotency.md @@ -1251,6 +1251,8 @@ To test with [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/ def test_idempotent_lambda(lambda_context): # Configure the boto3 to use the endpoint for the DynamoDB Local instance resource = boto3.client("dynamodb", endpoint_url='http://localhost:8000') + app.persistence_layer._client = resource + # If desired, change the value of the table_name variable to set the name of the DynamoDB table used by the persistence layer to one you created locally table_name = app.persistence_layer.table_name app.persistence_layer.table_name = table_name From f62a1e41a1d74220718d46f495d05cd27ab8a089 Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Wed, 5 Apr 2023 13:17:02 +0200 Subject: [PATCH 4/6] docs: correct table name swap; comment out --- docs/utilities/idempotency.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/utilities/idempotency.md b/docs/utilities/idempotency.md index dc75eb90f7f..a218b00d41e 100644 --- a/docs/utilities/idempotency.md +++ b/docs/utilities/idempotency.md @@ -1253,9 +1253,8 @@ To test with [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/ resource = boto3.client("dynamodb", endpoint_url='http://localhost:8000') app.persistence_layer._client = resource - # If desired, change the value of the table_name variable to set the name of the DynamoDB table used by the persistence layer to one you created locally - table_name = app.persistence_layer.table_name - app.persistence_layer.table_name = table_name + # 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 From 9ebac427bd81ba0a766ec2db94f5c5da4676889f Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Wed, 5 Apr 2023 18:21:36 +0200 Subject: [PATCH 5/6] docs: fix mock example; use new public client attr --- docs/utilities/idempotency.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/utilities/idempotency.md b/docs/utilities/idempotency.md index a218b00d41e..14dc3f6c098 100644 --- a/docs/utilities/idempotency.md +++ b/docs/utilities/idempotency.md @@ -1250,8 +1250,8 @@ To test with [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/ def test_idempotent_lambda(lambda_context): # Configure the boto3 to use the endpoint for the DynamoDB Local instance - resource = boto3.client("dynamodb", endpoint_url='http://localhost:8000') - app.persistence_layer._client = resource + 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" @@ -1312,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() ... ``` From 426718d01a70b7a356382b0fa7dee885b622f57c Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Wed, 5 Apr 2023 18:27:54 +0200 Subject: [PATCH 6/6] docs: fix wording --- docs/utilities/idempotency.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/utilities/idempotency.md b/docs/utilities/idempotency.md index 14dc3f6c098..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 `DynamoDB table` 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"