@@ -212,6 +212,13 @@ export interface ITable extends IResource {
212
212
*/
213
213
readonly tableName : string ;
214
214
215
+ /**
216
+ * ARN of the table's stream, if there is one.
217
+ *
218
+ * @attribute
219
+ */
220
+ readonly tableStreamArn ?: string ;
221
+
215
222
/**
216
223
* Permits an IAM principal all data read operations from this table:
217
224
* BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan.
@@ -305,17 +312,24 @@ export interface TableAttributes {
305
312
* The ARN of the dynamodb table.
306
313
* One of this, or {@link tabeName}, is required.
307
314
*
308
- * @default no table arn
315
+ * @default - no table arn
309
316
*/
310
317
readonly tableArn ?: string ;
311
318
312
319
/**
313
320
* The table name of the dynamodb table.
314
321
* One of this, or {@link tabeArn}, is required.
315
322
*
316
- * @default no table name
323
+ * @default - no table name
317
324
*/
318
325
readonly tableName ?: string ;
326
+
327
+ /**
328
+ * The ARN of the table's stream.
329
+ *
330
+ * @default - no table stream
331
+ */
332
+ readonly tableStreamArn ?: string ;
319
333
}
320
334
321
335
abstract class TableBase extends Resource implements ITable {
@@ -329,6 +343,11 @@ abstract class TableBase extends Resource implements ITable {
329
343
*/
330
344
public abstract readonly tableName : string ;
331
345
346
+ /**
347
+ * @attribute
348
+ */
349
+ public abstract readonly tableStreamArn ?: string ;
350
+
332
351
/**
333
352
* Adds an IAM policy statement associated with this table to an IAM
334
353
* principal's policy.
@@ -347,6 +366,25 @@ abstract class TableBase extends Resource implements ITable {
347
366
} ) ;
348
367
}
349
368
369
+ /**
370
+ * Adds an IAM policy statement associated with this table's stream to an
371
+ * IAM principal's policy.
372
+ * @param grantee The principal (no-op if undefined)
373
+ * @param actions The set of actions to allow (i.e. "dynamodb:DescribeStream", "dynamodb:GetRecords", ...)
374
+ */
375
+ public grantStream ( grantee : iam . IGrantable , ...actions : string [ ] ) : iam . Grant {
376
+ if ( ! this . tableStreamArn ) {
377
+ throw new Error ( `DynamoDB Streams must be enabled on the table ${ this . node . path } ` ) ;
378
+ }
379
+
380
+ return iam . Grant . addToPrincipal ( {
381
+ grantee,
382
+ actions,
383
+ resourceArns : [ this . tableStreamArn ] ,
384
+ scope : this ,
385
+ } ) ;
386
+ }
387
+
350
388
/**
351
389
* Permits an IAM principal all data read operations from this table:
352
390
* BatchGetItem, GetRecords, GetShardIterator, Query, GetItem, Scan.
@@ -359,17 +397,31 @@ abstract class TableBase extends Resource implements ITable {
359
397
/**
360
398
* Permits an IAM Principal to list streams attached to current dynamodb table.
361
399
*
362
- * @param _grantee The principal (no-op if undefined)
400
+ * @param grantee The principal (no-op if undefined)
363
401
*/
364
- public abstract grantTableListStreams ( _grantee : iam . IGrantable ) : iam . Grant ;
402
+ public grantTableListStreams ( grantee : iam . IGrantable ) : iam . Grant {
403
+ if ( ! this . tableStreamArn ) {
404
+ throw new Error ( `DynamoDB Streams must be enabled on the table ${ this . node . path } ` ) ;
405
+ }
406
+ return iam . Grant . addToPrincipal ( {
407
+ grantee,
408
+ actions : [ 'dynamodb:ListStreams' ] ,
409
+ resourceArns : [
410
+ Lazy . stringValue ( { produce : ( ) => `${ this . tableArn } /stream/*` } )
411
+ ] ,
412
+ } ) ;
413
+ }
365
414
366
415
/**
367
416
* Permits an IAM principal all stream data read operations for this
368
417
* table's stream:
369
418
* DescribeStream, GetRecords, GetShardIterator, ListStreams.
370
419
* @param grantee The principal to grant access to
371
420
*/
372
- public abstract grantStreamRead ( grantee : iam . IGrantable ) : iam . Grant ;
421
+ public grantStreamRead ( grantee : iam . IGrantable ) : iam . Grant {
422
+ this . grantTableListStreams ( grantee ) ;
423
+ return this . grantStream ( grantee , ...READ_STREAM_DATA_ACTIONS ) ;
424
+ }
373
425
374
426
/**
375
427
* Permits an IAM principal all data write operations to this table:
@@ -521,47 +573,41 @@ export class Table extends TableBase {
521
573
522
574
public readonly tableName : string ;
523
575
public readonly tableArn : string ;
576
+ public readonly tableStreamArn ?: string ;
524
577
525
- constructor ( _scope : Construct , _id : string , _tableArn : string , _tableName : string ) {
526
- super ( _scope , _id ) ;
578
+ constructor ( _tableArn : string , tableName : string , tableStreamArn ? : string ) {
579
+ super ( scope , id ) ;
527
580
this . tableArn = _tableArn ;
528
- this . tableName = _tableName ;
581
+ this . tableName = tableName ;
582
+ this . tableStreamArn = tableStreamArn ;
529
583
}
530
584
531
585
protected get hasIndex ( ) : boolean {
532
586
return false ;
533
587
}
534
-
535
- public grantTableListStreams ( _grantee : iam . IGrantable ) : iam . Grant {
536
- throw new Error ( "Method not implemented." ) ;
537
- }
538
-
539
- public grantStreamRead ( _grantee : iam . IGrantable ) : iam . Grant {
540
- throw new Error ( "Method not implemented." ) ;
541
- }
542
588
}
543
589
544
- let tableName : string ;
545
- let tableArn : string ;
590
+ let name : string ;
591
+ let arn : string ;
546
592
const stack = Stack . of ( scope ) ;
547
593
if ( ! attrs . tableName ) {
548
594
if ( ! attrs . tableArn ) { throw new Error ( 'One of tableName or tableArn is required!' ) ; }
549
595
550
- tableArn = attrs . tableArn ;
596
+ arn = attrs . tableArn ;
551
597
const maybeTableName = stack . parseArn ( attrs . tableArn ) . resourceName ;
552
598
if ( ! maybeTableName ) { throw new Error ( 'ARN for DynamoDB table must be in the form: ...' ) ; }
553
- tableName = maybeTableName ;
599
+ name = maybeTableName ;
554
600
} else {
555
601
if ( attrs . tableArn ) { throw new Error ( "Only one of tableArn or tableName can be provided" ) ; }
556
- tableName = attrs . tableName ;
557
- tableArn = stack . formatArn ( {
602
+ name = attrs . tableName ;
603
+ arn = stack . formatArn ( {
558
604
service : 'dynamodb' ,
559
605
resource : 'table' ,
560
606
resourceName : attrs . tableName ,
561
607
} ) ;
562
608
}
563
609
564
- return new Import ( scope , id , tableArn , tableName ) ;
610
+ return new Import ( arn , name , attrs . tableStreamArn ) ;
565
611
}
566
612
567
613
/**
@@ -664,54 +710,6 @@ export class Table extends TableBase {
664
710
}
665
711
}
666
712
667
- /**
668
- * Adds an IAM policy statement associated with this table's stream to an
669
- * IAM principal's policy.
670
- * @param grantee The principal (no-op if undefined)
671
- * @param actions The set of actions to allow (i.e. "dynamodb:DescribeStream", "dynamodb:GetRecords", ...)
672
- */
673
- public grantStream ( grantee : iam . IGrantable , ...actions : string [ ] ) : iam . Grant {
674
- if ( ! this . tableStreamArn ) {
675
- throw new Error ( `DynamoDB Streams must be enabled on the table ${ this . node . path } ` ) ;
676
- }
677
-
678
- return iam . Grant . addToPrincipal ( {
679
- grantee,
680
- actions,
681
- resourceArns : [ this . tableStreamArn ] ,
682
- scope : this ,
683
- } ) ;
684
- }
685
-
686
- /**
687
- * Permits an IAM Principal to list streams attached to current dynamodb table.
688
- *
689
- * @param grantee The principal (no-op if undefined)
690
- */
691
- public grantTableListStreams ( grantee : iam . IGrantable ) : iam . Grant {
692
- if ( ! this . tableStreamArn ) {
693
- throw new Error ( `DynamoDB Streams must be enabled on the table ${ this . node . path } ` ) ;
694
- }
695
- return iam . Grant . addToPrincipal ( {
696
- grantee,
697
- actions : [ 'dynamodb:ListStreams' ] ,
698
- resourceArns : [
699
- Lazy . stringValue ( { produce : ( ) => `${ this . tableArn } /stream/*` } )
700
- ] ,
701
- } ) ;
702
- }
703
-
704
- /**
705
- * Permits an IAM principal all stream data read operations for this
706
- * table's stream:
707
- * DescribeStream, GetRecords, GetShardIterator, ListStreams.
708
- * @param grantee The principal to grant access to
709
- */
710
- public grantStreamRead ( grantee : iam . IGrantable ) : iam . Grant {
711
- this . grantTableListStreams ( grantee ) ;
712
- return this . grantStream ( grantee , ...READ_STREAM_DATA_ACTIONS ) ;
713
- }
714
-
715
713
/**
716
714
* Add a global secondary index of table.
717
715
*
@@ -1088,8 +1086,11 @@ export class Table extends TableBase {
1088
1086
}
1089
1087
1090
1088
export enum AttributeType {
1089
+ /** Up to 400KiB of binary data (which must be encoded as base64 before sending to DynamoDB) */
1091
1090
BINARY = 'B' ,
1091
+ /** Numeric values made of up to 38 digits (positive, negative or zero) */
1092
1092
NUMBER = 'N' ,
1093
+ /** Up to 400KiB of UTF-8 encoded text */
1093
1094
STRING = 'S' ,
1094
1095
}
1095
1096
@@ -1108,8 +1109,11 @@ export enum BillingMode {
1108
1109
}
1109
1110
1110
1111
export enum ProjectionType {
1112
+ /** Only the index and primary keys are projected into the index. */
1111
1113
KEYS_ONLY = 'KEYS_ONLY' ,
1114
+ /** Only the specified table attributes are projected into the index. The list of projected attributes is in `nonKeyAttributes`. */
1112
1115
INCLUDE = 'INCLUDE' ,
1116
+ /** All of the table attributes are projected into the index. */
1113
1117
ALL = 'ALL'
1114
1118
}
1115
1119
0 commit comments