-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): can use Constructs to model collections of Stacks #1940
Conversation
…teable and severity is at the front.
Stacks no longer accept a `cdk.App` as scope, but a `cdk.Construct` like other constructs. This makes it possible define a Construct to represent your entire application, which can consist of a collection of Stacks. Stack names will automatically be derived from their location in the construct tree, but it's also possible to specify the deployed name of the stack by specifying the `stackName` property. Calling `app.run()` is no longer necessary, but can still safely be done. Fixes #1479.
cc @Doug-AWS, the user guide is going to need an update after this PR has been merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor comments
packages/@aws-cdk/aws-codepipeline/test/integ.pipeline-cfn-cross-region.expected.json
Show resolved
Hide resolved
/** | ||
* Return the path of components up to but excluding the root | ||
*/ | ||
public rootPath(): IConstruct[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can just delete this. Is this really a useful thing? I also don't like that it's called path
because it doesn't return a path (paths are strings), it returns an array of ancestors without the first one, which brings me to ask, what's rong with construct.node.ancestors().slice(1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also make ancestors a property please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"root path" is the term for the nodes in a tree that lie between a given node and the root of the trie. I wouldn't say a path is a string, maybe that a path can be represented as a string.
rootPath
could (and should) have more logic for the purposes of IDs, but honestly our tree structure and which things exist and have ids and whether those ids should be taken into account is completely messed up and inconsistent between real applications and unit tests, insofar as that anything that deals with names and paths is a tangle of messy ifs.
So sure, I'll inline the definition of rootPath()
everywhere.
ancestors()
takes an optional argument, so it cannot be made a property.
@@ -4,7 +4,7 @@ import { Construct, Resource, Stack, StackProps } from '../lib'; | |||
import { App } from '../lib/app'; | |||
|
|||
function withApp(context: { [key: string]: any } | undefined, block: (app: App) => void): cxapi.SynthesizeResponse { | |||
const app = new App(context); | |||
const app = new App({ context, autoRun: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make autoRun: false
the default when running outside the context of the toolkit (e.g. CDK_OUT is not set)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autoRun
false is not needed now i guess
Are we also going to change the templates to use this new approach? |
This is only for applications that consist of multiple stacks, our templates are single-stack applications. So, no. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yey! looking forward for this to be merged
packages/@aws-cdk/cdk/lib/app.ts
Outdated
* | ||
* If you set this, you don't have to call `run()` anymore. | ||
* | ||
* @default true if running via CDK toolkit, false otherwise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be more specific about the mechanism: true if running via the toolkit (CDK_OUTDIR is set)
@@ -4,7 +4,7 @@ import { Construct, Resource, Stack, StackProps } from '../lib'; | |||
import { App } from '../lib/app'; | |||
|
|||
function withApp(context: { [key: string]: any } | undefined, block: (app: App) => void): cxapi.SynthesizeResponse { | |||
const app = new App(context); | |||
const app = new App({ context, autoRun: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
autoRun
false is not needed now i guess
@@ -5,4 +5,3 @@ import { %name.PascalCased%Stack } from '../lib/%name%-stack'; | |||
|
|||
const app = new cdk.App(); | |||
new %name.PascalCased%Stack(app, '%name.PascalCased%Stack'); | |||
app.run(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about other langs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expect some integ tests to fail (no idea which one, but ...)
Do you have some examples of how one might use this new feature? |
Stacks no longer accept a
cdk.App
as scope, but acdk.Construct
likeother constructs. This makes it possible define a Construct to
represent your entire application, which can consist of a collection of
Stacks.
Stack names will automatically be derived from their location in the
construct tree, but it's also possible to specify the deployed name of
the stack by specifying the
stackName
property.ALSO IN THIS CHANGE
app.run()
is no longer necessary, but can still safelybe done.
awslint
so that the linter rule suppression keycan easily be copy pasted.
Fixes #1479. This PR replaces #1582.
Pull Request Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.