From 7f805dba11b091b0dd41b25cf66a5711844c94e5 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 15 Apr 2019 18:36:48 +0300 Subject: [PATCH 1/4] fix(aws-dynamodb): increase max gsi to 20 Fixes #2262 --- packages/@aws-cdk/aws-dynamodb/lib/table.ts | 9 ++++++--- packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts | 8 ++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk/aws-dynamodb/lib/table.ts b/packages/@aws-cdk/aws-dynamodb/lib/table.ts index 48e6518954020..db209e40caa57 100644 --- a/packages/@aws-cdk/aws-dynamodb/lib/table.ts +++ b/packages/@aws-cdk/aws-dynamodb/lib/table.ts @@ -9,6 +9,9 @@ import { ScalableTableAttribute } from './scalable-table-attribute'; const HASH_KEY_TYPE = 'HASH'; const RANGE_KEY_TYPE = 'RANGE'; +// https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes +const MAX_SECONDARY_INDEX_COUNT = 20; + const READ_DATA_ACTIONS = [ 'dynamodb:BatchGetItem', 'dynamodb:GetRecords', @@ -286,9 +289,9 @@ export class Table extends Construct { * @param props the property of local secondary index */ public addLocalSecondaryIndex(props: LocalSecondaryIndexProps) { - if (this.localSecondaryIndexes.length === 5) { - // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes - throw new RangeError('a maximum number of local secondary index per table is 5'); + // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes + if (this.localSecondaryIndexes.length >= MAX_SECONDARY_INDEX_COUNT) { + throw new RangeError(`a maximum number of local secondary index per table is ${MAX_SECONDARY_INDEX_COUNT}`); } this.validateIndexName(props.indexName); diff --git a/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts b/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts index 6e8a19954025f..0bfc9001db6fc 100644 --- a/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts +++ b/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts @@ -715,7 +715,7 @@ export = { const stack = new Stack(); const table = new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY }); const gsiGenerator = GSI_GENERATOR(); - for (let i = 0; i < 5; i++) { + for (let i = 0; i < 20; i++) { table.addGlobalSecondaryIndex(gsiGenerator.next().value); } @@ -782,16 +782,16 @@ export = { test.done(); }, - 'error when adding more than 5 global secondary indexes'(test: Test) { + 'error when adding more than 20 global secondary indexes'(test: Test) { const stack = new Stack(); const table = new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY }); const gsiGenerator = GSI_GENERATOR(); - for (let i = 0; i < 5; i++) { + for (let i = 0; i < 20; i++) { table.addGlobalSecondaryIndex(gsiGenerator.next().value); } test.throws(() => table.addGlobalSecondaryIndex(gsiGenerator.next().value), - /a maximum number of global secondary index per table is 5/); + /a maximum number of global secondary index per table is 20/); test.done(); }, From 3983632197639308996ac5f0fd9bfe3ad4f18f2e Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 15 Apr 2019 19:54:18 +0300 Subject: [PATCH 2/4] mixed up local/global --- packages/@aws-cdk/aws-dynamodb/lib/table.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-dynamodb/lib/table.ts b/packages/@aws-cdk/aws-dynamodb/lib/table.ts index db209e40caa57..3f2eb376a37be 100644 --- a/packages/@aws-cdk/aws-dynamodb/lib/table.ts +++ b/packages/@aws-cdk/aws-dynamodb/lib/table.ts @@ -10,7 +10,8 @@ const HASH_KEY_TYPE = 'HASH'; const RANGE_KEY_TYPE = 'RANGE'; // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes -const MAX_SECONDARY_INDEX_COUNT = 20; +const MAX_GLOBAL_SECONDARY_INDEX_COUNT = 20; // some regions have a limit of 5 but we are not going to codify this +const MAX_LOCAL_SECONDARY_INDEX_COUNT = 5; const READ_DATA_ACTIONS = [ 'dynamodb:BatchGetItem', @@ -257,9 +258,9 @@ export class Table extends Construct { * @param props the property of global secondary index */ public addGlobalSecondaryIndex(props: GlobalSecondaryIndexProps) { - if (this.globalSecondaryIndexes.length === 5) { + if (this.globalSecondaryIndexes.length === MAX_GLOBAL_SECONDARY_INDEX_COUNT) { // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes - throw new RangeError('a maximum number of global secondary index per table is 5'); + throw new RangeError(`a maximum number of global secondary index per table is ${MAX_GLOBAL_SECONDARY_INDEX_COUNT}`); } this.validateProvisioning(props); @@ -290,8 +291,8 @@ export class Table extends Construct { */ public addLocalSecondaryIndex(props: LocalSecondaryIndexProps) { // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes - if (this.localSecondaryIndexes.length >= MAX_SECONDARY_INDEX_COUNT) { - throw new RangeError(`a maximum number of local secondary index per table is ${MAX_SECONDARY_INDEX_COUNT}`); + if (this.localSecondaryIndexes.length >= MAX_LOCAL_SECONDARY_INDEX_COUNT) { + throw new RangeError(`a maximum number of local secondary index per table is ${MAX_LOCAL_SECONDARY_INDEX_COUNT}`); } this.validateIndexName(props.indexName); From 11433b5dd8d0938dfc5c805656170c67f9f6a41e Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 15 Apr 2019 20:16:48 +0300 Subject: [PATCH 3/4] remove the constraint around gsi because its a soft limit --- packages/@aws-cdk/aws-dynamodb/lib/table.ts | 6 ------ .../@aws-cdk/aws-dynamodb/test/test.dynamodb.ts | 14 -------------- 2 files changed, 20 deletions(-) diff --git a/packages/@aws-cdk/aws-dynamodb/lib/table.ts b/packages/@aws-cdk/aws-dynamodb/lib/table.ts index 3f2eb376a37be..8db33cc48b5a5 100644 --- a/packages/@aws-cdk/aws-dynamodb/lib/table.ts +++ b/packages/@aws-cdk/aws-dynamodb/lib/table.ts @@ -10,7 +10,6 @@ const HASH_KEY_TYPE = 'HASH'; const RANGE_KEY_TYPE = 'RANGE'; // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes -const MAX_GLOBAL_SECONDARY_INDEX_COUNT = 20; // some regions have a limit of 5 but we are not going to codify this const MAX_LOCAL_SECONDARY_INDEX_COUNT = 5; const READ_DATA_ACTIONS = [ @@ -258,11 +257,6 @@ export class Table extends Construct { * @param props the property of global secondary index */ public addGlobalSecondaryIndex(props: GlobalSecondaryIndexProps) { - if (this.globalSecondaryIndexes.length === MAX_GLOBAL_SECONDARY_INDEX_COUNT) { - // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes - throw new RangeError(`a maximum number of global secondary index per table is ${MAX_GLOBAL_SECONDARY_INDEX_COUNT}`); - } - this.validateProvisioning(props); this.validateIndexName(props.indexName); diff --git a/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts b/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts index 0bfc9001db6fc..6d06825ec9c5d 100644 --- a/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts +++ b/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts @@ -782,20 +782,6 @@ export = { test.done(); }, - 'error when adding more than 20 global secondary indexes'(test: Test) { - const stack = new Stack(); - const table = new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY }); - const gsiGenerator = GSI_GENERATOR(); - for (let i = 0; i < 20; i++) { - table.addGlobalSecondaryIndex(gsiGenerator.next().value); - } - - test.throws(() => table.addGlobalSecondaryIndex(gsiGenerator.next().value), - /a maximum number of global secondary index per table is 20/); - - test.done(); - }, - 'when adding a global secondary index without specifying read and write capacity'(test: Test) { const stack = new Stack(); const table = new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY }); From f79b7264ee534f6a405f931c4aa77ee1cd795e76 Mon Sep 17 00:00:00 2001 From: Elad Ben-Israel Date: Mon, 15 Apr 2019 20:30:46 +0300 Subject: [PATCH 4/4] fix test --- packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts b/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts index 6d06825ec9c5d..2fc3b186b34f0 100644 --- a/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts +++ b/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts @@ -715,7 +715,7 @@ export = { const stack = new Stack(); const table = new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY }); const gsiGenerator = GSI_GENERATOR(); - for (let i = 0; i < 20; i++) { + for (let i = 0; i < 5; i++) { table.addGlobalSecondaryIndex(gsiGenerator.next().value); }