Skip to content

Commit 43afa3a

Browse files
Elad Ben-IsraelRomainMuller
Elad Ben-Israel
authored andcommitted
fix(dynamodb): remove global secondary index limit (#2301)
Fixes #2262
1 parent 47ff448 commit 43afa3a

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

packages/@aws-cdk/aws-dynamodb/lib/table.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { ScalableTableAttribute } from './scalable-table-attribute';
99
const HASH_KEY_TYPE = 'HASH';
1010
const RANGE_KEY_TYPE = 'RANGE';
1111

12+
// https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes
13+
const MAX_LOCAL_SECONDARY_INDEX_COUNT = 5;
14+
1215
const READ_DATA_ACTIONS = [
1316
'dynamodb:BatchGetItem',
1417
'dynamodb:GetRecords',
@@ -254,11 +257,6 @@ export class Table extends Construct {
254257
* @param props the property of global secondary index
255258
*/
256259
public addGlobalSecondaryIndex(props: GlobalSecondaryIndexProps) {
257-
if (this.globalSecondaryIndexes.length === 5) {
258-
// https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes
259-
throw new RangeError('a maximum number of global secondary index per table is 5');
260-
}
261-
262260
this.validateProvisioning(props);
263261
this.validateIndexName(props.indexName);
264262

@@ -286,9 +284,9 @@ export class Table extends Construct {
286284
* @param props the property of local secondary index
287285
*/
288286
public addLocalSecondaryIndex(props: LocalSecondaryIndexProps) {
289-
if (this.localSecondaryIndexes.length === 5) {
290-
// https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes
291-
throw new RangeError('a maximum number of local secondary index per table is 5');
287+
// https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes
288+
if (this.localSecondaryIndexes.length >= MAX_LOCAL_SECONDARY_INDEX_COUNT) {
289+
throw new RangeError(`a maximum number of local secondary index per table is ${MAX_LOCAL_SECONDARY_INDEX_COUNT}`);
292290
}
293291

294292
this.validateIndexName(props.indexName);

packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts

-14
Original file line numberDiff line numberDiff line change
@@ -782,20 +782,6 @@ export = {
782782
test.done();
783783
},
784784

785-
'error when adding more than 5 global secondary indexes'(test: Test) {
786-
const stack = new Stack();
787-
const table = new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY });
788-
const gsiGenerator = GSI_GENERATOR();
789-
for (let i = 0; i < 5; i++) {
790-
table.addGlobalSecondaryIndex(gsiGenerator.next().value);
791-
}
792-
793-
test.throws(() => table.addGlobalSecondaryIndex(gsiGenerator.next().value),
794-
/a maximum number of global secondary index per table is 5/);
795-
796-
test.done();
797-
},
798-
799785
'when adding a global secondary index without specifying read and write capacity'(test: Test) {
800786
const stack = new Stack();
801787
const table = new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY });

0 commit comments

Comments
 (0)