Skip to content

Commit 841975a

Browse files
jungseokleerix0rrr
authored andcommitted
fix(aws-dynamodb): don't emit empty array properties (#909)
Make the CloudFormation output a little nicer by not emitting empty arrays if there are no secondary indexes defined.
1 parent e6e8c51 commit 841975a

File tree

3 files changed

+17
-66
lines changed

3 files changed

+17
-66
lines changed

packages/@aws-cdk/aws-dynamodb/lib/table.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { cloudformation as applicationautoscaling } from '@aws-cdk/aws-applicationautoscaling';
22
import iam = require('@aws-cdk/aws-iam');
3-
import { Construct, TagManager, Tags } from '@aws-cdk/cdk';
3+
import { Construct, TagManager, Tags, Token } from '@aws-cdk/cdk';
44
import { cloudformation as dynamodb } from './dynamodb.generated';
55

66
const HASH_KEY_TYPE = 'HASH';
@@ -218,8 +218,8 @@ export class Table extends Construct {
218218
tableName: props.tableName,
219219
keySchema: this.keySchema,
220220
attributeDefinitions: this.attributeDefinitions,
221-
globalSecondaryIndexes: this.globalSecondaryIndexes,
222-
localSecondaryIndexes: this.localSecondaryIndexes,
221+
globalSecondaryIndexes: new Token(() => this.globalSecondaryIndexes.length > 0 ? this.globalSecondaryIndexes : undefined),
222+
localSecondaryIndexes: new Token(() => this.localSecondaryIndexes.length > 0 ? this.localSecondaryIndexes : undefined),
223223
pointInTimeRecoverySpecification: props.pitrEnabled ? { pointInTimeRecoveryEnabled: props.pitrEnabled } : undefined,
224224
provisionedThroughput: { readCapacityUnits: props.readCapacity || 5, writeCapacityUnits: props.writeCapacity || 5 },
225225
sseSpecification: props.sseEnabled ? { sseEnabled: props.sseEnabled } : undefined,

packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.expected.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
"AttributeName": "hashKey",
1919
"AttributeType": "S"
2020
}
21-
],
22-
"GlobalSecondaryIndexes": [],
23-
"LocalSecondaryIndexes": []
21+
]
2422
}
2523
},
2624
"TableWithGlobalAndLocalSecondaryIndexBC540710": {
@@ -311,8 +309,7 @@
311309
"WriteCapacityUnits": 5
312310
}
313311
}
314-
],
315-
"LocalSecondaryIndexes": []
312+
]
316313
}
317314
},
318315
"TableWithLocalSecondaryIndex4DA3D08F": {
@@ -346,7 +343,6 @@
346343
"AttributeType": "N"
347344
}
348345
],
349-
"GlobalSecondaryIndexes": [],
350346
"LocalSecondaryIndexes": [
351347
{
352348
"IndexName": "LSI-PartitionAndSortKey",

packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts

+12-57
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ export = {
8585
Properties: {
8686
AttributeDefinitions: [{ AttributeName: 'hashKey', AttributeType: 'S' }],
8787
KeySchema: [{ AttributeName: 'hashKey', KeyType: 'HASH' }],
88-
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
89-
GlobalSecondaryIndexes: [],
90-
LocalSecondaryIndexes: []
88+
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
9189
}
9290
}
9391
}
@@ -116,9 +114,7 @@ export = {
116114
{ AttributeName: 'hashKey', KeyType: 'HASH' },
117115
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
118116
],
119-
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
120-
GlobalSecondaryIndexes: [],
121-
LocalSecondaryIndexes: []
117+
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
122118
}
123119
}
124120
}
@@ -147,9 +143,7 @@ export = {
147143
{ AttributeName: 'hashKey', KeyType: 'HASH' },
148144
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
149145
],
150-
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
151-
GlobalSecondaryIndexes: [],
152-
LocalSecondaryIndexes: []
146+
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
153147
}
154148
}
155149
}
@@ -178,9 +172,7 @@ export = {
178172
{ AttributeName: 'hashKey', KeyType: 'HASH' },
179173
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
180174
],
181-
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
182-
GlobalSecondaryIndexes: [],
183-
LocalSecondaryIndexes: []
175+
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
184176
}
185177
}
186178
}
@@ -209,9 +201,7 @@ export = {
209201
{ AttributeName: 'hashKey', KeyType: 'HASH' },
210202
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
211203
],
212-
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
213-
GlobalSecondaryIndexes: [],
214-
LocalSecondaryIndexes: []
204+
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
215205
}
216206
}
217207
}
@@ -240,9 +230,7 @@ export = {
240230
{ AttributeName: 'hashKey', KeyType: 'HASH' },
241231
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
242232
],
243-
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
244-
GlobalSecondaryIndexes: [],
245-
LocalSecondaryIndexes: []
233+
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
246234
}
247235
}
248236
}
@@ -278,8 +266,6 @@ export = {
278266
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
279267
],
280268
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
281-
GlobalSecondaryIndexes: [],
282-
LocalSecondaryIndexes: [],
283269
TableName: 'MyTable'
284270
}
285271
}
@@ -311,8 +297,6 @@ export = {
311297
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
312298
],
313299
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
314-
GlobalSecondaryIndexes: [],
315-
LocalSecondaryIndexes: [],
316300
AttributeDefinitions: [
317301
{ AttributeName: 'hashKey', AttributeType: 'S' },
318302
{ AttributeName: 'sortKey', AttributeType: 'N' }
@@ -349,8 +333,6 @@ export = {
349333
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
350334
],
351335
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
352-
GlobalSecondaryIndexes: [],
353-
LocalSecondaryIndexes: [],
354336
AttributeDefinitions: [
355337
{ AttributeName: 'hashKey', AttributeType: 'S' },
356338
{ AttributeName: 'sortKey', AttributeType: 'N' }
@@ -399,8 +381,6 @@ export = {
399381
ReadCapacityUnits: 42,
400382
WriteCapacityUnits: 1337
401383
},
402-
GlobalSecondaryIndexes: [],
403-
LocalSecondaryIndexes: [],
404384
PointInTimeRecoverySpecification: { PointInTimeRecoveryEnabled: true },
405385
SSESpecification: { SSEEnabled: true },
406386
StreamSpecification: { StreamViewType: 'KEYS_ONLY' },
@@ -452,8 +432,7 @@ export = {
452432
Projection: { ProjectionType: 'ALL' },
453433
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 }
454434
}
455-
],
456-
LocalSecondaryIndexes: []
435+
]
457436
}
458437
}
459438
}
@@ -503,8 +482,7 @@ export = {
503482
Projection: { ProjectionType: 'ALL' },
504483
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 }
505484
}
506-
],
507-
LocalSecondaryIndexes: []
485+
]
508486
}
509487
}
510488
}
@@ -552,8 +530,7 @@ export = {
552530
Projection: { ProjectionType: 'KEYS_ONLY' },
553531
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
554532
}
555-
],
556-
LocalSecondaryIndexes: []
533+
]
557534
}
558535
}
559536
}
@@ -605,8 +582,7 @@ export = {
605582
Projection: { NonKeyAttributes: ['gsiNonKey0', 'gsiNonKey1'], ProjectionType: 'INCLUDE' },
606583
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 }
607584
}
608-
],
609-
LocalSecondaryIndexes: []
585+
]
610586
}
611587
}
612588
}
@@ -775,8 +751,7 @@ export = {
775751
Projection: { ProjectionType: 'ALL' },
776752
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
777753
},
778-
],
779-
LocalSecondaryIndexes: []
754+
]
780755
}
781756
}
782757
}
@@ -836,8 +811,7 @@ export = {
836811
Projection: { ProjectionType: 'ALL' },
837812
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
838813
}
839-
],
840-
LocalSecondaryIndexes: []
814+
]
841815
}
842816
}
843817
}
@@ -872,7 +846,6 @@ export = {
872846
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
873847
],
874848
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
875-
GlobalSecondaryIndexes: [],
876849
LocalSecondaryIndexes: [
877850
{
878851
IndexName: 'MyLSI',
@@ -918,7 +891,6 @@ export = {
918891
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
919892
],
920893
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
921-
GlobalSecondaryIndexes: [],
922894
LocalSecondaryIndexes: [
923895
{
924896
IndexName: 'MyLSI',
@@ -967,7 +939,6 @@ export = {
967939
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
968940
],
969941
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
970-
GlobalSecondaryIndexes: [],
971942
LocalSecondaryIndexes: [
972943
{
973944
IndexName: 'MyLSI',
@@ -1077,8 +1048,6 @@ export = {
10771048
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
10781049
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
10791050
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
1080-
GlobalSecondaryIndexes: [],
1081-
LocalSecondaryIndexes: [],
10821051
AttributeDefinitions:
10831052
[ { AttributeName: 'hashKey', AttributeType: 'S' },
10841053
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
@@ -1159,8 +1128,6 @@ export = {
11591128
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
11601129
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
11611130
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
1162-
GlobalSecondaryIndexes: [],
1163-
LocalSecondaryIndexes: [],
11641131
AttributeDefinitions:
11651132
[ { AttributeName: 'hashKey', AttributeType: 'S' },
11661133
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
@@ -1269,8 +1236,6 @@ export = {
12691236
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
12701237
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
12711238
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
1272-
GlobalSecondaryIndexes: [],
1273-
LocalSecondaryIndexes: [],
12741239
AttributeDefinitions:
12751240
[ { AttributeName: 'hashKey', AttributeType: 'S' },
12761241
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
@@ -1350,8 +1315,6 @@ export = {
13501315
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
13511316
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
13521317
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
1353-
GlobalSecondaryIndexes: [],
1354-
LocalSecondaryIndexes: [],
13551318
AttributeDefinitions:
13561319
[ { AttributeName: 'hashKey', AttributeType: 'S' },
13571320
{ AttributeName: 'sortKey', AttributeType: 'N' } ] } },
@@ -1554,8 +1517,6 @@ export = {
15541517
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
15551518
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
15561519
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
1557-
GlobalSecondaryIndexes: [],
1558-
LocalSecondaryIndexes: [],
15591520
AttributeDefinitions:
15601521
[ { AttributeName: 'hashKey', AttributeType: 'S' },
15611522
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
@@ -1636,8 +1597,6 @@ export = {
16361597
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
16371598
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
16381599
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
1639-
GlobalSecondaryIndexes: [],
1640-
LocalSecondaryIndexes: [],
16411600
AttributeDefinitions:
16421601
[ { AttributeName: 'hashKey', AttributeType: 'S' },
16431602
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
@@ -1746,8 +1705,6 @@ export = {
17461705
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
17471706
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
17481707
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
1749-
GlobalSecondaryIndexes: [],
1750-
LocalSecondaryIndexes: [],
17511708
AttributeDefinitions:
17521709
[ { AttributeName: 'hashKey', AttributeType: 'S' },
17531710
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
@@ -1827,8 +1784,6 @@ export = {
18271784
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
18281785
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
18291786
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
1830-
GlobalSecondaryIndexes: [],
1831-
LocalSecondaryIndexes: [],
18321787
AttributeDefinitions:
18331788
[ { AttributeName: 'hashKey', AttributeType: 'S' },
18341789
{ AttributeName: 'sortKey', AttributeType: 'N' } ] } },

0 commit comments

Comments
 (0)