-
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
Docs lack examples or explanation of how to export and import values between stacks #10480
Comments
Hi @jpSimkins, you should be able to just implicitly import resources from one stack to another, see the docs and this PR. I agree that we should probably have a section in the docs that talks about best approaches when designing a multi stack app. In the meantime, I suggest looking at the Cloudformation docs and this helpful user's guide. |
Thank you @SomayaB What I was trying to accomplish is something where I do not need to be aware of the ids or anything. Ideally, I wanted to point to a stack and then an output value of the stack. It seems this is not possible with CDK. I tried to use Terraform has a remote states system that is more easily malleable for IaC. This is where I am getting this design from and from what I have seen, it's just not something possible with the CDK. That is what I needed to identify. So in order to use the CDK for IaC, I need to keep track of IDs and use them throughout the code. Thank you for the links, I see that using a cdk.json file may be useful for this approach or even a constants file with these IDs would suffice, I was just looking for a more elegant solution. Thanks for your insights on this. |
To update this ticket in-case future searches find this: To use e.g.: Output in StackA: new CfnOutput(this, 'VpcId', {
value: this._sg_AllowRDSAccess.securityGroupId,
exportName: 'StackA-VpcId' // This is the name you will use for the import
}); Stack B usage: const VPC_ID = Fn.importValue('StackA-VpcId'); One more thing to make note of, and something that makes using The VPC example I provided above, is such a case. I am forced to hard-code the VpcID in my code because using
Meaning, the token that is a placeholder for the value will throw this error. I find this severely limits the usage of these as they tend to break in the CDK and hard-coding these values solves that issue. Not sure if there is any concerns to solve this issue but I find this limitation to render this useless. |
|
I am new to the CDK and do not use CloudFormation as I prefer Terraform over CloudFormation. I mention this only because it seems if you have CloudFormation experience, this may be easy to identify how to do this but for someone with none, this seems to be impossible although there are numerous discussions about being able to... but no working examples.
One issue that I am still trying to identify is how I can export values from a stack so that I can import them in another stack.
I currently use
CfnOutput
to output the values but this doesn't seem to allow me to import them into another stack.I see this ticket: #603 that has expirewd links and explains about
Outputs
&Parameters
, andExports
&Fn::ImportValues
. I think the most useful part of that ticket is: #603 (comment)I am able to make outputs but I still cannot figure out how to import the outputs so I can use them in another stack. I am also considering using SSM as this seems to be the easiest way to do this but I feel this is a hack.
This leads me to another question that is a result of this design. What is the best approach to designing stacks?
I don't think having a single stack for the entire AWS account is ideal. I was first using nested stacks and passing the variables of each stack into each nested stack as needed. This works but it doesn't seem ideal as every deploy I do is the entire account, not just the part I am working on. Is this concern even worth worrying about?
I typically have a base stack which is the VPC, RDS, and a bastion. I then have a few other nested stacks that are in the actual project. I can pass in the base stack and I have getters that can be used to get the VPC or RDS details. Again, this is not what I want.
What I am trying to do is have my base stack use outputs. I then want to import these outputs in each stack that needs them. I can use this same design for all systems and this seems much cleaner and easier to manage to me.
This is a 📕 documentation issue
The text was updated successfully, but these errors were encountered: