Skip to content

Remove the need for App boilerplate #216

@eladb

Description

@eladb

All CDK apps today have this boilerplate.

JavaScript:

const app = new App(process.argv);
// add stack here
process.stdout.write(app.run());

Java:

public static void main(final String argv[]) {
    App app = new App(Arrays.asList(argv));
    // add stack here
    System.out.writeln(app.run());
}

The reason we need this boilerplate is due to how the toolkit and CDK apps interact, and the fact that the toolkit is language-agnostic. As far as the toolkit is concerned, CDK apps are executables that adhere to the "cx-api" interface, which is using ARGV to accept inputs and STDOUT as outputs. This is the lowest common denominator across languages (any language out there allows you to write programs that accept ARGV and emit STDOUT).

This is all good an fine, but there's no value in exposing this to users if we can provide a better experience (understanding this protocol is not something that most users will benefit from).

Let's modify the protocol such that instead of ARGV/STDOUT it will pass in the toolkit request via environment variables and the output will be emitted to a temporary working directory. This will make the app boilerplate code look like this:

const app = new cdk.App();

new MyStack(app, 'stack1');
new YourStack(app, 'stack2');

app.run();

Much cleaner.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions