From 04bd78f6f406f477d1c280e09b6f64037dbe41e8 Mon Sep 17 00:00:00 2001 From: rtrive Date: Sat, 27 Mar 2021 19:11:12 +0100 Subject: [PATCH 1/6] Dynamodb endpoint_url for local testing --- aws_lambda_powertools/utilities/parameters/dynamodb.py | 3 ++- docs/utilities/parameters.md | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/parameters/dynamodb.py b/aws_lambda_powertools/utilities/parameters/dynamodb.py index a4b05121aa2..7e8080229bd 100644 --- a/aws_lambda_powertools/utilities/parameters/dynamodb.py +++ b/aws_lambda_powertools/utilities/parameters/dynamodb.py @@ -150,6 +150,7 @@ def __init__( key_attr: str = "id", sort_attr: str = "sk", value_attr: str = "value", + endpoint_url: Optional[str] = None, config: Optional[Config] = None, ): """ @@ -157,7 +158,7 @@ def __init__( """ config = config or Config() - self.table = boto3.resource("dynamodb", config=config).Table(table_name) + self.table = boto3.resource("dynamodb", endpoint_url=endpoint_url, config=config).Table(table_name) self.key_attr = key_attr self.sort_attr = sort_attr diff --git a/docs/utilities/parameters.md b/docs/utilities/parameters.md index e50f3f85b81..787a4ed10c2 100644 --- a/docs/utilities/parameters.md +++ b/docs/utilities/parameters.md @@ -196,6 +196,15 @@ The AWS Systems Manager Parameter Store provider supports two additional argumen The DynamoDB Provider does not have any high-level functions, as it needs to know the name of the DynamoDB table containing the parameters. +**Local testing with DynamoDB** + +You can initiliazare DynamoDB provider for [local dynamodb](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html) with this configuration: +```python hl_lines="3 7" +from aws_lambda_powertools.utilities import parameters + +dynamodb_provider = parameters.DynamoDBProvider(table_name="my-table", endpoint_url: "http://localhost:8000") +``` + **DynamoDB table structure for single parameters** For single parameters, you must use `id` as the [partition key](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.CoreComponents.html#HowItWorks.CoreComponents.PrimaryKey) for that table. From dc273f7e6cf2e31aa31d4ed1af8a20cd7885a9cb Mon Sep 17 00:00:00 2001 From: rtrive Date: Tue, 30 Mar 2021 19:39:56 +0200 Subject: [PATCH 2/6] Add endpoint_url parameter on docstring --- aws_lambda_powertools/utilities/parameters/dynamodb.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/aws_lambda_powertools/utilities/parameters/dynamodb.py b/aws_lambda_powertools/utilities/parameters/dynamodb.py index 7e8080229bd..6df3e8314ee 100644 --- a/aws_lambda_powertools/utilities/parameters/dynamodb.py +++ b/aws_lambda_powertools/utilities/parameters/dynamodb.py @@ -26,6 +26,8 @@ class DynamoDBProvider(BaseProvider): Name of the DynamoDB table sort key (defaults to 'sk'), used only for get_multiple value_attr: str, optional Attribute that contains the values in the DynamoDB table (defaults to 'value') + endpoint_url: str, optional + Complete url to reference local DynamoDB instance config: botocore.config.Config, optional Botocore configuration to pass during client initialization From c2f5e96dce0b07d255c47022f88d57502eb69484 Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Wed, 31 Mar 2021 08:31:49 +0200 Subject: [PATCH 3/6] docs: fix typo and project name Signed-off-by: heitorlessa --- docs/utilities/parameters.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/utilities/parameters.md b/docs/utilities/parameters.md index 787a4ed10c2..d3161e2e101 100644 --- a/docs/utilities/parameters.md +++ b/docs/utilities/parameters.md @@ -196,10 +196,11 @@ The AWS Systems Manager Parameter Store provider supports two additional argumen The DynamoDB Provider does not have any high-level functions, as it needs to know the name of the DynamoDB table containing the parameters. -**Local testing with DynamoDB** +##### Local testing with DynamoDB Local -You can initiliazare DynamoDB provider for [local dynamodb](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html) with this configuration: -```python hl_lines="3 7" +You can initialize the DynamoDB provider pointing to [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html) using **`endpoint_url`** parameter: + +```python hl_lines="3" from aws_lambda_powertools.utilities import parameters dynamodb_provider = parameters.DynamoDBProvider(table_name="my-table", endpoint_url: "http://localhost:8000") From ba4b4229e7c487da94bfa28cadc9d7e9a93811a2 Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Wed, 31 Mar 2021 08:33:35 +0200 Subject: [PATCH 4/6] feat: use a tab snippet to standout Signed-off-by: heitorlessa --- docs/utilities/parameters.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/utilities/parameters.md b/docs/utilities/parameters.md index d3161e2e101..c8f156e427f 100644 --- a/docs/utilities/parameters.md +++ b/docs/utilities/parameters.md @@ -196,15 +196,16 @@ The AWS Systems Manager Parameter Store provider supports two additional argumen The DynamoDB Provider does not have any high-level functions, as it needs to know the name of the DynamoDB table containing the parameters. -##### Local testing with DynamoDB Local +**Local testing with DynamoDB Local** You can initialize the DynamoDB provider pointing to [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html) using **`endpoint_url`** parameter: -```python hl_lines="3" -from aws_lambda_powertools.utilities import parameters +=== "dynamodb_local.py" + ```python hl_lines="3" + from aws_lambda_powertools.utilities import parameters -dynamodb_provider = parameters.DynamoDBProvider(table_name="my-table", endpoint_url: "http://localhost:8000") -``` + dynamodb_provider = parameters.DynamoDBProvider(table_name="my-table", endpoint_url: "http://localhost:8000") + ``` **DynamoDB table structure for single parameters** From 7b7f6438779a2678865d4bc2773e635a5e01c25a Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Wed, 31 Mar 2021 08:35:23 +0200 Subject: [PATCH 5/6] fix: endpoint_url parameter syntax Signed-off-by: heitorlessa --- docs/utilities/parameters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/utilities/parameters.md b/docs/utilities/parameters.md index c8f156e427f..5f1d6b4e7bb 100644 --- a/docs/utilities/parameters.md +++ b/docs/utilities/parameters.md @@ -204,7 +204,7 @@ You can initialize the DynamoDB provider pointing to [DynamoDB Local](https://do ```python hl_lines="3" from aws_lambda_powertools.utilities import parameters - dynamodb_provider = parameters.DynamoDBProvider(table_name="my-table", endpoint_url: "http://localhost:8000") + dynamodb_provider = parameters.DynamoDBProvider(table_name="my-table", endpoint_url="http://localhost:8000") ``` **DynamoDB table structure for single parameters** From 576c9eba6555392a1ca00f929b3dc4ce32badbc4 Mon Sep 17 00:00:00 2001 From: heitorlessa Date: Wed, 31 Mar 2021 08:35:50 +0200 Subject: [PATCH 6/6] docs: include example url in docstring --- aws_lambda_powertools/utilities/parameters/dynamodb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/parameters/dynamodb.py b/aws_lambda_powertools/utilities/parameters/dynamodb.py index 6df3e8314ee..5edae643ec0 100644 --- a/aws_lambda_powertools/utilities/parameters/dynamodb.py +++ b/aws_lambda_powertools/utilities/parameters/dynamodb.py @@ -27,7 +27,7 @@ class DynamoDBProvider(BaseProvider): value_attr: str, optional Attribute that contains the values in the DynamoDB table (defaults to 'value') endpoint_url: str, optional - Complete url to reference local DynamoDB instance + Complete url to reference local DynamoDB instance, e.g. http://localhost:8080 config: botocore.config.Config, optional Botocore configuration to pass during client initialization