-
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
Allow setting stackName of Stack inside the Stack #7784
Comments
You can achieve this by simply passing in the stack name to the interface MyStackProps extends StackProps {
cluster: string;
jobNumber: number;
}
class MyStack extends Stack {
constructor(scope: Construct, id: string, props: MyStackProps) {
super(scope, id, {
stackName: `MyStack-${props.jobNumber}-${props.cluster}`,
...props // before/after will impact if consumers can specify a custom `stackName`
});
} Closing for now. Let me know if this is what you are after. |
Hey Elad, thanks for the quick reply. Unfortunately this is still not quite what I am looking for. My stack takes in a few
|
@MitchellJeppson this is not really something we can support. Parameters are resolved only during deployment, and we need to know stack names during synthesis... |
How to achieve this in Java? |
I ran into this problem while trying to solve environment deployment concerns. I want an "Environment" CloudFormation parameter. I am not a fan of synthesizing per environment. I much prefer a "Build once, deploy many" approach to deploying to environments. One CloudFormation and artifacts that will be deployed to any environment. I realized that I can "default" the CfnParameter and hard code the build-time stackName to the initial environment. The stack name can then be set on subsequent deployments. Problem solved. |
@seriouscoderone want to do the same thing. how exactly do you set the stack name on the subsequent deployments? |
@seriouscoderone found this helpful article that explains how mult-env deployments are conceptualized in CDK: Does not exactly solve the problem described here, as it is not "build once, deploy many". But this gave us a solid understanding of how these deployments are meant to work in CDK and that happened to be fine for us. |
@seriouscoderone do you mind sharing more details? |
@eladb how can we pass these values? using command line or env? env is a possibility - straight forward enough. what about as arguments to the cdk deploy command? how to do that? Is there any in built support? or one will have to write custom stuff?
|
@eladb I was wondering if I could request that this be reopened/revisited. My team is rebuilding our application on CDK and we have a lot of shared AWS accounts, meaning we need some way to distinguish resources and stacks across environments. Resources are fine (we can do those with CFn parameters) but there doesn't seem to be a way to change or parameterise the name of the stack itself at deploy time. For the same reasons Michael specified above and others mentioned in #2636, we'd really like to "build once deploy repeatedly" because we don't necessarily have (or want) access to Java/Maven/our code asset repo at deploy time. Ruling out synth-time modification rules out anything in Java (e.g. arguments/env vars as was posted above). So firstly is there anything I'm missing? It seems stackName is validated to a regex that's "numbers/letters/dashes" and blocks If I've got all that right then can I request either:
Anything that means we can run a |
FYI #9261 shows a way to handle some of this that worked for me. |
Thanks, that's an answer for the |
This was a surprise to me as well, but it seems quite a deliberate design decision:
So practically it can be done by defining multiple copies of your stack (https://docs.aws.amazon.com/cdk/latest/guide/stack_how_to_create_multiple_stacks.html), then specifying which one from that menu at Not really ideal if you are already defining a separate set of deployments/stacknames in pipeline deploy code elsewhere that your stack might have previously remained happily unaware of (eg you might just have nothing more than a "small"/"large" parameter in a stack but leave all the naming of actual stacks to pipeline deploy code: thats not possible in cdk, your set of stack names must be now defined twice, in two places). It also makes me uncomfortable that under the hood a separate template json is generated for each separate copy of the stack. Which feels like anti-pattern given that the idea is to absolutely minimise differences between environments, which previously would be encouraged by deploying the same actual template file multiple times. At first I though the environment concept might help model this, but it's not a very good concept of "environment", because it assumes each stack only exists once in an account (it should just be named "Account"). Possibly you could only use |
Yeah I agree with all your points. Our topology is application code in one area, and a separate set of configs for each environment. We're developing for a fairly large organisation and they often tell us to set up a new environment for a specific program of work, and we don't really want to be re-releasing a new version of our codebase to accommodate that. I guess if you were strictly "multi account" (we are for production and a few others, just not dev/test) then you could work with fixed stack names. Good idea with the TBH I think for now we'll just do something like |
Currently you can explicitly set the stack name by passing in the stackName prop to a Stack. It would be nice to be able to dynamically set the stack name within the Stack implementation.
Use Case
I would like to be able to use a stack parameter in the stack name. For example I have parameters cluster=BigCluster and JobNumber=123. I would like the name of my stack to be MyStack-BigCluster-123
Proposed Solution
a
setStackName(String)
method in Stack would be ideal.This is a 🚀 Feature Request
The text was updated successfully, but these errors were encountered: