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 all commits
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
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