Skip to content

Commit 68efa04

Browse files
author
Elad Ben-Israel
authored
refactor: remove "export"s and normalize resource names (#2580)
Implemented an awslint rule to help identify all "export" methods and remove them. Align all AWS resource constructs (besides `events.EventRule`) to their canonical name. Fixes #2577 Fixes #2578 Fixes #2458 Fixes #2419 Fixes #2579 Fixes #2313 Related #2551 BREAKING CHANGE: All `export` methods from all AWS resources have been removed. CloudFormation Exports are now automatically created when attributes are referenced across stacks within the same app. To export resources manually, you can explicitly define a `CfnOutput`. * `kms.EncryptionKey` renamed to `kms.Key` * `ec2.VpcNetwork` renamed to `ec2.Vpc` * `ec2.VpcSubnet` renamed to `ec2.Subnet` * `cloudtrail.CloudTrail` renamed `to `cloudtrail.Trail` * Deleted a few `XxxAttribute` and `XxxImportProps` interfaces which were no longer in used after their corresponding `export` method was deleted and there was no use for them in imports. * `ecs.ClusterAttributes` now accepts `IVpc` and `ISecurityGroup` instead of attributes. You can use their corresponding `fromXxx` methods to import them as needed. * `servicediscovery.CnameInstance.instanceCname` renamed to `cname`. * `glue.IDatabase.locationUrl` is now only in `glue.Database` (not on the interface) * `ec2.TcpPortFromAttribute` and `UdpPortFromAttribute` removed. Use `TcpPort` and `UdpPort` with `new Token(x).toNumber` instead. * `ec2.VpcNetwork.importFromContext` renamed to `ec2.Vpc.fromLookup` * `iam.IRole.roleId` has been removed from the interface, but `Role.roleId` is still available for owned resources.
1 parent e7ad990 commit 68efa04

File tree

192 files changed

+1451
-3509
lines changed

Some content is hidden

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

192 files changed

+1451
-3509
lines changed

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

-29
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,12 @@ import { Method, MethodOptions } from './method';
77
import { IResource, ResourceBase, ResourceOptions } from './resource';
88
import { Stage, StageOptions } from './stage';
99

10-
export interface RestApiAttributes {
11-
/**
12-
* The REST API ID of an existing REST API resource.
13-
*/
14-
readonly restApiId: string;
15-
16-
/**
17-
* The resource ID of the root resource.
18-
*/
19-
readonly restApiRootResourceId?: string;
20-
}
21-
2210
export interface IRestApi extends IResourceBase {
2311
/**
2412
* The ID of this API Gateway RestApi.
2513
* @attribute
2614
*/
2715
readonly restApiId: string;
28-
29-
/**
30-
* Exports a REST API resource from this stack.
31-
* @returns REST API props that can be imported to another stack.
32-
*/
33-
export(): RestApiAttributes;
3416
}
3517

3618
export interface RestApiProps extends ResourceOptions {
@@ -165,7 +147,6 @@ export class RestApi extends Resource implements IRestApi {
165147
public static fromRestApiId(scope: Construct, id: string, restApiId: string): IRestApi {
166148
class Import extends Resource implements IRestApi {
167149
public readonly restApiId = restApiId;
168-
public export(): RestApiAttributes { return { restApiId }; }
169150
}
170151

171152
return new Import(scope, id);
@@ -237,16 +218,6 @@ export class RestApi extends Resource implements IRestApi {
237218
this.root = new RootResource(this, props, resource.restApiRootResourceId);
238219
}
239220

240-
/**
241-
* Exports a REST API resource from this stack.
242-
* @returns REST API props that can be imported to another stack.
243-
*/
244-
public export(): RestApiAttributes {
245-
return {
246-
restApiId: new CfnOutput(this, 'RestApiId', { value: this.restApiId }).makeImportValue().toString()
247-
};
248-
}
249-
250221
/**
251222
* The deployed root URL of this REST API.
252223
*/

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export = {
303303
// GIVEN
304304
const stack = new cdk.Stack();
305305
const api = new apigateway.RestApi(stack, 'test-api', { deploy: false });
306-
const vpc = new ec2.VpcNetwork(stack, 'VPC');
306+
const vpc = new ec2.Vpc(stack, 'VPC');
307307
const nlb = new elbv2.NetworkLoadBalancer(stack, 'NLB', {
308308
vpc
309309
});

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

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, haveResource, haveResourceLike, ResourcePart, SynthUtils } from '@aws-cdk/assert';
1+
import { expect, haveResource, haveResourceLike, ResourcePart } from '@aws-cdk/assert';
22
import cdk = require('@aws-cdk/cdk');
33
import { App, Stack } from '@aws-cdk/cdk';
44
import { Test } from 'nodeunit';
@@ -328,25 +328,15 @@ export = {
328328
test.done();
329329
},
330330

331-
'import/export'(test: Test) {
331+
'fromRestApiId'(test: Test) {
332332
// GIVEN
333333
const stack = new cdk.Stack();
334334

335335
// WHEN
336336
const imported = apigateway.RestApi.fromRestApiId(stack, 'imported-api', 'api-rxt4498f');
337-
const api = new apigateway.RestApi(stack, 'MyRestApi');
338-
api.root.addMethod('GET');
339-
340-
const exported = api.export();
341337

342338
// THEN
343-
stack.node.prepareTree();
344-
test.deepEqual(SynthUtils.toCloudFormation(stack).Outputs.MyRestApiRestApiIdB93C5C2D, {
345-
Value: { Ref: 'MyRestApi2D1F47A9' },
346-
Export: { Name: 'Stack:MyRestApiRestApiIdB93C5C2D' }
347-
});
348339
test.deepEqual(imported.node.resolve(imported.restApiId), 'api-rxt4498f');
349-
test.deepEqual(imported.node.resolve(exported), { restApiId: { 'Fn::ImportValue': 'Stack:MyRestApiRestApiIdB93C5C2D' } });
350340
test.done();
351341
},
352342

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export = {
99
'default setup'(test: Test) {
1010
// GIVEN
1111
const stack = new cdk.Stack();
12-
const vpc = new ec2.VpcNetwork(stack, 'VPC');
12+
const vpc = new ec2.Vpc(stack, 'VPC');
1313
const nlb = new elbv2.NetworkLoadBalancer(stack, 'NLB', {
1414
vpc
1515
});

packages/@aws-cdk/aws-autoscaling/lib/auto-scaling-group.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export interface AutoScalingGroupProps extends CommonAutoScalingGroupProps {
148148
/**
149149
* VPC to launch these instances in.
150150
*/
151-
readonly vpc: ec2.IVpcNetwork;
151+
readonly vpc: ec2.IVpc;
152152

153153
/**
154154
* Type of instance to launch

packages/@aws-cdk/aws-autoscaling/test/integ.amazonlinux2.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import autoscaling = require('../lib');
66
const app = new cdk.App();
77
const stack = new cdk.Stack(app, 'aws-cdk-autoscaling-integ');
88

9-
const vpc = new ec2.VpcNetwork(stack, 'VPC', {
9+
const vpc = new ec2.Vpc(stack, 'VPC', {
1010
maxAZs: 2
1111
});
1212

packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-classic-loadbalancer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import autoscaling = require('../lib');
77
const app = new cdk.App();
88
const stack = new cdk.Stack(app, 'aws-cdk-asg-integ');
99

10-
const vpc = new ec2.VpcNetwork(stack, 'VPC', {
10+
const vpc = new ec2.Vpc(stack, 'VPC', {
1111
maxAZs: 3
1212
});
1313

packages/@aws-cdk/aws-autoscaling/test/integ.asg-w-elbv2.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import autoscaling = require('../lib');
77
const app = new cdk.App();
88
const stack = new cdk.Stack(app, 'aws-cdk-asg-integ');
99

10-
const vpc = new ec2.VpcNetwork(stack, 'VPC', {
10+
const vpc = new ec2.Vpc(stack, 'VPC', {
1111
maxAZs: 2
1212
});
1313

packages/@aws-cdk/aws-autoscaling/test/integ.custom-scaling.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import autoscaling = require('../lib');
66
const app = new cdk.App();
77
const stack = new cdk.Stack(app, 'aws-cdk-autoscaling-integ');
88

9-
const vpc = new ec2.VpcNetwork(stack, 'VPC', {
9+
const vpc = new ec2.Vpc(stack, 'VPC', {
1010
maxAZs: 2
1111
});
1212

packages/@aws-cdk/aws-autoscaling/test/integ.external-role.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class TestStack extends cdk.Stack {
77
constructor(scope: cdk.App, id: string) {
88
super(scope, id);
99

10-
const vpc = new ec2.VpcNetwork(this, 'VPC');
10+
const vpc = new ec2.Vpc(this, 'VPC');
1111
const role = new iam.Role(this, 'Role', {
1212
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
1313
});

packages/@aws-cdk/aws-autoscaling/test/test.auto-scaling-group.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ export = {
524524
};
525525

526526
function mockVpc(stack: cdk.Stack) {
527-
return ec2.VpcNetwork.import(stack, 'MyVpc', {
527+
return ec2.Vpc.fromVpcAttributes(stack, 'MyVpc', {
528528
vpcId: 'my-vpc',
529529
availabilityZones: [ 'az1' ],
530530
publicSubnetIds: [ 'pub1' ],

packages/@aws-cdk/aws-autoscaling/test/test.lifecyclehooks.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export = {
1010
'we can add a lifecycle hook to an ASG'(test: Test) {
1111
// GIVEN
1212
const stack = new cdk.Stack();
13-
const vpc = new ec2.VpcNetwork(stack, 'VPC');
13+
const vpc = new ec2.Vpc(stack, 'VPC');
1414
const asg = new autoscaling.AutoScalingGroup(stack, 'ASG', {
1515
vpc,
1616
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.Micro),

packages/@aws-cdk/aws-autoscaling/test/test.scaling.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,13 @@ export = {
224224
};
225225

226226
class ASGFixture extends cdk.Construct {
227-
public readonly vpc: ec2.VpcNetwork;
227+
public readonly vpc: ec2.Vpc;
228228
public readonly asg: autoscaling.AutoScalingGroup;
229229

230230
constructor(scope: cdk.Construct, id: string) {
231231
super(scope, id);
232232

233-
this.vpc = new ec2.VpcNetwork(this, 'VPC');
233+
this.vpc = new ec2.Vpc(this, 'VPC');
234234
this.asg = new autoscaling.AutoScalingGroup(this, 'ASG', {
235235
vpc: this.vpc,
236236
instanceType: new ec2.InstanceTypePair(ec2.InstanceClass.M4, ec2.InstanceSize.Micro),

packages/@aws-cdk/aws-autoscaling/test/test.scheduled-action.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export = {
104104
};
105105

106106
function makeAutoScalingGroup(scope: cdk.Construct) {
107-
const vpc = new ec2.VpcNetwork(scope, 'VPC');
107+
const vpc = new ec2.Vpc(scope, 'VPC');
108108
return new autoscaling.AutoScalingGroup(scope, 'ASG', {
109109
vpc,
110110
instanceType: new ec2.InstanceType('t2.micro'),

packages/@aws-cdk/aws-certificatemanager/lib/certificate.ts

+1-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CfnOutput, Construct, IResource, Resource } from '@aws-cdk/cdk';
1+
import { Construct, IResource, Resource } from '@aws-cdk/cdk';
22
import { CfnCertificate } from './certificatemanager.generated';
33
import { apexDomain } from './util';
44

@@ -9,21 +9,6 @@ export interface ICertificate extends IResource {
99
* @attribute
1010
*/
1111
readonly certificateArn: string;
12-
13-
/**
14-
* Export this certificate from the stack
15-
*/
16-
export(): CertificateAttributes;
17-
}
18-
19-
/**
20-
* Reference to an existing Certificate
21-
*/
22-
export interface CertificateAttributes {
23-
/**
24-
* The certificate's ARN
25-
*/
26-
readonly certificateArn: string;
2712
}
2813

2914
/**
@@ -79,9 +64,6 @@ export class Certificate extends Resource implements ICertificate {
7964
public static fromCertificateArn(scope: Construct, id: string, certificateArn: string): ICertificate {
8065
class Import extends Resource implements ICertificate {
8166
public certificateArn = certificateArn;
82-
public export(): CertificateAttributes {
83-
return { certificateArn };
84-
}
8567
}
8668

8769
return new Import(scope, id);
@@ -118,13 +100,4 @@ export class Certificate extends Resource implements ICertificate {
118100
};
119101
}
120102
}
121-
122-
/**
123-
* Export this certificate from the stack
124-
*/
125-
public export(): CertificateAttributes {
126-
return {
127-
certificateArn: new CfnOutput(this, 'Arn', { value: this.certificateArn }).makeImportValue().toString()
128-
};
129-
}
130103
}

packages/@aws-cdk/aws-certificatemanager/lib/dns-validated-certificate.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import lambda = require('@aws-cdk/aws-lambda');
44
import route53 = require('@aws-cdk/aws-route53');
55
import cdk = require('@aws-cdk/cdk');
66
import path = require('path');
7-
import { CertificateAttributes, CertificateProps, ICertificate } from './certificate';
7+
import { CertificateProps, ICertificate } from './certificate';
88

99
export interface DnsValidatedCertificateProps extends CertificateProps {
1010
/**
@@ -71,15 +71,6 @@ export class DnsValidatedCertificate extends cdk.Construct implements ICertifica
7171
this.certificateArn = certificate.getAtt('Arn').toString();
7272
}
7373

74-
/**
75-
* Export this certificate from the stack
76-
*/
77-
public export(): CertificateAttributes {
78-
return {
79-
certificateArn: new cdk.CfnOutput(this, 'Arn', { value: this.certificateArn }).makeImportValue().toString()
80-
};
81-
}
82-
8374
protected validate(): string[] {
8475
const errors: string[] = [];
8576
// Ensure the zone name is a parent zone of the certificate domain name

packages/@aws-cdk/aws-certificatemanager/test/test.certificate.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ export = {
4343
},
4444

4545
'export and import'(test: Test) {
46+
// GIVEN
4647
const stack = new Stack();
4748

48-
const refProps = new Certificate(stack, 'Cert', {
49-
domainName: 'hello.com',
50-
}).export();
51-
52-
Certificate.fromCertificateArn(stack, 'Imported', refProps.certificateArn);
49+
// WHEN
50+
const c = Certificate.fromCertificateArn(stack, 'Imported', 'cert-arn');
5351

52+
// THEN
53+
test.deepEqual(c.certificateArn, 'cert-arn');
5454
test.done();
5555
}
5656
};

packages/@aws-cdk/aws-certificatemanager/test/test.dns-validated-certificate.ts

-16
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,6 @@ export = {
8080
test.done();
8181
},
8282

83-
'export and import'(test: Test) {
84-
const stack = new Stack();
85-
86-
const helloDotComZone = new PublicHostedZone(stack, 'HelloDotCom', {
87-
zoneName: 'hello.com'
88-
});
89-
90-
const refProps = new DnsValidatedCertificate(stack, 'Cert', {
91-
domainName: 'hello.com',
92-
hostedZone: helloDotComZone,
93-
}).export();
94-
95-
test.ok('certificateArn' in refProps);
96-
test.done();
97-
},
98-
9983
'adds validation error on domain mismatch'(test: Test) {
10084
const stack = new Stack();
10185

packages/@aws-cdk/aws-cloudtrail/lib/index.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import iam = require('@aws-cdk/aws-iam');
22
import kms = require('@aws-cdk/aws-kms');
33
import logs = require('@aws-cdk/aws-logs');
44
import s3 = require('@aws-cdk/aws-s3');
5-
import cdk = require('@aws-cdk/cdk');
5+
import { Construct, Resource } from '@aws-cdk/cdk';
66
import { CfnTrail } from './cloudtrail.generated';
77

88
// AWS::CloudTrail CloudFormation Resources:
99
export * from './cloudtrail.generated';
1010

11-
export interface CloudTrailProps {
11+
export interface TrailProps {
1212
/**
1313
* For most services, events are recorded in the region where the action occurred.
1414
* For global services such as AWS Identity and Access Management (IAM), AWS STS, Amazon CloudFront, and Route 53,
@@ -65,7 +65,7 @@ export interface CloudTrailProps {
6565
/** The AWS Key Management Service (AWS KMS) key ID that you want to use to encrypt CloudTrail logs.
6666
* @default none
6767
*/
68-
readonly kmsKey?: kms.IEncryptionKey;
68+
readonly kmsKey?: kms.IKey;
6969

7070
/** The name of an Amazon SNS topic that is notified when new log files are published.
7171
* @default none
@@ -99,12 +99,21 @@ export enum ReadWriteType {
9999
* const cloudTrail = new CloudTrail(this, 'MyTrail');
100100
*
101101
*/
102-
export class CloudTrail extends cdk.Construct {
102+
export class Trail extends Resource {
103+
104+
/**
105+
* @attribute
106+
*/
107+
public readonly trailArn: string;
108+
109+
/**
110+
* @attribute
111+
*/
112+
public readonly trailSnsTopicArn: string;
103113

104-
public readonly cloudTrailArn: string;
105114
private eventSelectors: EventSelector[] = [];
106115

107-
constructor(scope: cdk.Construct, id: string, props: CloudTrailProps = {}) {
116+
constructor(scope: Construct, id: string, props: TrailProps = {}) {
108117
super(scope, id);
109118

110119
const s3bucket = new s3.Bucket(this, 'S3', {encryption: s3.BucketEncryption.Unencrypted});
@@ -157,7 +166,10 @@ export class CloudTrail extends cdk.Construct {
157166
snsTopicName: props.snsTopic,
158167
eventSelectors: this.eventSelectors
159168
});
160-
this.cloudTrailArn = trail.trailArn;
169+
170+
this.trailArn = trail.trailArn;
171+
this.trailSnsTopicArn = trail.trailSnsTopicArn;
172+
161173
const s3BucketPolicy = s3bucket.node.findChild("Policy").node.findChild("Resource") as s3.CfnBucketPolicy;
162174
trail.node.addDependency(s3BucketPolicy);
163175

packages/@aws-cdk/aws-cloudtrail/test/integ.cloudtrail.lit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const stack = new cdk.Stack(app, 'integ-cloudtrail');
77

88
const bucket = new s3.Bucket(stack, 'Bucket', { removalPolicy: cdk.RemovalPolicy.Destroy });
99

10-
const trail = new cloudtrail.CloudTrail(stack, 'Trail');
10+
const trail = new cloudtrail.Trail(stack, 'Trail');
1111
trail.addS3EventSelector([bucket.arnForObjects('')]);
1212

1313
app.run();

0 commit comments

Comments
 (0)