Skip to content

Commit 1b5d46a

Browse files
rtriveheitorlessa
andauthored
feat(parameter): add dynamodb_endpoint_url for local_testing (#376)
* 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]>
1 parent 9a86321 commit 1b5d46a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: aws_lambda_powertools/utilities/parameters/dynamodb.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ class DynamoDBProvider(BaseProvider):
2626
Name of the DynamoDB table sort key (defaults to 'sk'), used only for get_multiple
2727
value_attr: str, optional
2828
Attribute that contains the values in the DynamoDB table (defaults to 'value')
29+
endpoint_url: str, optional
30+
Complete url to reference local DynamoDB instance, e.g. http://localhost:8080
2931
config: botocore.config.Config, optional
3032
Botocore configuration to pass during client initialization
3133
@@ -150,14 +152,15 @@ def __init__(
150152
key_attr: str = "id",
151153
sort_attr: str = "sk",
152154
value_attr: str = "value",
155+
endpoint_url: Optional[str] = None,
153156
config: Optional[Config] = None,
154157
):
155158
"""
156159
Initialize the DynamoDB client
157160
"""
158161

159162
config = config or Config()
160-
self.table = boto3.resource("dynamodb", config=config).Table(table_name)
163+
self.table = boto3.resource("dynamodb", endpoint_url=endpoint_url, config=config).Table(table_name)
161164

162165
self.key_attr = key_attr
163166
self.sort_attr = sort_attr

Diff for: docs/utilities/parameters.md

+11
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,17 @@ The AWS Systems Manager Parameter Store provider supports two additional argumen
196196

197197
The DynamoDB Provider does not have any high-level functions, as it needs to know the name of the DynamoDB table containing the parameters.
198198

199+
**Local testing with DynamoDB Local**
200+
201+
You can initialize the DynamoDB provider pointing to [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html) using **`endpoint_url`** parameter:
202+
203+
=== "dynamodb_local.py"
204+
```python hl_lines="3"
205+
from aws_lambda_powertools.utilities import parameters
206+
207+
dynamodb_provider = parameters.DynamoDBProvider(table_name="my-table", endpoint_url="http://localhost:8000")
208+
```
209+
199210
**DynamoDB table structure for single parameters**
200211

201212
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.

0 commit comments

Comments
 (0)