@@ -9,6 +9,9 @@ import { ScalableTableAttribute } from './scalable-table-attribute';
9
9
const HASH_KEY_TYPE = 'HASH' ;
10
10
const RANGE_KEY_TYPE = 'RANGE' ;
11
11
12
+ // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-secondary-indexes
13
+ const MAX_LOCAL_SECONDARY_INDEX_COUNT = 5 ;
14
+
12
15
const READ_DATA_ACTIONS = [
13
16
'dynamodb:BatchGetItem' ,
14
17
'dynamodb:GetRecords' ,
@@ -254,11 +257,6 @@ export class Table extends Construct {
254
257
* @param props the property of global secondary index
255
258
*/
256
259
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
-
262
260
this . validateProvisioning ( props ) ;
263
261
this . validateIndexName ( props . indexName ) ;
264
262
@@ -286,9 +284,9 @@ export class Table extends Construct {
286
284
* @param props the property of local secondary index
287
285
*/
288
286
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 } ` ) ;
292
290
}
293
291
294
292
this . validateIndexName ( props . indexName ) ;
0 commit comments