Skip to content

Commit d9d3a99

Browse files
authored
feat: physical names in the entire Construct Library (#2894)
This PR changes the xyzName attribute of all Resources in the Construct Library to be of type PhysicalName, and adds an AWS linter rule that checks ensures conformance. The name of the property can be any ending substring of the base name of the resource with the "Name" suffix - for example, if my resource is AWS::MyService::AwesomeFoobar, the name can be foobarName or awesomeFoobarName. BREAKING CHANGE: all <resource>Name attributes had their type changed from string to cdk.PhysicalName.
1 parent ea10f0d commit d9d3a99

File tree

135 files changed

+1087
-511
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+1087
-511
lines changed

packages/@aws-cdk/aws-apigateway/lib/api-key.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Construct, IResource as IResourceBase, Resource } from '@aws-cdk/cdk';
1+
import { Construct, IResource as IResourceBase, PhysicalName, Resource } from '@aws-cdk/cdk';
22
import { CfnApiKey } from './apigateway.generated';
33
import { ResourceOptions } from "./resource";
44
import { RestApi } from './restapi';
@@ -70,7 +70,7 @@ export interface ApiKeyProps extends ResourceOptions {
7070
* @link http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-apikey.html#cfn-apigateway-apikey-name
7171
* @default automically generated name
7272
*/
73-
readonly name?: string;
73+
readonly apiKeyName?: PhysicalName;
7474
}
7575

7676
/**
@@ -83,14 +83,16 @@ export class ApiKey extends Resource implements IApiKey {
8383
public readonly keyId: string;
8484

8585
constructor(scope: Construct, id: string, props: ApiKeyProps = { }) {
86-
super(scope, id);
86+
super(scope, id, {
87+
physicalName: props.apiKeyName,
88+
});
8789

8890
const resource = new CfnApiKey(this, 'Resource', {
8991
customerId: props.customerId,
9092
description: props.description,
9193
enabled: props.enabled || true,
9294
generateDistinctId: props.generateDistinctId,
93-
name: props.name,
95+
name: this.physicalName.value,
9496
stageKeys: this.renderStageKeys(props.resources)
9597
});
9698

packages/@aws-cdk/aws-apigateway/lib/restapi.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import iam = require('@aws-cdk/aws-iam');
2-
import { CfnOutput, Construct, IResource as IResourceBase, Resource, Stack } from '@aws-cdk/cdk';
2+
import { CfnOutput, Construct, IResource as IResourceBase, PhysicalName, Resource, Stack } from '@aws-cdk/cdk';
33
import { ApiKey, IApiKey } from './api-key';
44
import { CfnAccount, CfnRestApi } from './apigateway.generated';
55
import { Deployment } from './deployment';
@@ -64,7 +64,7 @@ export interface RestApiProps extends ResourceOptions {
6464
*
6565
* @default - ID of the RestApi construct.
6666
*/
67-
readonly restApiName?: string;
67+
readonly restApiName?: PhysicalName;
6868

6969
/**
7070
* Custom header parameters for the request.
@@ -198,10 +198,12 @@ export class RestApi extends Resource implements IRestApi {
198198
private _latestDeployment: Deployment | undefined;
199199

200200
constructor(scope: Construct, id: string, props: RestApiProps = { }) {
201-
super(scope, id);
201+
super(scope, id, {
202+
physicalName: props.restApiName || PhysicalName.of(id),
203+
});
202204

203205
const resource = new CfnRestApi(this, 'Resource', {
204-
name: props.restApiName || id,
206+
name: this.physicalName.value!,
205207
description: props.description,
206208
policy: props.policy,
207209
failOnWarnings: props.failOnWarnings,

packages/@aws-cdk/aws-apigateway/lib/vpc-link.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import elbv2 = require('@aws-cdk/aws-elasticloadbalancingv2');
2-
import { Construct, Lazy, Resource } from '@aws-cdk/cdk';
2+
import { Construct, Lazy, PhysicalName, Resource } from '@aws-cdk/cdk';
33
import { CfnVpcLink } from './apigateway.generated';
44

55
/**
@@ -10,7 +10,7 @@ export interface VpcLinkProps {
1010
* The name used to label and identify the VPC link.
1111
* @default - automatically generated name
1212
*/
13-
readonly vpcLinkName?: string;
13+
readonly vpcLinkName?: PhysicalName;
1414

