From 8ab7b1062416adce1f2423c558bd3bfd714c5590 Mon Sep 17 00:00:00 2001 From: Adam Ruka Date: Sun, 2 Aug 2020 12:27:51 -0700 Subject: [PATCH 1/2] fix(dynamodb): allow using PhysicalName.GENERATE_IF_NEEDED as the Table name (#9377) Fixes #9374 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-dynamodb/lib/table.ts | 4 +- .../aws-dynamodb/test/dynamodb.test.ts | 37 ++++++++++--------- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/packages/@aws-cdk/aws-dynamodb/lib/table.ts b/packages/@aws-cdk/aws-dynamodb/lib/table.ts index f5cf9df385869..2cb849d669f72 100644 --- a/packages/@aws-cdk/aws-dynamodb/lib/table.ts +++ b/packages/@aws-cdk/aws-dynamodb/lib/table.ts @@ -913,8 +913,6 @@ export class Table extends TableBase { this.encryptionKey = encryptionKey; - if (props.tableName) { this.node.addMetadata('aws:cdk:hasPhysicalName', props.tableName); } - this.tableArn = this.getResourceArnAttribute(this.table.attrArn, { service: 'dynamodb', resource: 'table', @@ -922,6 +920,8 @@ export class Table extends TableBase { }); this.tableName = this.getResourceNameAttribute(this.table.ref); + if (props.tableName) { this.node.addMetadata('aws:cdk:hasPhysicalName', this.tableName); } + this.tableStreamArn = streamSpecification ? this.table.attrStreamArn : undefined; this.scalingRole = this.makeScalingRole(); diff --git a/packages/@aws-cdk/aws-dynamodb/test/dynamodb.test.ts b/packages/@aws-cdk/aws-dynamodb/test/dynamodb.test.ts index 05287f09adaa5..0e82947b82894 100644 --- a/packages/@aws-cdk/aws-dynamodb/test/dynamodb.test.ts +++ b/packages/@aws-cdk/aws-dynamodb/test/dynamodb.test.ts @@ -1,9 +1,9 @@ -import { ResourcePart, SynthUtils } from '@aws-cdk/assert'; +import { ABSENT, ResourcePart, SynthUtils } from '@aws-cdk/assert'; import '@aws-cdk/assert/jest'; import * as appscaling from '@aws-cdk/aws-applicationautoscaling'; import * as iam from '@aws-cdk/aws-iam'; import * as kms from '@aws-cdk/aws-kms'; -import { App, CfnDeletionPolicy, ConstructNode, Duration, RemovalPolicy, Stack, Tag } from '@aws-cdk/core'; +import { App, CfnDeletionPolicy, ConstructNode, Duration, PhysicalName, RemovalPolicy, Stack, Tag } from '@aws-cdk/core'; import { Attribute, AttributeType, @@ -67,8 +67,12 @@ function* LSI_GENERATOR(): Generator { } describe('default properties', () => { + let stack: Stack; + beforeEach(() => { + stack = new Stack(); + }); + test('hash key only', () => { - const stack = new Stack(); new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY }); expect(stack).toHaveResource('AWS::DynamoDB::Table', { @@ -82,7 +86,6 @@ describe('default properties', () => { }); test('removalPolicy is DESTROY', () => { - const stack = new Stack(); new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, removalPolicy: RemovalPolicy.DESTROY }); expect(stack).toHaveResource('AWS::DynamoDB::Table', { DeletionPolicy: CfnDeletionPolicy.DELETE }, ResourcePart.CompleteDefinition); @@ -90,7 +93,6 @@ describe('default properties', () => { }); test('hash + range key', () => { - const stack = new Stack(); new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY, @@ -110,8 +112,6 @@ describe('default properties', () => { }); test('hash + range key can also be specified in props', () => { - const stack = new Stack(); - new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY, @@ -132,7 +132,6 @@ describe('default properties', () => { }); test('point-in-time recovery is not enabled', () => { - const stack = new Stack(); new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY, @@ -154,7 +153,6 @@ describe('default properties', () => { }); test('server-side encryption is not enabled', () => { - const stack = new Stack(); new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY, @@ -176,7 +174,6 @@ describe('default properties', () => { }); test('stream is not enabled', () => { - const stack = new Stack(); new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY, @@ -198,7 +195,6 @@ describe('default properties', () => { }); test('ttl is not enabled', () => { - const stack = new Stack(); new Table(stack, CONSTRUCT_NAME, { partitionKey: TABLE_PARTITION_KEY, sortKey: TABLE_SORT_KEY, @@ -220,8 +216,6 @@ describe('default properties', () => { }); test('can specify new and old images', () => { - const stack = new Stack(); - new Table(stack, CONSTRUCT_NAME, { tableName: TABLE_NAME, readCapacity: 42, @@ -249,8 +243,6 @@ describe('default properties', () => { }); test('can specify new images only', () => { - const stack = new Stack(); - new Table(stack, CONSTRUCT_NAME, { tableName: TABLE_NAME, readCapacity: 42, @@ -278,8 +270,6 @@ describe('default properties', () => { }); test('can specify old images only', () => { - const stack = new Stack(); - new Table(stack, CONSTRUCT_NAME, { tableName: TABLE_NAME, readCapacity: 42, @@ -305,6 +295,19 @@ describe('default properties', () => { }, ); }); + + test('can use PhysicalName.GENERATE_IF_NEEDED as the Table name', () => { + new Table(stack, CONSTRUCT_NAME, { + tableName: PhysicalName.GENERATE_IF_NEEDED, + partitionKey: TABLE_PARTITION_KEY, + }); + + // since the resource has not been used in a cross-environment manner, + // so the name should not be filled + expect(stack).toHaveResourceLike('AWS::DynamoDB::Table', { + TableName: ABSENT, + }); + }); }); test('when specifying every property', () => { From 71be72d3eee93ebd5bbf91e9639b3fd8b043bb7f Mon Sep 17 00:00:00 2001 From: Christopher Rybicki Date: Sun, 2 Aug 2020 20:24:39 -0400 Subject: [PATCH 2/2] docs(core): fix broken link to awslint (#9398) Fixes https://github.com/aws/aws-cdk/issues/9394 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bcf045935ed0e..ef73dba94c39d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -364,7 +364,7 @@ part of the build of all AWS modules in the project and enforces the [AWS Construct Library Design Guidelines](./DESIGN_GUIDELINES.md). For more information about this tool, see the [awslint -README](./tools/awslint/README.md). +README](./packages/awslint/README.md). Generally speaking, if you make any changes which violate an awslint rule, build will fail with appropriate messages. All rules are documented and explained in @@ -377,7 +377,7 @@ Here are a few useful commands: * `scripts/foreach.sh yarn awslint` will start linting the entire repo, progressively. Rerun `scripts/foreach.sh` after fixing to continue. * `lerna run awslint --no-bail --stream 2> awslint.txt` will run __awslint__ in all modules and collect all results into awslint.txt * `lerna run awslint -- -i ` will run awslint throughout the repo and - evaluate only the rule specified [awslint README](./tools/awslint/README.md) + evaluate only the rule specified [awslint README](./packages/awslint/README.md) for details on include/exclude rule patterns. ### cfn2ts