Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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