Skip to content

Commit b2e1964

Browse files
author
Elad Ben-Israel
authored
refactor(core): misc cleanups to App-related APIs (#2731)
Fixes #1891 Testing: all toolkit integration tests passed. BREAKING CHANGE: * **cli:** This release requires CDK CLI >= 0.34.0 * **core:** `App.run()` was renamed to `App.synth()` (soft deprecation, it will be removed in the next release). * **core:** The `Stack.autoDeploy` feature has been removed. You can use `cdk deploy STACK ...` to determine which stacks to deploy (and wildcards are supported, so `cdk deploy '*'` will deploy all stacks. We plan to change the CLI to require specifying stacks if there is more than a single stack in the app (#2750). * **core:** `ConstructNode.aspects` is now private. * **core:** The `Synthesizer` has been removed. Use `ConstructNode.synth(node)` instead. * **core:** `ISynthesizable.synthesize` now accepts an `ISynthesisSession` which contains the `CloudAssemblyBuilder` object. This will allow further extension in the future. * **cx-api:** `cxapi.MissingContext` now includes the context `key` * **core:** `Stack.reportMissingContext` now accepts a single argument of type `cxapi.MissingContext`, which includes the missing context key * **core:** `Stack.annotatePhysicalName` has been removed (not used). * **core:** `Stack.missingContext` is now private. * **cx-api:** Multiple changes to the cloud assembly APIs to reduce surface area and clean up. * **cdk-integ (private):** if an integration test includes multiple stacks, use `/// !cdk-integ STACK ...` to explicitly specify which stacks to include in the test.
1 parent 0db32de commit b2e1964

File tree

201 files changed

+896
-686
lines changed

Some content is hidden

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

201 files changed

+896
-686
lines changed

packages/@aws-cdk/app-delivery/test/integ.cicd.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ new cicd.PipelineDeployStackAction(stack, 'DeployStack', {
3838
capabilities: cfn.CloudFormationCapabilities.None,
3939
});
4040

41-
app.run();
41+
app.synth();

packages/@aws-cdk/assert/lib/inspector.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ export class StackPathInspector extends Inspector {
5454
// The names of paths in metadata in tests are very ill-defined. Try with the full path first,
5555
// then try with the stack name preprended for backwards compat with most tests that happen to give
5656
// their stack an ID that's the same as the stack name.
57-
const md = this.stack.metadata[this.path] || this.stack.metadata[`/${this.stack.name}${this.path}`];
57+
const metadata = this.stack.manifest.metadata || {};
58+
const md = metadata[this.path] || metadata[`/${this.stack.name}${this.path}`];
5859
if (md === undefined) { return undefined; }
59-
const resourceMd = md.find(entry => entry.type === 'aws:cdk:logicalId');
60+
const resourceMd = md.find(entry => entry.type === api.LOGICAL_ID_METADATA_KEY);
6061
if (resourceMd === undefined) { return undefined; }
6162
const logicalId = resourceMd.data;
6263
return this.stack.template.Resources[logicalId];

packages/@aws-cdk/assert/lib/synth-utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Stack, SynthesisOptions, Synthesizer } from '@aws-cdk/cdk';
1+
import { ConstructNode, Stack, SynthesisOptions } from '@aws-cdk/cdk';
22
import cxapi = require('@aws-cdk/cx-api');
33

44
export class SynthUtils {
@@ -7,8 +7,8 @@ export class SynthUtils {
77
*/
88
public static synthesize(stack: Stack, options: SynthesisOptions = { }): cxapi.CloudFormationStackArtifact {
99
// always synthesize against the root (be it an App or whatever) so all artifacts will be included
10-
const synth = new Synthesizer();
11-
const assembly = synth.synthesize(stack.node.root, options);
10+
const root = stack.node.root;
11+
const assembly = ConstructNode.synth(root.node, options);
1212
return assembly.getStack(stack.name);
1313
}
1414

packages/@aws-cdk/assert/test/test.assertions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ function synthesizedStack(fn: (stack: cdk.Stack) => void): cx.CloudFormationStac
209209
const stack = new cdk.Stack(app, 'TestStack');
210210
fn(stack);
211211

212-
const assembly = app.run();
212+
const assembly = app.synth();
213213
return assembly.getStack(stack.name);
214214
}
215215

packages/@aws-cdk/assets-docker/test/integ.assets-docker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ const asset = new assets.DockerImageAsset(stack, 'DockerImage', {
1212
new cdk.CfnOutput(stack, 'ArtifactHash', { value: asset.artifactHash });
1313
new cdk.CfnOutput(stack, 'ImageUri', { value: asset.imageUri });
1414

15-
app.run();
15+
app.synth();

packages/@aws-cdk/assets-docker/test/test.image-asset.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export = {
172172
directory: path.join(__dirname, 'demo-image')
173173
});
174174

175-
const session = app.run();
175+
const session = app.synth();
176176

177177
test.ok(fs.existsSync(path.join(session.directory, 'asset.1a17a141505ac69144931fe263d130f4612251caa4bbbdaf68a44ed0f405439c/Dockerfile')));
178178
test.ok(fs.existsSync(path.join(session.directory, 'asset.1a17a141505ac69144931fe263d130f4612251caa4bbbdaf68a44ed0f405439c/index.py')));

packages/@aws-cdk/assets/lib/staging.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Construct } from '@aws-cdk/cdk';
1+
import { Construct, ISynthesisSession } from '@aws-cdk/cdk';
22
import cxapi = require('@aws-cdk/cx-api');
33
import fs = require('fs');
44
import path = require('path');
@@ -66,12 +66,12 @@ export class Staging extends Construct {
6666
}
6767
}
6868

69-
protected synthesize(session: cxapi.CloudAssemblyBuilder) {
69+
protected synthesize(session: ISynthesisSession) {
7070
if (!this.relativePath) {
7171
return;
7272
}
7373

74-
const targetPath = path.join(session.outdir, this.relativePath);
74+
const targetPath = path.join(session.assembly.outdir, this.relativePath);
7575

7676
// asset already staged
7777
if (fs.existsSync(targetPath)) {

packages/@aws-cdk/assets/test/integ.assets.directory.lit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ class TestStack extends cdk.Stack {
2020

2121
const app = new cdk.App();
2222
new TestStack(app, 'aws-cdk-asset-test');
23-
app.run();
23+
app.synth();

packages/@aws-cdk/assets/test/integ.assets.file.lit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ class TestStack extends cdk.Stack {
2020

2121
const app = new cdk.App();
2222
new TestStack(app, 'aws-cdk-asset-file-test');
23-
app.run();
23+
app.synth();

packages/@aws-cdk/assets/test/integ.assets.permissions.lit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ class TestStack extends cdk.Stack {
2020

2121
const app = new cdk.App();
2222
new TestStack(app, 'aws-cdk-asset-refs');
23-
app.run();
23+
app.synth();

packages/@aws-cdk/assets/test/integ.assets.refs.lit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ class TestStack extends cdk.Stack {
2424

2525
const app = new cdk.App();
2626
new TestStack(app, 'aws-cdk-asset-refs');
27-
app.run();
27+
app.synth();

packages/@aws-cdk/assets/test/integ.multi-assets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ class TestStack extends cdk.Stack {
2424

2525
const app = new cdk.App();
2626
new TestStack(app, 'aws-cdk-multi-assets');
27-
app.run();
27+
app.synth();

packages/@aws-cdk/assets/test/test.asset.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export = {
2929
test.ok(entry, 'found metadata entry');
3030

3131
// verify that now the template contains parameters for this asset
32-
const session = app.run();
32+
const session = app.synth();
3333

3434
test.deepEqual(stack.node.resolve(entry!.data), {
3535
path: SAMPLE_ASSET_DIR,
@@ -57,8 +57,11 @@ export = {
5757
path: dirPath
5858
});
5959

60-
const synth = app.run().getStack(stack.name);
61-
test.deepEqual(synth.metadata['/my-stack/MyAsset'][0].data, {
60+
const synth = app.synth().getStack(stack.name);
61+
const meta = synth.manifest.metadata || {};
62+
test.ok(meta['/my-stack/MyAsset']);
63+
test.ok(meta['/my-stack/MyAsset'][0]);
64+
test.deepEqual(meta['/my-stack/MyAsset'][0].data, {
6265
path: 'asset.6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2',
6366
id: "mystackMyAssetD6B1B593",
6467
packaging: "zip",
@@ -248,7 +251,7 @@ export = {
248251
});
249252

250253
// THEN
251-
app.run();
254+
app.synth();
252255
test.ok(fs.existsSync(tempdir));
253256
test.ok(fs.existsSync(path.join(tempdir, 'asset.a7a79cdf84b802ea8b198059ff899cffc095a1b9606e919f98e05bf80779756b.zip')));
254257
test.done();
@@ -268,7 +271,7 @@ export = {
268271
});
269272

270273
// THEN
271-
app.run();
274+
app.synth();
272275
test.ok(fs.existsSync(tempdir));
273276
const hash = 'asset.6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2';
274277
test.ok(fs.existsSync(path.join(tempdir, hash, 'sample-asset-file.txt')));
@@ -340,10 +343,10 @@ export = {
340343
new ZipDirectoryAsset(stack, 'MyAsset', { path: SAMPLE_ASSET_DIR });
341344

342345
// WHEN
343-
const session = app.run();
346+
const session = app.synth();
344347
const artifact = session.getStack(stack.name);
345-
346-
const md = Object.values(artifact.metadata)[0][0].data;
348+
const metadata = artifact.manifest.metadata || {};
349+
const md = Object.values(metadata)[0]![0]!.data;
347350
test.deepEqual(md.path, 'asset.6b84b87243a4a01c592d78e1fd3855c4bfef39328cd0a450cc97e81717fea2a2');
348351
test.done();
349352
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ function helloCode(_event: any, _context: any, callback: any) {
6969
});
7070
}
7171

72-
new BookApp().run();
72+
new BookApp().synth();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ const api = new apigateway.RestApi(stack, 'my-api');
1010
// at least one method is required
1111
api.root.addMethod('GET');
1212

13-
app.run();
13+
app.synth();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ const app = new cdk.App();
8282

8383
new Test(app, 'test-apigateway-restapi');
8484

85-
app.run();
85+
app.synth();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export = {
131131
api.root.addResource('bar').addResource('goo');
132132

133133
// THEN
134-
test.throws(() => app.run(), /The REST API doesn't contain any methods/);
134+
test.throws(() => app.synth(), /The REST API doesn't contain any methods/);
135135
test.done();
136136
},
137137

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ new autoscaling.AutoScalingGroup(stack, 'Fleet', {
1616
machineImage: new ec2.AmazonLinuxImage({ generation: ec2.AmazonLinuxGeneration.AmazonLinux2 }),
1717
});
1818

19-
app.run();
19+
app.synth();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ const lb = new elb.LoadBalancer(stack, 'LB', {
2828
lb.addTarget(asg);
2929
lb.addListener({ externalPort: 80 });
3030

31-
app.run();
31+
app.synth();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ asg.scaleOnRequestCount('AModestLoad', {
3737
targetRequestsPerSecond: 1
3838
});
3939

40-
app.run();
40+
app.synth();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ asg.scaleOnCpuUtilization('KeepCPUReasonable', {
3030
targetUtilizationPercent: 50
3131
});
3232

33-
app.run();
33+
app.synth();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ const app = new cdk.App();
2525

2626
new TestStack(app, 'integ-iam-external-role');
2727

28-
app.run();
28+
app.synth();

packages/@aws-cdk/aws-autoscaling/test/integ.spot-instances.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ new autoscaling.AutoScalingGroup(stack, 'Fleet', {
1717
spotPrice: '0.20'
1818
});
1919

20-
app.run();
20+
app.synth();

packages/@aws-cdk/aws-cloudformation/test/integ.aws-custom-resource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ new cdk.CfnOutput(stack, 'MessageId', { value: snsPublish.getData('MessageId') }
4545
new cdk.CfnOutput(stack, 'TopicArn', { value: listTopics.getData('Topics.0.TopicArn') });
4646
new cdk.CfnOutput(stack, 'ParameterValue', { value: getParameter.getData('Parameter.Value') });
4747

48-
app.run();
48+
app.synth();

packages/@aws-cdk/aws-cloudformation/test/integ.trivial-lambda-resource.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ const app = new cdk.App();
5959

6060
new SucceedingStack(app, 'SucceedingStack');
6161

62-
app.run();
62+
app.synth();

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-bucket-logging.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ new cloudfront.CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably2', {
5252
loggingConfig: {}
5353
});
5454

55-
app.run();
55+
app.synth();

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-custom.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ new cloudfront.CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', {
2424
]
2525
});
2626

27-
app.run();
27+
app.synth();

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-empty-root.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ new cloudfront.CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', {
2525
defaultRootObject: ''
2626
});
2727

28-
app.run();
28+
app.synth();

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-ipv6-disabled.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ new cloudfront.CloudFrontWebDistribution(stack, 'MyDistribution', {
2323
enableIpV6: false
2424
});
2525

26-
app.run();
26+
app.synth();

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-security-policy.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ new cloudfront.CloudFrontWebDistribution(stack, 'AnAmazingWebsiteProbably', {
3030
}
3131
});
3232

33-
app.run();
33+
app.synth();

packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ new cloudfront.CloudFrontWebDistribution(stack, 'MyDistribution', {
2222
]
2323
});
2424

25-
app.run();
25+
app.synth();

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ const bucket = new s3.Bucket(stack, 'Bucket', { removalPolicy: cdk.RemovalPolicy
1010
const trail = new cloudtrail.Trail(stack, 'Trail');
1111
trail.addS3EventSelector([bucket.arnForObjects('')]);
1212

13-
app.run();
13+
app.synth();

packages/@aws-cdk/aws-cloudwatch/test/integ.alarm-and-dashboard.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@ dashboard.add(new cloudwatch.SingleValueWidget({
5050
metrics: [metric]
5151
}));
5252

53-
app.run();
53+
app.synth();

packages/@aws-cdk/aws-codebuild/test/integ.caching.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ new codebuild.Project(stack, 'MyProject', {
2424
}
2525
});
2626

27-
app.run();
27+
app.synth();

packages/@aws-cdk/aws-codebuild/test/integ.defaults.lit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ const app = new cdk.App();
2626

2727
new TestStack(app, 'codebuild-default-project');
2828

29-
app.run();
29+
app.synth();

packages/@aws-cdk/aws-codebuild/test/integ.docker-asset.lit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ const app = new cdk.App();
3030

3131
new TestStack(app, 'test-codebuild-docker-asset');
3232

33-
app.run();
33+
app.synth();

packages/@aws-cdk/aws-codebuild/test/integ.ecr.lit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ const app = new cdk.App();
3030

3131
new TestStack(app, 'test-codebuild-docker-asset');
3232

33-
app.run();
33+
app.synth();

packages/@aws-cdk/aws-codebuild/test/integ.github.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ const app = new cdk.App();
2020

2121
new TestStack(app, 'test-codebuild-github');
2222

23-
app.run();
23+
app.synth();

packages/@aws-cdk/aws-codebuild/test/integ.project-bucket.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ new codebuild.Project(stack, 'MyProject', {
2121
}
2222
});
2323

24-
app.run();
24+
app.synth();

packages/@aws-cdk/aws-codebuild/test/integ.project-secondary-sources-artifacts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ new codebuild.Project(stack, 'MyProject', {
3131
],
3232
});
3333

34-
app.run();
34+
app.synth();

packages/@aws-cdk/aws-codebuild/test/integ.project-shell.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ new Project(stack, 'MyProject', {
1111
buildScriptAsset: new assets.ZipDirectoryAsset(stack, 'Bundle', { path: 'script_bundle' })
1212
});
1313

14-
app.run();
14+
app.synth();

packages/@aws-cdk/aws-codebuild/test/integ.project-vpc.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ new Project(stack, 'MyProject', {
2323
vpc
2424
});
2525

26-
app.run();
26+
app.synth();

packages/@aws-cdk/aws-codecommit/test/integ.codecommit-events.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ repo.onReferenceCreated('OnReferenceCreated', {
1919
}
2020
});
2121

22-
app.run();
22+
app.synth();

packages/@aws-cdk/aws-codedeploy/test/lambda/integ.deployment-group.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ new codedeploy.LambdaDeploymentGroup(stack, 'BlueGreenDeployment', {
4545
postHook
4646
});
4747

48-
app.run();
48+
app.synth();

packages/@aws-cdk/aws-codedeploy/test/server/integ.deployment-group.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ new codedeploy.ServerDeploymentGroup(stack, 'CodeDeployGroup', {
4242
},
4343
});
4444

45-
app.run();
45+
app.synth();

packages/@aws-cdk/aws-codepipeline-actions/test/integ.cfn-template-from-repo.lit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ new codepipeline.Pipeline(stack, 'Pipeline', {
5959
});
6060
/// !hide
6161

62-
app.run();
62+
app.synth();

packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-deployed-through-codepipeline.lit.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// !cdk-integ PipelineStack
12
import codebuild = require('@aws-cdk/aws-codebuild');
23
import codecommit = require('@aws-cdk/aws-codecommit');
34
import codepipeline = require('@aws-cdk/aws-codepipeline');
@@ -8,11 +9,7 @@ import codepipeline_actions = require('../lib');
89
const app = new cdk.App();
910

1011
/// !show
11-
const lambdaStack = new cdk.Stack(app, 'LambdaStack', {
12-
// remove the Stack from `cdk synth` and `cdk deploy`
13-
// unless you explicitly filter for it
14-
autoDeploy: false,
15-
});
12+
const lambdaStack = new cdk.Stack(app, 'LambdaStack');
1613
const lambdaCode = lambda.Code.cfnParameters();
1714
new lambda.Function(lambdaStack, 'Lambda', {
1815
code: lambdaCode,

packages/@aws-cdk/aws-codepipeline-actions/test/integ.lambda-pipeline.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ lambdaStage.addAction(new cpactions.LambdaInvokeAction({
4242
lambda: lambdaFun,
4343
}));
4444

45-
app.run();
45+
app.synth();

0 commit comments

Comments
 (0)