Skip to content
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

Support for multiple instances of a cdk.App #1479

Closed
BDQ opened this issue Jan 4, 2019 · 3 comments · Fixed by #1940 · May be fixed by MechanicalRock/account-reaper#6
Closed

Support for multiple instances of a cdk.App #1479

BDQ opened this issue Jan 4, 2019 · 3 comments · Fixed by #1940 · May be fixed by MechanicalRock/account-reaper#6
Labels
@aws-cdk/core Related to core CDK functionality feature-request A feature should be added or improved.

Comments

@BDQ
Copy link
Contributor

BDQ commented Jan 4, 2019

The current definition of an environment for CDK seems to be an Account Id + Region pair, but what about a use case where we might want multiple instances of a single App in the same account / region?

In our use case, we want to have many separate staging/qa instances of a (multi-stack) cdk.App - and in some cases each App instance may include slight tweaks to the underlying CDK code.

As a workaround for now, I'm injecting the local branch name into the stack names for each app instance, as follows:

  const app = new cdk.App();

  const registryStack = new RegistryStack(app, `mp-${branchSafe}-ecr`);
  new BuildStack(app, `mp-${branchSafe}-bld` });

  app.run();

It'd be great to have official support for environment / instance labels to allow multiple copies of the same app in the same account/region. Bonus points if it could leverage tags.

@rix0rrr rix0rrr added @aws-cdk/core Related to core CDK functionality feature-request A feature should be added or improved. labels Jan 4, 2019
@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 4, 2019

As a design note, I think a higher-level Construct that:

  • Can contain Stacks.
  • Can set an account/region that applies to all stacks in it.
  • Participates in the generation of the stack names

Should be sufficient to achieve this. Then that containing construct can be instantiated multiple times.

@rix0rrr
Copy link
Contributor

rix0rrr commented Jan 9, 2019

As an additional note about something that I missed last time around: App is designed to only be instantiated once. It's represents the "CDK App", not "your app".

rix0rrr added a commit that referenced this issue Mar 4, 2019
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.
rix0rrr added a commit that referenced this issue Mar 20, 2019
It is now possible for a Construct to contain Stacks. This allows
modeling your application as a single Construct, and instantiating
it multiple times for every environment.

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.
@BDQ
Copy link
Contributor Author

BDQ commented Mar 22, 2019

@rix0rrr - #1940 looks great! Thanks for this, it'll really help clean up my code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/core Related to core CDK functionality feature-request A feature should be added or improved.
Projects
None yet
2 participants