Skip to content

Commit

Permalink
feat(parameter): add dynamodb_endpoint_url for local_testing (#376)
Browse files Browse the repository at this point in the history
* Dynamodb endpoint_url for local testing

* Add endpoint_url parameter on docstring

* docs: fix typo and project name

Signed-off-by: heitorlessa <[email protected]>

* feat: use a tab snippet to standout

Signed-off-by: heitorlessa <[email protected]>

* fix: endpoint_url parameter syntax

Signed-off-by: heitorlessa <[email protected]>

* docs: include example url in docstring

Co-authored-by: heitorlessa <[email protected]>
  • Loading branch information
rtrive and heitorlessa authored Mar 31, 2021
1 parent 9a86321 commit 1b5d46a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion aws_lambda_powertools/utilities/parameters/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, e.g. http://localhost:8080
config: botocore.config.Config, optional
Botocore configuration to pass during client initialization
Expand Down Expand Up @@ -150,14 +152,15 @@ def __init__(
key_attr: str = "id",
sort_attr: str = "sk",
value_attr: str = "value",
endpoint_url: Optional[str] = None,
config: Optional[Config] = None,
):
"""
Initialize the DynamoDB client
"""

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
Expand Down
11 changes: 11 additions & 0 deletions docs/utilities/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ 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**

You can initialize the DynamoDB provider pointing to [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html) using **`endpoint_url`** parameter:

=== "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 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.
Expand Down

0 comments on commit 1b5d46a

Please sign in to comment.