diff --git a/aws_lambda_powertools/utilities/parameters/dynamodb.py b/aws_lambda_powertools/utilities/parameters/dynamodb.py index a4b05121aa2..5edae643ec0 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, e.g. http://localhost:8080 config: botocore.config.Config, optional Botocore configuration to pass during client initialization @@ -150,6 +152,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 +160,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..5f1d6b4e7bb 100644 --- a/docs/utilities/parameters.md +++ b/docs/utilities/parameters.md @@ -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.