Skip to content

Commit

Permalink
fix(dynamodb): remove global secondary index limit (#2301)
Browse files Browse the repository at this point in the history
Fixes #2262
  • Loading branch information
Elad Ben-Israel authored and RomainMuller committed Apr 16, 2019
1 parent 47ff448 commit 43afa3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 22 deletions.
14 changes: 6 additions & 8 deletions packages/@aws-cdk/aws-dynamodb/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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_LOCAL_SECONDARY_INDEX_COUNT = 5;

const READ_DATA_ACTIONS = [
'dynamodb:BatchGetItem',
'dynamodb:GetRecords',
Expand Down Expand Up @@ -254,11 +257,6 @@ export class Table extends Construct {
* @param props the property of global secondary index
*/
public addGlobalSecondaryIndex(props: GlobalSecondaryIndexProps) {
if (this.globalSecondaryIndexes.length === 5) {
// 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');
}

this.validateProvisioning(props);
this.validateIndexName(props.indexName);

Expand Down Expand Up @@ -286,9 +284,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_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);
Expand Down
14 changes: 0 additions & 14 deletions packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -782,20 +782,6 @@ export = {
test.done();
},

'error when adding more than 5 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++) {
table.addGlobalSecondaryIndex(gsiGenerator.next().value);
}

test.throws(() => table.addGlobalSecondaryIndex(gsiGenerator.next().value),
/a maximum number of global secondary index per table is 5/);

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 });
Expand Down

0 comments on commit 43afa3a

Please sign in to comment.