Skip to content

Cross stack reference caused "cyclic reference" error #3087

@darren-dazh

Description

@darren-dazh

Note: for support questions, please first reference our documentation, then use Stackoverflow. This repository's issues are intended for feature requests and bug reports.

  • I'm submitting a ...

    • 🪲 bug report
    • 🚀 feature request
    • 📚 construct library gap
    • ☎️ security issue or vulnerability => Please see policy
    • ❓ support request => Please see note at the top of this template.
  • What is the current behavior?
    If the current behavior is a 🪲bug🪲: Please provide the steps to reproduce

I created 2 stacks - one for CodeCommit repository, and the other for CodePipeline which takes the previous one as source stage.

class CodeRepo(core.Stack):
......
    self.repo = codecommit.Repository(
            self,
            id='CodeCommitRepo',
            repository_name=repo_name
        )

class MyPipeline(core.Stack):
......
        def __init__(self, scope: core.Construct, id: str, code_repo: codecommit.IRepository) -> None:
            ......
            # create CodePipeline and its stages.
            pipeline = codepipeline.Pipeline(self, id='CodePipeline', pipeline_name='pipeline', restart_execution_on_update=False)

            source_stage = pipeline.add_stage(stage_name='Source')
            source_stage.add_action(
                codepipeline_actions.CodeCommitSourceAction(
                    action_name='action',
                    repository=code_repo,
                    branch='master',
                    output=codepipeline.Artifact(artifact_name='output'),
                    trigger=codepipeline_actions.CodeCommitTrigger.EVENTS
                )
            )

app = core.App() 
repo_stack = CodeRepo(app, 'repo_stack')
pipeline_stack = MyPipeline(app, 'pipeline_stack', repo_stack.repo)

app.synth()

Then I got following error:

File "./venv/lib/python3.6/site-packages/aws_cdk/core/__init__.py", line 2905, in synth
    return jsii.invoke(self, "synth", [])
  File "./venv/lib/python3.6/site-packages/jsii/_kernel/__init__.py", line 104, in wrapped
    return _recursize_dereference(kernel, fn(kernel, *args, **kwargs))
  File "./venv/lib/python3.6/site-packages/jsii/_kernel/__init__.py", line 258, in invoke
    args=_make_reference_for_native(self, args),
  File "./venv/lib/python3.6/site-packages/jsii/_kernel/providers/process.py", line 346, in invoke
    return self._process.send(request, InvokeResponse)
  File "./venv/lib/python3.6/site-packages/jsii/_kernel/providers/process.py", line 316, in send
    raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: 'pipeline_stack' depends on 'repo_stack' (pipeline_stack/CodePipeline/Role/DefaultPolicy/Resource -> repo_stack/CodeCommitRepo/Resource.Arn). Adding this dependency (repo_stack/CodeCommitRepo/pipelinestackCodePipelineA06C8E1EEventRule/Resource -> pipeline_stack/CodePipeline/Resource.Ref) would create a cyclic reference.

An interesting observation is, if i put codecommit.Repository(...) in the pipeline_stack and refer the repo resource as usual, everything works without cyclic dependency.

  • What is the expected behavior (or behavior of feature suggested)?
    CDK is expected to handle the dependency issue, as described on aws doc for "Passing Resources from a Different Stack".

  • What is the motivation / use case for changing the behavior or adding this feature?

  • Please tell us about your environment:

    • CDK CLI Version: 0.36.0
    • Module Version: 0.36.0
    • OS: [ OSX Mojave ]
    • Language: [ Python ]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. associated pull-request, stackoverflow, gitter, etc)

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-codecommitRelated to AWS CodeCommit@aws-cdk/aws-codepipelineRelated to AWS CodePipelinebugThis issue is a bug.cross-stackRelated to cross-stack resource sharingeffort/largeLarge work item – several weeks of effortin-progressThis issue is being actively worked on.p1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions