diff --git a/source/patterns/@aws-solutions-constructs/core/lib/dynamodb-table-helper.ts b/source/patterns/@aws-solutions-constructs/core/lib/dynamodb-table-helper.ts index 479fc1b25..3dd8bf229 100644 --- a/source/patterns/@aws-solutions-constructs/core/lib/dynamodb-table-helper.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/dynamodb-table-helper.ts @@ -58,7 +58,9 @@ export interface BuildDynamoDBTableWithStreamProps { export function buildDynamoDBTable(scope: Construct, props: BuildDynamoDBTableProps): [dynamodb.ITable, dynamodb.Table?] { // Conditional DynamoDB Table creation - if (props.existingTableObj) { + if (props.existingTableObj && props.existingTableInterface) { + throw new Error('Error - Either provide existingTableInterface or existingTableObj, but not both.'); + } else if (props.existingTableObj) { return [props.existingTableObj, props.existingTableObj]; } else if (props.existingTableInterface) { return [props.existingTableInterface, undefined]; diff --git a/source/patterns/@aws-solutions-constructs/core/lib/input-validation.ts b/source/patterns/@aws-solutions-constructs/core/lib/input-validation.ts index 5945ab497..8d130f9ca 100644 --- a/source/patterns/@aws-solutions-constructs/core/lib/input-validation.ts +++ b/source/patterns/@aws-solutions-constructs/core/lib/input-validation.ts @@ -97,11 +97,6 @@ export function CheckProps(propsObject: VerifiedProps | any) { errorFound = true; } - if (propsObject.existingTableObj && propsObject.existingTableInterface) { - errorMessages += 'Error - Either provide existingTableInterface or existingTableObj, but not both.\n'; - errorFound = true; - } - if (propsObject.existingStreamObj && propsObject.kinesisStreamProps) { errorMessages += 'Error - Either provide existingStreamObj or kinesisStreamProps, but not both.\n'; errorFound = true; diff --git a/source/patterns/@aws-solutions-constructs/core/test/dynamo-table.test.ts b/source/patterns/@aws-solutions-constructs/core/test/dynamo-table.test.ts index 1ba6fb8fd..21c907849 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/dynamo-table.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/dynamo-table.test.ts @@ -390,3 +390,27 @@ test('test getPartitionKeyNameFromTable()', () => { expect(testKeyName).toEqual(partitionKeyName); }); + +test('Test providing both existingTableInterface and existingTableObj', () => { + const stack = new Stack(); + + const tableProps: dynamodb.TableProps = { + partitionKey: { + name: 'table_id', + type: dynamodb.AttributeType.STRING + }, + stream: dynamodb.StreamViewType.NEW_IMAGE + }; + + const existingTableInterface = new dynamodb.Table(stack, 'DynamoTable', tableProps) + ; + const newProps = { + existingTableInterface, + existingTableObj: existingTableInterface + }; + const app = () => { + defaults.buildDynamoDBTable(stack, newProps); + }; + + expect(app).toThrowError('Error - Either provide existingTableInterface or existingTableObj, but not both.'); +}); \ No newline at end of file diff --git a/source/patterns/@aws-solutions-constructs/core/test/input-validation.test.ts b/source/patterns/@aws-solutions-constructs/core/test/input-validation.test.ts index f63a22acb..ea3759672 100644 --- a/source/patterns/@aws-solutions-constructs/core/test/input-validation.test.ts +++ b/source/patterns/@aws-solutions-constructs/core/test/input-validation.test.ts @@ -498,28 +498,4 @@ test('Test unsuccessful CheckListValues', () => { // Assertion expect(app).toThrowError('Invalid test value submitted - three'); -}); - -test('Test providing both existingTableInterface and existingTableObj', () => { - const stack = new Stack(); - - const tableProps: dynamodb.TableProps = { - partitionKey: { - name: 'table_id', - type: dynamodb.AttributeType.STRING - }, - stream: dynamodb.StreamViewType.NEW_IMAGE - }; - - const existingTableInterface = new dynamodb.Table(stack, 'DynamoTable', tableProps) - ; - const newProps = { - existingTableInterface, - existingTableObj: existingTableInterface - }; - const app = () => { - defaults.CheckProps(newProps); - }; - - expect(app).toThrowError('Error - Either provide existingTableInterface or existingTableObj, but not both.\n'); }); \ No newline at end of file