question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to reference resources across multiple levels of nested stacks

See original GitHub issue

Minimal repro

const top = new Stack();
const topLevel = new CfnResource(top, 'toplevel', { type: 'TopLevel' });
const nested1 = new NestedStack(top, 'nested1');
const nested2 = new NestedStack(nested1, 'nested2');

new CfnResource(nested2, 'refToTopLevel', {
  type: 'BottomLevel',
  properties: { RefToTopLevel: topLevel.ref }
});

Original issue

I’m trying to create an EKS Cluster on a NestedStack.

I have all my dependencies separated in NestedStacks (VPC, LoadBalancer, Services). So, it makes sense to have a NestedStack to create my EKS Cluster.

The EKS Cluster can be included in a Main Stack, but not on a Nested. When the EKS Cluster is on a Nested Stack, the cdk gives me the follow error:

jsii.errors.JSIIError: Nested stack 'eks-test/EksCluster' cannot depend on a parent stack 'eks-test'

Reproduction Steps

  • Create a sample app using the cdk
  • Create a NestedStack including an eks cluster
  • Try to synth

Error Log

(.env) ⋊> ~/P/s/eks_test on master ⨯ cdk synth                                                                                                                                                                                      [18:46:48]
jsii.errors.JavaScriptError:
  Error: Nested stack 'eks-test/EksCluster' cannot depend on a parent stack 'eks-test'
      at Object.addDependency (/private/var/folders/w2/t7tdyk5576q1k8kqyjg2ndhh0000gp/T/jsii-kernel-r9YaoT/node_modules/@aws-cdk/core/lib/deps.js:57:15)
      at NestedStack.addDependency (/private/var/folders/w2/t7tdyk5576q1k8kqyjg2ndhh0000gp/T/jsii-kernel-r9YaoT/node_modules/@aws-cdk/core/lib/stack.js:200:16)
      at KubectlProvider.prepareCrossReference (/private/var/folders/w2/t7tdyk5576q1k8kqyjg2ndhh0000gp/T/jsii-kernel-r9YaoT/node_modules/@aws-cdk/core/lib/stack.js:692:28)
      at KubectlProvider.prepareCrossReference (/private/var/folders/w2/t7tdyk5576q1k8kqyjg2ndhh0000gp/T/jsii-kernel-r9YaoT/node_modules/@aws-cdk/aws-cloudformation/lib/nested-stack.js:111:26)
      at KubectlProvider.prepare (/private/var/folders/w2/t7tdyk5576q1k8kqyjg2ndhh0000gp/T/jsii-kernel-r9YaoT/node_modules/@aws-cdk/core/lib/stack.js:560:43)
      at Function.prepare (/private/var/folders/w2/t7tdyk5576q1k8kqyjg2ndhh0000gp/T/jsii-kernel-r9YaoT/node_modules/@aws-cdk/core/lib/construct.js:87:27)
      at Function.synth (/private/var/folders/w2/t7tdyk5576q1k8kqyjg2ndhh0000gp/T/jsii-kernel-r9YaoT/node_modules/@aws-cdk/core/lib/construct.js:51:14)
      at App.synth (/private/var/folders/w2/t7tdyk5576q1k8kqyjg2ndhh0000gp/T/jsii-kernel-r9YaoT/node_modules/@aws-cdk/core/lib/app.js:71:52)
      at _wrapSandboxCode (/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7665:51)
      at Kernel._wrapSandboxCode (/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8301:19)
      at ret._ensureSync (/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7665:25)
      at Kernel._ensureSync (/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8274:20)
      at Kernel.invoke (/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7664:26)
      at KernelHost.processRequest (/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7372:28)
      at KernelHost.run (/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7312:14)
      at Immediate.setImmediate [as _onImmediate] (/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7315:37)
      at runCallback (timers.js:705:18)
      at tryOnImmediate (timers.js:676:5)
      at processImmediate (timers.js:658:5)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "app.py", line 13, in <module>
    app.synth()
  File "/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/aws_cdk/core/__init__.py", line 3585, in synth
    return jsii.invoke(self, "synth", [])
  File "/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_kernel/__init__.py", line 113, in wrapped
    return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
  File "/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_kernel/__init__.py", line 288, in invoke
    args=_make_reference_for_native(self, args),
  File "/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_kernel/providers/process.py", line 348, in invoke
    return self._process.send(request, InvokeResponse)
  File "/Users/rafaelzamanakineippe/Public/sentia/eks_test/.env/lib/python3.7/site-packages/jsii/_kernel/providers/process.py", line 318, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Nested stack 'eks-test/EksCluster' cannot depend on a parent stack 'eks-test'
Subprocess exited with error 1

Environment

  • CLI Version : 1.26.0 (build e251651)
  • Framework Version: 1.26.0
  • OS : MacOS Catalina
  • Language : python

Other

For more information I create the public repository rzamana/cdk_eks_tests


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cmckni3commented, Mar 27, 2020

Experiencing this with 1.31.0 with the DynamoDB replicationRegions custom resource as mentioned in #6726.

0reactions
eladbcommented, Mar 20, 2020

Thanks for letting us know

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with nested stacks - AWS CloudFormation
Nested stacks are stacks created as part of other stacks. You create a nested stack within another stack by using the AWS::CloudFormation::Stack resource....
Read more >
Passing values and parameters to nested stacks - N47
Notes: Cross-stack references across regions cannot be created. You can use the intrinsic function Fn::ImportValue to import only values that ...
Read more >
CloudFormation Stack Policy Archives
A nested stack can be created within another stack by using the AWS::CloudFormation::Stack resource. Nested stacks can be used to define ...
Read more >
CloudFormation Nested Stacks Primer - Trek10
The first thing to realize is that nested stacks are treated just like any other resource in a CloudFormation template. There is nothing...
Read more >
Nested stacks - AWS CloudFormation Workshop
To reference a CloudFormation stack in your template, use the AWS::CloudFormation::Stack resource. ... The TemplateURL property is used to reference the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found