-
Notifications
You must be signed in to change notification settings - Fork 250
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
fix(allow ITable for dynamodb stream patterns) #214
Conversation
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
@@ -69,7 +69,7 @@ export interface DynamoDBStreamToLambdaProps { | |||
|
|||
export class DynamoDBStreamToLambda extends Construct { | |||
public readonly lambdaFunction: lambda.Function; | |||
public readonly dynamoTable: dynamodb.Table; | |||
public readonly dynamoTable?: dynamodb.Table; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expose both this as an optional property as well as the ITable, which will always exist. Then we need to document well when the Table object would be available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting something like this:
public readonly dynamoTable?: dynamodb.Table;
public readonly dynamoTableInterface?: dynamodb.ITable;
where dynamoTable
will be available if the user user provides dynamoTableProps
or existingTableObj
of type Table
and dynamoTableInterface
will be available if the user provides existingTableObj
of type ITable
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking:
public readonly dynamoTable?: dynamodb.Table;
public readonly dynamoTableInterface: dynamodb.ITable;
(making as much info as possible available). But I hadn't thought about names, that's unfortunate.
As I recall, if the client supplies existingTableObject the code currently returns ITable regardless of what was passed to the ITable parameter. This is actually pretty sticky - why don't you set up a meeting tomorrow morning for you, Ryan and me to toss around ideas. The cleanest solution would be to go ITable for everything about this construct - the only drawback is that if someone needs the table somewhere else they can't use it. The workaround would be to create the table somewhere else (either independently or as part of another construct).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, cannot go with ITable
for everything then the user won't be able to make mutating calls on dynamoTable
property e.g. dynamoTable.addGlobalSecondaryIndex()
, also it will break the existing customer's code..
dynamoTableProps: props.dynamoTableProps, | ||
existingTableObj: props.existingTableObj | ||
}); | ||
|
||
if (table instanceof dynamodb.Table) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The definition of buildDynamoDBTableWithStream
is:
export function buildDynamoDBTableWithStream(scope: cdk.Construct, props: BuildDynamoDBTableWithStreamProps): dynamodb.ITable {
Typescript sees this and will never trigger this condition (pretty sure instanceof isn't fully functional at runtime as the code actually runs as JavaScript with no type information). Either way, the function will never return a Table.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First thought suggestion, define the function as:
export function buildDynamoDBTableWithStream(scope: cdk.Construct, props: BuildDynamoDBTableWithStreamProps): [ dynamodb.ITable, dynamodbTable ] {
Then return everything you can from the from the function (either ITable, undefined or ITable, Table). Assign both to properties of the construct (and stressing again to explain the difference in the docs). I'm not a fan of this operator to return multiple values, but it seems to work here. There may be a better way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
@@ -73,7 +73,8 @@ _Parameters_ | |||
|
|||
| **Name** | **Type** | **Description** | | |||
|:-------------|:----------------|-----------------| | |||
|dynamoTable|[`dynamodb.Table`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.Table.html)|Returns an instance of dynamodb.Table created by the construct| | |||
|dynamoTableInterface|[`dynamodb.ITable`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.ITable.html)|Returns an instance of dynamodb.ITable created by the construct| | |||
|dynamoTable?|[`dynamodb.Table`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.Table.html)|Returns an instance of dynamodb.Table created by the construct| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add:
Returns an instance of dynamodb.Table created by the construct. IMPORTANT: If existingTableInterface was provided in the props object, this property will be undefined.
|dynamoEventSourceProps?|[`aws-lambda-event-sources.DynamoEventSourceProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda-event-sources.DynamoEventSourceProps.html)|Optional user provided props to override the default props for DynamoDB Event Source| | ||
|
||
## Pattern Properties | ||
|
||
| **Name** | **Type** | **Description** | | ||
|:-------------|:----------------|-----------------| | ||
|dynamoTable|[`dynamodb.Table`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.Table.html)|Returns an instance of dynamodb.Table created by the construct| | ||
|dynamoTableInterface|[`dynamodb.ITable`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.ITable.html)|Returns an instance of dynamodb.ITable created by the construct| | ||
|dynamoTable?|[`dynamodb.Table`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.Table.html)|Returns an instance of dynamodb.Table created by the construct| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment
@@ -90,11 +91,12 @@ export class DynamoDBStreamToLambda extends Construct { | |||
|
|||
const table: dynamodb.ITable = defaults.buildDynamoDBTableWithStream(this, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Purposefully pointing to an object as the wrong type seems a little cheesy (and fraught with peril). I like the returning 2 values approach better. It also allows cleaner code in this routine, as this line could be"
[dynamoTableInterface, dynamoTable] = defaults.buildDynamoDBTableWithStream(...
Lines 97-99 are then no longer needed
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Issue #, if available: 119
Description of changes:
Allow users to pass
dynamodb.ITable
for in construct propsexistingTableObj
for dynamodb stream patternsBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.