Skip to content

Commit

Permalink
fix(aws-dynamodb): don't emit empty array properties (#909)
Browse files Browse the repository at this point in the history
Make the CloudFormation output a little nicer by not emitting empty arrays if there are no secondary indexes defined.
  • Loading branch information
jungseoklee authored and rix0rrr committed Oct 15, 2018
1 parent e6e8c51 commit 841975a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 66 deletions.
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-dynamodb/lib/table.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { cloudformation as applicationautoscaling } from '@aws-cdk/aws-applicationautoscaling';
import iam = require('@aws-cdk/aws-iam');
import { Construct, TagManager, Tags } from '@aws-cdk/cdk';
import { Construct, TagManager, Tags, Token } from '@aws-cdk/cdk';
import { cloudformation as dynamodb } from './dynamodb.generated';

const HASH_KEY_TYPE = 'HASH';
Expand Down Expand Up @@ -218,8 +218,8 @@ export class Table extends Construct {
tableName: props.tableName,
keySchema: this.keySchema,
attributeDefinitions: this.attributeDefinitions,
globalSecondaryIndexes: this.globalSecondaryIndexes,
localSecondaryIndexes: this.localSecondaryIndexes,
globalSecondaryIndexes: new Token(() => this.globalSecondaryIndexes.length > 0 ? this.globalSecondaryIndexes : undefined),
localSecondaryIndexes: new Token(() => this.localSecondaryIndexes.length > 0 ? this.localSecondaryIndexes : undefined),
pointInTimeRecoverySpecification: props.pitrEnabled ? { pointInTimeRecoveryEnabled: props.pitrEnabled } : undefined,
provisionedThroughput: { readCapacityUnits: props.readCapacity || 5, writeCapacityUnits: props.writeCapacity || 5 },
sseSpecification: props.sseEnabled ? { sseEnabled: props.sseEnabled } : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
"AttributeName": "hashKey",
"AttributeType": "S"
}
],
"GlobalSecondaryIndexes": [],
"LocalSecondaryIndexes": []
]
}
},
"TableWithGlobalAndLocalSecondaryIndexBC540710": {
Expand Down Expand Up @@ -311,8 +309,7 @@
"WriteCapacityUnits": 5
}
}
],
"LocalSecondaryIndexes": []
]
}
},
"TableWithLocalSecondaryIndex4DA3D08F": {
Expand Down Expand Up @@ -346,7 +343,6 @@
"AttributeType": "N"
}
],
"GlobalSecondaryIndexes": [],
"LocalSecondaryIndexes": [
{
"IndexName": "LSI-PartitionAndSortKey",
Expand Down
69 changes: 12 additions & 57 deletions packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ export = {
Properties: {
AttributeDefinitions: [{ AttributeName: 'hashKey', AttributeType: 'S' }],
KeySchema: [{ AttributeName: 'hashKey', KeyType: 'HASH' }],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
}
}
}
Expand Down Expand Up @@ -116,9 +114,7 @@ export = {
{ AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
}
}
}
Expand Down Expand Up @@ -147,9 +143,7 @@ export = {
{ AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
}
}
}
Expand Down Expand Up @@ -178,9 +172,7 @@ export = {
{ AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
}
}
}
Expand Down Expand Up @@ -209,9 +201,7 @@ export = {
{ AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
}
}
}
Expand Down Expand Up @@ -240,9 +230,7 @@ export = {
{ AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: []
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
}
}
}
Expand Down Expand Up @@ -278,8 +266,6 @@ export = {
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
TableName: 'MyTable'
}
}
Expand Down Expand Up @@ -311,8 +297,6 @@ export = {
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
AttributeDefinitions: [
{ AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' }
Expand Down Expand Up @@ -349,8 +333,6 @@ export = {
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
AttributeDefinitions: [
{ AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' }
Expand Down Expand Up @@ -399,8 +381,6 @@ export = {
ReadCapacityUnits: 42,
WriteCapacityUnits: 1337
},
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
PointInTimeRecoverySpecification: { PointInTimeRecoveryEnabled: true },
SSESpecification: { SSEEnabled: true },
StreamSpecification: { StreamViewType: 'KEYS_ONLY' },
Expand Down Expand Up @@ -452,8 +432,7 @@ export = {
Projection: { ProjectionType: 'ALL' },
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 }
}
],
LocalSecondaryIndexes: []
]
}
}
}
Expand Down Expand Up @@ -503,8 +482,7 @@ export = {
Projection: { ProjectionType: 'ALL' },
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 }
}
],
LocalSecondaryIndexes: []
]
}
}
}
Expand Down Expand Up @@ -552,8 +530,7 @@ export = {
Projection: { ProjectionType: 'KEYS_ONLY' },
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
}
],
LocalSecondaryIndexes: []
]
}
}
}
Expand Down Expand Up @@ -605,8 +582,7 @@ export = {
Projection: { NonKeyAttributes: ['gsiNonKey0', 'gsiNonKey1'], ProjectionType: 'INCLUDE' },
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 }
}
],
LocalSecondaryIndexes: []
]
}
}
}
Expand Down Expand Up @@ -775,8 +751,7 @@ export = {
Projection: { ProjectionType: 'ALL' },
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
},
],
LocalSecondaryIndexes: []
]
}
}
}
Expand Down Expand Up @@ -836,8 +811,7 @@ export = {
Projection: { ProjectionType: 'ALL' },
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }
}
],
LocalSecondaryIndexes: []
]
}
}
}
Expand Down Expand Up @@ -872,7 +846,6 @@ export = {
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [
{
IndexName: 'MyLSI',
Expand Down Expand Up @@ -918,7 +891,6 @@ export = {
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [
{
IndexName: 'MyLSI',
Expand Down Expand Up @@ -967,7 +939,6 @@ export = {
{ AttributeName: 'sortKey', KeyType: 'RANGE' }
],
ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [
{
IndexName: 'MyLSI',
Expand Down Expand Up @@ -1077,8 +1048,6 @@ export = {
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
Expand Down Expand Up @@ -1159,8 +1128,6 @@ export = {
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
Expand Down Expand Up @@ -1269,8 +1236,6 @@ export = {
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
Expand Down Expand Up @@ -1350,8 +1315,6 @@ export = {
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ] } },
Expand Down Expand Up @@ -1554,8 +1517,6 @@ export = {
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
Expand Down Expand Up @@ -1636,8 +1597,6 @@ export = {
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
Expand Down Expand Up @@ -1746,8 +1705,6 @@ export = {
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ],
Expand Down Expand Up @@ -1827,8 +1784,6 @@ export = {
[ { AttributeName: 'hashKey', KeyType: 'HASH' },
{ AttributeName: 'sortKey', KeyType: 'RANGE' } ],
ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 },
GlobalSecondaryIndexes: [],
LocalSecondaryIndexes: [],
AttributeDefinitions:
[ { AttributeName: 'hashKey', AttributeType: 'S' },
{ AttributeName: 'sortKey', AttributeType: 'N' } ] } },
Expand Down

0 comments on commit 841975a

Please sign in to comment.