From 841975a147cc5bb03aaa5d2f13e65cfb01f41397 Mon Sep 17 00:00:00 2001 From: Jungseok Lee Date: Mon, 15 Oct 2018 00:46:08 -0700 Subject: [PATCH] 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. --- packages/@aws-cdk/aws-dynamodb/lib/table.ts | 6 +- .../test/integ.dynamodb.expected.json | 8 +-- .../aws-dynamodb/test/test.dynamodb.ts | 69 ++++--------------- 3 files changed, 17 insertions(+), 66 deletions(-) diff --git a/packages/@aws-cdk/aws-dynamodb/lib/table.ts b/packages/@aws-cdk/aws-dynamodb/lib/table.ts index 601570ec1f2d1..eabbfac2d6726 100644 --- a/packages/@aws-cdk/aws-dynamodb/lib/table.ts +++ b/packages/@aws-cdk/aws-dynamodb/lib/table.ts @@ -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'; @@ -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, diff --git a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.expected.json b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.expected.json index 12b7020d69c42..d508449c163f7 100644 --- a/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.expected.json +++ b/packages/@aws-cdk/aws-dynamodb/test/integ.dynamodb.expected.json @@ -18,9 +18,7 @@ "AttributeName": "hashKey", "AttributeType": "S" } - ], - "GlobalSecondaryIndexes": [], - "LocalSecondaryIndexes": [] + ] } }, "TableWithGlobalAndLocalSecondaryIndexBC540710": { @@ -311,8 +309,7 @@ "WriteCapacityUnits": 5 } } - ], - "LocalSecondaryIndexes": [] + ] } }, "TableWithLocalSecondaryIndex4DA3D08F": { @@ -346,7 +343,6 @@ "AttributeType": "N" } ], - "GlobalSecondaryIndexes": [], "LocalSecondaryIndexes": [ { "IndexName": "LSI-PartitionAndSortKey", diff --git a/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts b/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts index b1d1481307a88..20cb222e33032 100644 --- a/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts +++ b/packages/@aws-cdk/aws-dynamodb/test/test.dynamodb.ts @@ -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 } } } } @@ -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 } } } } @@ -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 } } } } @@ -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 } } } } @@ -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 } } } } @@ -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 } } } } @@ -278,8 +266,6 @@ export = { { AttributeName: 'sortKey', KeyType: 'RANGE' } ], ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 }, - GlobalSecondaryIndexes: [], - LocalSecondaryIndexes: [], TableName: 'MyTable' } } @@ -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' } @@ -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' } @@ -399,8 +381,6 @@ export = { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 }, - GlobalSecondaryIndexes: [], - LocalSecondaryIndexes: [], PointInTimeRecoverySpecification: { PointInTimeRecoveryEnabled: true }, SSESpecification: { SSEEnabled: true }, StreamSpecification: { StreamViewType: 'KEYS_ONLY' }, @@ -452,8 +432,7 @@ export = { Projection: { ProjectionType: 'ALL' }, ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 } } - ], - LocalSecondaryIndexes: [] + ] } } } @@ -503,8 +482,7 @@ export = { Projection: { ProjectionType: 'ALL' }, ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 } } - ], - LocalSecondaryIndexes: [] + ] } } } @@ -552,8 +530,7 @@ export = { Projection: { ProjectionType: 'KEYS_ONLY' }, ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 } } - ], - LocalSecondaryIndexes: [] + ] } } } @@ -605,8 +582,7 @@ export = { Projection: { NonKeyAttributes: ['gsiNonKey0', 'gsiNonKey1'], ProjectionType: 'INCLUDE' }, ProvisionedThroughput: { ReadCapacityUnits: 42, WriteCapacityUnits: 1337 } } - ], - LocalSecondaryIndexes: [] + ] } } } @@ -775,8 +751,7 @@ export = { Projection: { ProjectionType: 'ALL' }, ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 } }, - ], - LocalSecondaryIndexes: [] + ] } } } @@ -836,8 +811,7 @@ export = { Projection: { ProjectionType: 'ALL' }, ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 } } - ], - LocalSecondaryIndexes: [] + ] } } } @@ -872,7 +846,6 @@ export = { { AttributeName: 'sortKey', KeyType: 'RANGE' } ], ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }, - GlobalSecondaryIndexes: [], LocalSecondaryIndexes: [ { IndexName: 'MyLSI', @@ -918,7 +891,6 @@ export = { { AttributeName: 'sortKey', KeyType: 'RANGE' } ], ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }, - GlobalSecondaryIndexes: [], LocalSecondaryIndexes: [ { IndexName: 'MyLSI', @@ -967,7 +939,6 @@ export = { { AttributeName: 'sortKey', KeyType: 'RANGE' } ], ProvisionedThroughput: { ReadCapacityUnits: 5, WriteCapacityUnits: 5 }, - GlobalSecondaryIndexes: [], LocalSecondaryIndexes: [ { IndexName: 'MyLSI', @@ -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' } ], @@ -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' } ], @@ -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' } ], @@ -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' } ] } }, @@ -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' } ], @@ -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' } ], @@ -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' } ], @@ -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' } ] } },