Skip to content
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(aws-dynamodb): remove global index limit #2301

Merged
merged 4 commits into from
Apr 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 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_SECONDARY_INDEX_COUNT = 20;

const READ_DATA_ACTIONS = [
'dynamodb:BatchGetItem',
'dynamodb:GetRecords',
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
},
Expand Down