-
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
Changes from 3 commits
7451a9a
172e127
8ff9b21
774b75c
aa9da31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,14 +58,15 @@ _Parameters_ | |
|existingLambdaObj?|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Existing instance of Lambda Function object, providing both this and `lambdaFunctionProps` will cause an error.| | ||
|lambdaFunctionProps?|[`lambda.FunctionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.FunctionProps.html)|User provided props to override the default props for the Lambda function.| | ||
|dynamoTableProps?|[`dynamodb.TableProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.TableProps.html)|Optional user provided props to override the default props for DynamoDB Table| | ||
|existingTableObj?|[`dynamodb.Table`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.Table.html)|Existing instance of DynamoDB table object, providing both this and `dynamoTableProps` will cause an error.| | ||
|existingTableInterface?|[`dynamodb.ITable`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-dynamodb.ITable.html)|Existing instance of DynamoDB table object or interface, providing both this and `dynamoTableProps` will cause an error.| | ||
|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 commentThe reason will be displayed to describe this comment to others. Learn more. Same comment |
||
|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct| | ||
|
||
## Lambda Function | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,7 +45,7 @@ export interface DynamoDBStreamToLambdaProps { | |
* | ||
* @default - None | ||
*/ | ||
readonly existingTableObj?: dynamodb.Table, | ||
readonly existingTableInterface?: dynamodb.ITable, | ||
/** | ||
* Optional user provided props to override the default props | ||
* | ||
|
@@ -69,7 +69,8 @@ export interface DynamoDBStreamToLambdaProps { | |
|
||
export class DynamoDBStreamToLambda extends Construct { | ||
public readonly lambdaFunction: lambda.Function; | ||
public readonly dynamoTable: dynamodb.Table; | ||
public readonly dynamoTableInterface: dynamodb.ITable; | ||
public readonly dynamoTable?: dynamodb.Table; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Are you suggesting something like this:
where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking:
(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 commentThe reason will be displayed to describe this comment to others. Learn more. Yep, cannot go with |
||
|
||
/** | ||
* @summary Constructs a new instance of the LambdaToDynamoDB class. | ||
|
@@ -88,20 +89,25 @@ export class DynamoDBStreamToLambda extends Construct { | |
lambdaFunctionProps: props.lambdaFunctionProps | ||
}); | ||
|
||
this.dynamoTable = defaults.buildDynamoDBTableWithStream(this, { | ||
const table: dynamodb.ITable = defaults.buildDynamoDBTableWithStream(this, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"
Lines 97-99 are then no longer needed |
||
dynamoTableProps: props.dynamoTableProps, | ||
existingTableObj: props.existingTableObj | ||
existingTableInterface: props.existingTableInterface | ||
}); | ||
|
||
this.dynamoTableInterface = table; | ||
if (!props.existingTableInterface) { | ||
this.dynamoTable = table as dynamodb.Table; | ||
} | ||
|
||
// Grant DynamoDB Stream read perimssion for lambda function | ||
this.dynamoTable.grantStreamRead(this.lambdaFunction.grantPrincipal); | ||
table.grantStreamRead(this.lambdaFunction.grantPrincipal); | ||
|
||
// Add the Lambda event source mapping | ||
const eventSourceProps = defaults.DynamoEventSourceProps(this, { | ||
eventSourceProps: props.dynamoEventSourceProps, | ||
deploySqsDlqQueue: props.deploySqsDlqQueue, | ||
sqsDlqQueueProps: props.sqsDlqQueueProps | ||
}); | ||
this.lambdaFunction.addEventSource(new DynamoEventSource(this.dynamoTable, eventSourceProps)); | ||
this.lambdaFunction.addEventSource(new DynamoEventSource(table, eventSourceProps)); | ||
} | ||
} |
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.