Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(parameters): DynamoDBProvider support #1202

Merged
merged 7 commits into from
Jan 6, 2023

Conversation

dreamorosi
Copy link
Contributor

@dreamorosi dreamorosi commented Dec 28, 2022

Description of your changes

This PR implements the DynamoDBProvider class which will allow the future Parameters utility to support retrieving parameters from DynamoDB.

The DynamoDBProvider supports the following retrieval modes:

  • get this class method allows customers to retrieve a single parameter by name and allows to specify transform, max age.

The provider comes with defaults thanks to which the user only has to specify the table name and the the name of the parameter to retrieve:

const parameters = new DynamoDBProvider({
  tableName: 'some-table'
});

The table named some-table expects an item that looks like this:

{ "id": "foo", "value": "bar" }

However, if users have items with other type of shapes, like for instance:

{ "key": "foo", "val": "bar" }

they can instantiate the provider like so:

const parameters = new DynamoDBProvider({
  tableName: 'some-table',
  keyAttr: 'key',
  valueAttr: 'val',
});

In both cases, they can retrieve the parameter using the get method:

const parameter = parameters.get('foo');
console.log(parameter); // bar
  • getMultiple this class method allows customers to retrieve multiple parameters by path and allows to specify a shared config object that changes the behavior around transform, max age.

Similarly to what described above, the default come also for path-based retrieval:

const parameters = new DynamoDBProvider({
  tableName: 'some-table'
});

The table named some-table expects an item that looks like this:

{ "id": "foo", "sk": "a", "value": "value-param-a" }
{ "id": "foo", "sk": "b", "value": "value-param-b" }

Which will result, when used, in this:

const parameterObject = parameters.getMultiple('foo');
for (const [ key, val ] of Object.entries(parameterObject)) {
  console.log(key, val);
}
// a, value-param-a
// b, value-param-b

Just like before, if users have items with a different shape, say this:

{ "key": "foo", "sort": "a", "val": "value-param-a" }
{ "key": "foo", "sort": "b", "val": "value-param-b" }

They can customize the provider's behavior by instantiating it with different attribute names:

const parameters = new DynamoDBProvider({
  tableName: 'some-table',
  keyAttr: 'key',
  valueAttr: 'val',
  sortAttr: 'sort',
});

Both get and getMultiple also allow an optional options argument that allow to customize the provider's behavior around caching and transform/errors.

The options object also accepts a sdkOptions object, which allows the user to pass additional inputs to the SDK client API call (i.e. specify ConsistentRead). There are however some SDK options that cannot be passed as they are managed by the provider, these are:

  • TableName
  • ProjectionExpression
  • Key (applies only to get)
  • KeyConditionExpression (applies only to getMultiple)
  • ExpressionAttributeValues (applies only to getMultiple)

How to verify this change

See the newly added unit test cases & optionally compare also the API surface with the implementation found in Powertools for Python.

Related issues, RFCs

Issue number: #1174

PR status

Is this ready for review?: YES
Is it a breaking change?: NO

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding changes to the examples
  • My changes generate no new warnings
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • Any dependent changes have been merged and published
  • The PR title follows the conventional commit semantics

Breaking change checklist

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@dreamorosi dreamorosi self-assigned this Dec 28, 2022
@dreamorosi dreamorosi linked an issue Dec 28, 2022 that may be closed by this pull request
4 tasks
@pull-request-size pull-request-size bot added the size/XL PRs between 500-999 LOC, often PRs that grown with feedback label Dec 28, 2022
@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Dec 28, 2022
@dreamorosi dreamorosi added the parameters This item relates to the Parameters Utility label Dec 28, 2022
kennethwkz-mm
kennethwkz-mm previously approved these changes Dec 29, 2022
Copy link

@kennethwkz-mm kennethwkz-mm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really nice to have

@dreamorosi dreamorosi force-pushed the 1174-feature-request-implement-dynamodbprovider branch from 8736473 to 0aa6b56 Compare December 29, 2022 16:47
@dreamorosi dreamorosi force-pushed the 1174-feature-request-implement-dynamodbprovider branch 3 times, most recently from 2446278 to a777f0b Compare January 5, 2023 20:12
@dreamorosi dreamorosi force-pushed the 1174-feature-request-implement-dynamodbprovider branch from a777f0b to 9e1c6c6 Compare January 6, 2023 17:07
@dreamorosi dreamorosi merged commit db94850 into main Jan 6, 2023
@dreamorosi dreamorosi deleted the 1174-feature-request-implement-dynamodbprovider branch January 6, 2023 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature PRs that introduce new features or minor changes parameters This item relates to the Parameters Utility size/XL PRs between 500-999 LOC, often PRs that grown with feedback
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: implement DynamoDBProvider
2 participants