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.

[appmesh] VirtualNode in separate stack from Mesh creates circular dependency

See original GitHub issue

Adding a VirtualNode to a Mesh (where the Mesh is in one stack and the VirtualNode is in another) creates an circular reference, but shouldn’t.

Reproduction Steps

Sample code available at buzzsurfr/appmesh-cross-stack-bug

Sample code in master branch works, but uncommenting the following lines…

https://github.com/buzzsurfr/appmesh-cross-stack-bug/blob/e374561e516c328ed90de2add287b2d81153a642/lib/meshed-service-stack.ts#L103-L112

…then run:

npm run build
cdk ls

What did you expect to happen?

This shouldn’t be a circular reference and should work.

What actually happened?

/Users/username/Sandbox/cdk/appmesh-cross-stack-bug/node_modules/@aws-cdk/core/lib/stack.ts:688
      throw new Error(`'${target.node.path}' depends on '${this.node.path}' (${cycle.join(', ')}). Adding this dependency (${reason}) would create a cyclic reference.`);
            ^
Error: 'InfrastructureStack' depends on 'MeshedServiceStack' (InfrastructureStack -> MeshedServiceStack/service/CloudmapService/Resource.Name). Adding this dependency (MeshedServiceStack -> InfrastructureStack/Mesh/Resource.MeshName) would create a cyclic reference.
    at MeshedServiceStack._addAssemblyDependency (/Users/username/Sandbox/cdk/appmesh-cross-stack-bug/node_modules/@aws-cdk/core/lib/stack.ts:688:13)
    at Object.addDependency (/Users/username/Sandbox/cdk/appmesh-cross-stack-bug/node_modules/@aws-cdk/core/lib/deps.ts:52:20)
    at MeshedServiceStack.addDependency (/Users/username/Sandbox/cdk/appmesh-cross-stack-bug/node_modules/@aws-cdk/core/lib/stack.ts:445:5)
    at resolveValue (/Users/username/Sandbox/cdk/appmesh-cross-stack-bug/node_modules/@aws-cdk/core/lib/private/refs.ts:101:12)
    at Object.resolveReferences (/Users/username/Sandbox/cdk/appmesh-cross-stack-bug/node_modules/@aws-cdk/core/lib/private/refs.ts:31:24)
    at Object.prepareApp (/Users/username/Sandbox/cdk/appmesh-cross-stack-bug/node_modules/@aws-cdk/core/lib/private/prepare-app.ts:36:5)
    at Object.synthesize (/Users/username/Sandbox/cdk/appmesh-cross-stack-bug/node_modules/@aws-cdk/core/lib/private/synthesis.ts:21:3)
    at App.synth (/Users/username/Sandbox/cdk/appmesh-cross-stack-bug/node_modules/@aws-cdk/core/lib/stage.ts:175:23)
    at process.<anonymous> (/Users/username/Sandbox/cdk/appmesh-cross-stack-bug/node_modules/@aws-cdk/core/lib/app.ts:112:45)
    at Object.onceWrapper (events.js:422:26)
Subprocess exited with error 1

Environment

  • CLI Version : 1.61.1 (build 347918f)
  • Framework Version: ^1.61.1
  • Node.js Version: v13.12.0
  • OS : macOS Catalina 10.15.6
  • Language (Version): TypeScript (3.9.7)

Other


This is 🐛 Bug Report

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Seiya6329commented, Jun 21, 2021

I think the only possible action from this might be adding some clarification to the documentation of the various add*() methods in AppMesh that they create a resource in the same Stack as the object they are called on (the Mesh in case of VirtualNode), which might be different than the current Stack.

This is really great point and has been suggested by @dfezzie as well.

Conclusion:

  • No actions to change the code
  • Update the CDK documentation to clarify the difference of using .add() method and the constructor to create a resource.
1reaction
skinny85commented, Jun 21, 2021

I think I agree with your conclusions @Seiya6329. Looks like I was worried about that new VirtualNode(... case for nothing 🙂.

This looks to be just a matter of various references between CDK constructs causing dependencies between Stacks. I don’t think there’s anything unusual here for AppMesh.

For the problem posted originally in the issue, it’s just a matter of changing from:

        const virtualNode = props.mesh.addVirtualNode('vn', {
            serviceDiscovery: appmesh.ServiceDiscovery.cloudMap({
                service: service.cloudMapService!,
            }),
            listeners: [appmesh.VirtualNodeListener.http({
                port: appContainer.containerPort,
            })],
        });

to:

        const virtualNode = new appmesh.VirtualNode(this, 'vn', {
            mesh: props.mesh,
            serviceDiscovery: appmesh.ServiceDiscovery.cloudMap({
                service: service.cloudMapService!,
            }),
            listeners: [appmesh.VirtualNodeListener.http({
                port: appContainer.containerPort,
            })],
        });

to solve the cycle.

I think the only possible action from this might be adding some clarification to the documentation of the various add*() methods in AppMesh that they create a resource in the same Stack as the object they are called on (the Mesh in case of VirtualNode), which might be different than the current Stack. But I think that 's as far as any code changes are needed here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-cdk/aws-appmesh module - AWS Documentation
AWS App Mesh is a service mesh based on the Envoy proxy that makes it easy ... the same stack as the mesh...
Read more >
awsappmesh - Go Packages
AWS App Mesh is a service mesh based on the Envoy proxy that makes it easy to ... across stacks (or nested stack)...
Read more >
Introduction to AWS App Mesh - AWS Online Tech Talks
To learn more, please visit: https://aws.amazon.com/app-meshAWS App Mesh is a service mesh that makes it easy to monitor and control ...
Read more >
Weird circular dependency issue when updating a CDK ec2 ...
I am using CDK pipelines here to deploy a very simple stack. The stack consists of 2 sub-stacks: an Aurora cluster and an...
Read more >
AWS::AppMesh::VirtualNode - Amazon CloudFormation
Creates a virtual node within a service mesh. A virtual node acts as a logical pointer to a particular task group, such as...
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