-
Notifications
You must be signed in to change notification settings - Fork 4k
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
misleading init templates and sample app #5903
Comments
I'm not strongly opinionated on this. FWIW, I like our current structure because it hints at a potential code organization that we should encourage for large CDK appplications, namely, separate file per stack. Keeps the app configuration separate from the stack configuration. In the world where we're doing CI/CD, all stacks are defined in their own classes and the account to stack mapping (+ configuration) sits alongside the app definition. |
How about making this even simpler for the simple use case? import { SingleStackApp } from '@aws-cdk/core';
import * as s3 from '@aws-cdk/aws-s3';
const app = new SingleStackApp();
new s3.Bucket(app, 'MyBucket');
app.synth(); |
I think the difference between users and authors is already there with the I really like the current structure and it works well in several scenarios. |
I think the main problem with the current template is that stacks should not live under In the
export class MyConstruct { ... } And then:
import { MyConstruct } from './lib/my-construct.ts'
const app = new SingleStackApp(app, 'MyStack');
new MyConstruct(stack, '...');
app.synth() |
Now i'm leaning towards simply changing |
@eladb I don't agree with the super-simple one-file approach, We had that in the beginning and people made these monstrosities of monofiles that held many levels of abstractions. @iliapolo what about having the created Construct in |
This issue has not received any attention in 1 year. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
❓ General Issue
Our current init templates and sample app don't really encourage the behavior and programming model we want customers to adopt.
The problem is this:
The fact we are defaulting to extending
cdk.Stack
sets users in a trajectory to actually useStacks
as the sharable, reusable, component. In reality, these components should simply be regular constructs.A
Stack
might encapsulate deployment context that isn't really sharable or generic:It feels like our core
Stack
(similar toApp
) object should be used when defining the actual application that will be deployed (what we currently define inbin
), and not the re-usable component (what we currently define inlib
).@eladb Did mention that
Stacks
can be used inside organizations to enforce specific policies related to deployment, but that probably shouldn't be our main use-case.As far as templates and examples go, we should have a distinction between customers who are merely construct users, and those who are construct authors.
For example, for users, perhaps a more natural and simplified version of the template could be:
index.ts
This structure is much simpler for customers who simply want to create a stack and deploy it.
For authors, which are more advanced customers, we can stick to our current template structure, but extending
cdk.Construct
instead ofcdk.Stack
.This distinction, between authors and users, is valid and exists in most programming languages and tools, with regards to best practices and such.
We should also probably create a some kind of best practices document, which will also detail when should you actually choose to extend
Stack
instead ofConstruct
.The Question
Thoughts?
Environment
The text was updated successfully, but these errors were encountered: