feat: Add option to create SingleTableDatastore from existing DynamoDB table #346
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Extracted a basic interface for ISingleTableDatastore, that is implemented by SingleTableDatastore, so the udnerlying datastore can be created in other ways.
SingleTableDatastorewill create its ownaws_dynamodb.Tableinstance and expose only a limited amount of the settings. There is no way around this without either reaching into the CDK's escape hatch, or foregoing cdk-serverless' Single Table Datastore setup entirely.This change introduces a static method
SingleTableDatastore.fromTablethat takes an existingaws_dynamodb.Tableinstance and creates an implementation ofISingleTableDatastorethat can be injected into cdk-serverless API constructs, allowing advanced users to configure a DynamoDB table on their own and use it within cdk-serverless.SingleTableDatastorenow implements the interfaceISingleTableDatastoreand the base API construct now expects that interface instead of the concrete implementation. Right now I do not see this breaking existing uses.Other information:
I considered generalizing the type of
aws_dynamodb.Tableto its interface to allow the use of imported tables, but felt this was out of scope, as this might break common use cases where users access the table instance insideSingleTableDatastoreafter creation.Alternatively, overhauling the
SingleTableDatastorePropsto expose most or all of the underlyingaws_dynamodb.TablePropswould be an option, but could create more friction with the existing API.The project only unit-tests projen components, not CDK constructs. Is this desired? This change is simple, but so would testing proper stack creation be.