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.

Create repo in stack A and ref it to codepipeline in stack B throws 'cyclic reference'

See original GitHub issue

❓ General Issue

The Question

Stack A has a CodeCommit repo. I want the CodePipeline in Stack B to use this repo. This throws Adding this dependency (cdk-repo -> cdk-pipe/CodePipeline/Resource.Ref) would create a cyclic reference.

I just had a very similar problem #5657 where I manually needed to hard code the artifact bucket. However, this time the resource mentioned in the error is hardcoded. So I am unsure if this me not understanding how this is supposed to work or if this is unexpected behavior.

Code

Here is a repo with an example of what I try to do.

app.py

#!/usr/bin/env python3

from aws_cdk import core

from cdk_repopipe.cdk_repo_stack import RepoStack
from cdk_repopipe.cdk_pipe_stack import PipelineStack


app = core.App()
repo_stack = RepoStack(app, "cdk-repo")
pipe_stack = PipelineStack(app, "cdk-pipe", repo_stack.repo)

app.synth()

repo.py

from aws_cdk import (
    core,
    aws_codecommit as codecommit
)


class RepoStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # The code that defines your stack goes here
        self.repo = codecommit.Repository(self, "my-repo", repository_name="test-repo")

pipeline.py

from aws_cdk import (
    core,
    aws_codecommit as codecommit,
    aws_codebuild as codebuild,
    aws_codepipeline as codepipeline,
    aws_autoscaling as autoscaling,
    aws_codepipeline_actions as codepipeline_actions,
    aws_codedeploy as codedeploy,
    aws_ec2 as ec2,
    aws_s3 as s3
)


class PipelineStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, repo: codecommit.Repository, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Pipeline
        artifactBucket = s3.Bucket(self, 'PipelineBucket',
            bucket_name="bucket-name")

        pipeline = codepipeline.Pipeline(self, "CodePipeline",
            artifact_bucket=s3.Bucket.from_bucket_attributes(self, 'ImportedBucket',
            bucket_name="bucket-name")
        )
        
        # Source
        source_output = codepipeline.Artifact()
        source_action = codepipeline_actions.CodeCommitSourceAction(
            action_name="Source",
            repository=repo,
            output=source_output
        )        
        pipeline.add_stage(stage_name="Source", actions=[source_action])


        # Deploy
        deploy_application = codedeploy.ServerApplication(self, "CodeDeployApplication", 
            application_name="application-name"
        )

        deployment_group = codedeploy.ServerDeploymentGroup(self, "DeploymentGroup",
            application=deploy_application,
        )
        
        deploy_action = codepipeline_actions.CodeDeployServerDeployAction(
            action_name="deploy",
            input=source_output,
            deployment_group=deployment_group
        )
        pipeline.add_stage(stage_name="Deploy", actions=[ deploy_action ])

Environment

  • CDK CLI Version: aws-cli/1.14.44 Python/3.6.9 Linux/5.0.0-37-generic botocore/1.13.13
  • Module Version: 1.19.0 (build 5597bbe)
  • OS: Ubuntu 18.04.3 LTS
  • Language: Python

Other information

The repo has to be in a different stack so it can be used by prod and dev stacks

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
markuslcommented, Mar 6, 2020

@skinny85 I’m also encountering the same issue. Is there any workaround for this behavior until a proper fix is implemented?

0reactions
athempelcommented, Jan 29, 2022

Is this a duplicate of #3087?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling circular dependency errors in AWS CloudFormation
You can use Ref to reference information from another resource. When Resource A has a Ref in its properties to Resource B, Resource...
Read more >
"would create a cyclic reference" when creating CodePipeline ...
I have a stack with an auto scaling group that I reference in a second stack to my deployment group. The aws cdk...
Read more >
CloudFormation managed by CodeCommit and Code ...
CloudCommit is the code versioning and management repository tool in AWS, Git based. It should be familiar to GitHub users for software ...
Read more >
awscdk - Go Packages
func NewBootstraplessSynthesizer_Override(b BootstraplessSynthesizer, ... Used by the CodePipeline construct for the support stacks needed for cross-region ...
Read more >
CodePipeline for Serverless Applications With ... - Levi9
Complex Codepipeline(s) with AWS Templates and Nested Stacks ... If you use Github or other supported repo providers there are build-in webhooks).
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