1515
/**
1616
* The description of the VPC link.
@@ -41,10 +41,13 @@ export class VpcLink extends Resource {
4141
private readonly targets = new Array<elbv2.INetworkLoadBalancer>();
4242

4343
constructor(scope: Construct, id: string, props: VpcLinkProps = {}) {
44-
super(scope, id);
44+
super(scope, id, {
45+
physicalName: props.vpcLinkName ||
46+
PhysicalName.of(Lazy.stringValue({ produce: () => this.node.uniqueId })),
47+
});
4548

4649
const cfnResource = new CfnVpcLink(this, 'Resource', {
47-
name: props.vpcLinkName || this.node.uniqueId,
50+
name: this.physicalName.value!,
4851
description: props.description,
4952
targetArns: Lazy.listValue({ produce: () => this.renderTargets() })
5053
});

packages/@aws-cdk/aws-apigateway/package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,15 @@
9393
"exclude": [
9494
"from-method:@aws-cdk/aws-apigateway.Resource",
9595
"from-method:@aws-cdk/aws-apigateway.ApiKey",
96-
"ref-via-interface:@aws-cdk/aws-apigateway.ApiKeyProps.resources"
96+
"ref-via-interface:@aws-cdk/aws-apigateway.ApiKeyProps.resources",
97+
"props-physical-name:@aws-cdk/aws-apigateway.DeploymentProps",
98+
"props-physical-name:@aws-cdk/aws-apigateway.MethodProps",
99+
"props-physical-name:@aws-cdk/aws-apigateway.ProxyResourceProps",
100+
"props-physical-name:@aws-cdk/aws-apigateway.ResourceProps",
101+
"props-physical-name:@aws-cdk/aws-apigateway.StageProps",
102+
"props-physical-name:@aws-cdk/aws-apigateway.UsagePlanProps",
103+
"props-physical-name:@aws-cdk/aws-apigateway.LambdaRestApiProps"
97104
]
98105
},
99106
"stability": "experimental"
100-
}
107+
}

packages/@aws-cdk/aws-apigateway/test/test.lambda-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export = {
8181
runtime: lambda.Runtime.Nodejs810,
8282
});
8383
const alias = new lambda.Alias(stack, 'alias', {
84-
aliasName: 'my-alias',
84+
aliasName: cdk.PhysicalName.of('my-alias'),
8585
version: new lambda.Version(stack, 'version', {
8686
lambda: handler
8787
})

packages/@aws-cdk/aws-apigateway/test/test.restapi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export = {
141141
const api = new apigateway.RestApi(stack, 'restapi', {
142142
deploy: false,
143143
cloudWatchRole: false,
144-
restApiName: 'my-rest-api'
144+
restApiName: cdk.PhysicalName.of('my-rest-api'),
145145
});
146146

147147
api.root.addMethod('GET');
@@ -176,7 +176,7 @@ export = {
176176
const api = new apigateway.RestApi(stack, 'restapi', {
177177
deploy: false,
178178
cloudWatchRole: false,
179-
restApiName: 'my-rest-api'
179+
restApiName: cdk.PhysicalName.of('my-rest-api'),
180180
});
181181

182182
// WHEN

packages/@aws-cdk/aws-apigateway/test/test.vpc-link.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export = {
1616

1717
// WHEN
1818
new apigateway.VpcLink(stack, 'VpcLink', {
19-
vpcLinkName: 'MyLink',
19+
vpcLinkName: cdk.PhysicalName.of('MyLink'),
2020
targets: [nlb]
2121
});
2222

@@ -71,4 +71,4 @@ export = {
7171
test.throws(() => app.synth(), /No targets added to vpc link/);
7272
test.done();
7373
}
74-
};
74+
};

packages/@aws-cdk/aws-applicationautoscaling/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,10 @@
8585
"engines": {
8686
"node": ">= 8.10.0"
8787
},
88+
"awslint": {
89+
"exclude": [
90+
"props-physical-name:@aws-cdk/aws-applicationautoscaling.ScalableTargetProps"
91+
]
92+
},
8893
"stability": "experimental"
89-
}
94+
}

packages/@aws-cdk/aws-autoscaling/lib/lifecycle-hook.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import iam = require('@aws-cdk/aws-iam');
2-
import { Construct, IResource, Resource } from '@aws-cdk/cdk';
2+
import { Construct, IResource, PhysicalName, Resource } from '@aws-cdk/cdk';
33
import { IAutoScalingGroup } from './auto-scaling-group';
44
import { CfnLifecycleHook } from './autoscaling.generated';
55
import { ILifecycleHookTarget } from './lifecycle-hook-target';
@@ -13,7 +13,7 @@ export interface BasicLifecycleHookProps {
1313
*
1414
* @default - Automatically generated name.
1515
*/
16-
readonly lifecycleHookName?: string;
16+
readonly lifecycleHookName?: PhysicalName;
1717

1818
/**
1919
* The action the Auto Scaling group takes when the lifecycle hook timeout elapses or if an unexpected failure occurs.
@@ -92,7 +92,9 @@ export class LifecycleHook extends Resource implements ILifecycleHook {
9292
public readonly lifecycleHookName: string;
9393

9494
constructor(scope: Construct, id: string, props: LifecycleHookProps) {
95-
super(scope, id);
95+
super(scope, id, {
96+
physicalName: props.lifecycleHookName,
97+
});
9698

9799
this.role = props.role || new iam.Role(this, 'Role', {
98100
assumedBy: new iam.ServicePrincipal('autoscaling.amazonaws.com')
@@ -104,7 +106,7 @@ export class LifecycleHook extends Resource implements ILifecycleHook {
104106
autoScalingGroupName: props.autoScalingGroup.autoScalingGroupName,
105107
defaultResult: props.defaultResult,
106108
heartbeatTimeout: props.heartbeatTimeoutSec,
107-
lifecycleHookName: props.lifecycleHookName,
109+
lifecycleHookName: this.physicalName.value,
108110
lifecycleTransition: props.lifecycleTransition,
109111
notificationMetadata: props.notificationMetadata,
110112
notificationTargetArn: targetProps.notificationTargetArn,

packages/@aws-cdk/aws-autoscaling/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@
9797
"exclude": [
9898
"import-props-interface:@aws-cdk/aws-autoscaling.AutoScalingGroupImportProps",
9999
"resource-interface-extends-construct:@aws-cdk/aws-autoscaling.IAutoScalingGroup",
100-
"export:@aws-cdk/aws-autoscaling.IAutoScalingGroup"
100+
"export:@aws-cdk/aws-autoscaling.IAutoScalingGroup",
101+
"props-physical-name:@aws-cdk/aws-autoscaling.AutoScalingGroupProps",
102+
"props-physical-name:@aws-cdk/aws-autoscaling.ScheduledActionProps"
101103
]
102104
},
103105
"stability": "experimental"
104-
}
106+
}

0 commit comments

Comments
 (0)