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.

SecurityGroup connections between stacks lead to cyclic references

See original GitHub issue

I’ve notice two cases where I can get a cyclic reference exception when referencing one stack twice within another:

  1. In the example below the props.databaseCluster is coming from a data stack - and I can use either reference on the first or last line to it, but not both.
    // app stack
    const DATABASE_URL = `postgresql://${props.databaseCluster.clusterEndpoint.hostname}`

    const container = taskDefinition.addContainer('app', {
      image: ecs.ContainerImage.fromEcrRepository(props.ecr, props.branch),
      environment: { DATABASE_URL }
    })

    // create a SG for Fargate service
    const secGroup = new ec2.SecurityGroup(this, 'DataAccessSecGrp', {
      vpc: props.vpc,
      allowAllOutbound: true
    })

    // let ECS see RDS
    props.databaseCluster.connections.allowDefaultPortFrom(secGroup, 'allow PG')
  1. I’ve also noticed that I get the same exception if I export two different things from the data stack and try to reference them in the app stack - for example I defined the security group in the data stack and export and try to use it in app stack (along with the databaseCluster export).

The error is something like:

Error: Stack ‘data’ already depends on stack ‘app’. Adding this dependency would create a cyclic reference.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

6reactions
Plasmacommented, Apr 9, 2021

I’m a bit stumped too, for example, defining an Rds instance in one stack, then dependent stacks wanting to attach SG rules seems to easily raise this error.

6reactions
sgronblocommented, Mar 25, 2021

Is this supposed to work this way already? I tried creating a BastionLinuxHost in my FoundationStack. Then I create a DB instance in DBStack. Now an attempt to allow SG access from bastion to db using: this.db.connections.allowDefaultPortFrom(props.bastionHost, 'Allow DB access from bastion') seems to result in a cyclic dependency?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling circular dependency errors in AWS CloudFormation
A common error that you may get when working with AWS CloudFormation is the circular dependency error: error message.
Read more >
How to add a security group to an existing RDS with CDK ...
If I try to call the following command from the deploy stack, I get a cyclic dependency error: props.rdsSG.connections.allowFrom(ecsSG, ec2.Port ...
Read more >
Resolving Circular Dependency between multiple AWS ...
The core.yaml contains security group for the webserver (WebServerSecurityGroup) and ElasticBanstalk. Also, it is importing the resources from the resources.
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 >
Avoiding Circular Dependency Problems in AWS ...
While creating the stack AWS will throw a “Circular dependency between ... that allows all hosts in a Security Group to access each...
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