aws / aws/aws-cdk

CDKPipelines: cyclic reference when using cross-region actions

Open
#26,691 3 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/pipelines bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
71

Description

### Describe the bug

A cyclic dependency is created when:

- I create a cross-Region pipeline for regions A (us-west-2) and B (us-east-1)
- that pipeline has a cross-region action in one of the stages
- that cross-region action uses files that need to be transferred from region A to region B
- a cross-region-stack-111111111111:us-east-1 deploys the replication bucket in region B

### Expected Behavior

CDKPipelines creates and manages the cross-region stack and the role that the cross-region action is using. It needs to take care of how it manages dependencies and avoid throwing an error the user cannot fix.

### Current Behavior

```
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.0.0:java (default-cli) on project service: An exception occured while executing the Java class. Error: 'DemoToolchain' depends on 'cross-region-stack-742584497250:us-east-1' ({DemoToolchain}.addDependency({cross-region-stack-742584497250:us-east-1})). Adding this dependency (replication bucket {cross-region-stack-742584497250:us-east-1/Default/CrossRegionCodePipelineReplicationBucket} to action role {DemoToolchain/Pipeline-Demo/Pipeline/UAT/Deploy/CodePipelineActionRole}) would create a cyclic reference.
[ERROR] @jsii/kernel.RuntimeError: Error: 'DemoToolchain' depends on 'cross-region-stack-742584497250:us-east-1' ({DemoToolchain}.addDependency({cross-region-stack-742584497250:us-east-1})). Adding this dependency (replication bucket {cross-region-stack-742584497250:us-east-1/Default/CrossRegionCodePipelineReplicationBucket} to action role {DemoToolchain/Pipeline-Demo/Pipeline/UAT/Deploy/CodePipelineActionRole}) would create a cyclic reference.
[ERROR] at Kernel._Kernel_ensureSync (/private/var/folders/cx/_x5h45_j4j9287h_zmrdtz61lnbmp0/T/jsii-java-runtime18290442372859984211/lib/program.js:10385:23)
[ERROR] at Kernel.invoke (/private/var/folders/cx/_x5h45_j4j9287h_zmrdtz61lnbmp0/T/jsii-java-runtime18290442372859984211/lib/program.js:9749:102)
[ERROR] at KernelHost.processRequest (/private/var/folders/cx/_x5h45_j4j9287h_zmrdtz61lnbmp0/T/jsii-java-runtime18290442372859984211/lib/program.js:11598:36)
[ERROR] at KernelHost.completeCallback (/private/var/folders/cx/_x5h45_j4j9287h_zmrdtz61lnbmp0/T/jsii-java-runtime18290442372859984211/lib/program.js:11585:33)
[ERROR] at KernelHost.processRequest (/private/var/folders/cx/_x5h45_j4j9287h_zmrdtz61lnbmp0/T/jsii-java-runtime18290442372859984211/lib/program.js:11627:24)
[ERROR] at KernelHost.completeCallback (/private/var/folders/cx/_x5h45_j4j9287h_zmrdtz61lnbmp0/T/jsii-java-runtime18290442372859984211/lib/program.js:11585:33)
[ERROR] at KernelHost.processRequest (/private/var/folders/cx/_x5h45_j4j9287h_zmrdtz61lnbmp0/T/jsii-java-runtime18290442372859984211/lib/program.js:11627:24)
[ERROR] at KernelHost.completeCallback (/private/var/folders/cx/_x5h45_j4j9287h_zmrdtz61lnbmp0/T/jsii-java-runtime18290442372859984211/lib/program.js:11585:33)
[ERROR] at KernelHost.processRequest (/private/var/folders/cx/_x5h45_j4j9287h_zmrdtz61lnbmp0/T/jsii-java-runtime18290442372859984211/lib/program.js:11627:24)
[ERROR] at KernelHost.completeCallback (/private/var/folders/cx/_x5h45_j4j9287h_zmrdtz61lnbmp0/T/jsii-java-runtime18290442372859984211/lib/program.js:11585:33)
[ERROR] @jsii/kernel.RuntimeError: Error: 'DemoToolchain' depends on 'cross-region-stack-742584497250:us-east-1' ({DemoToolchain}.addDependency({cross-region-stack-742584497250:us-east-1})). Adding this dependency (replication bucket {cross-region-stack-742584497250:us-east-1/Default/CrossRegionCodePipelineReplicationBucket} to action role {DemoToolchain/Pipeline-Demo/Pipeline/UAT/Deploy/CodePipelineActionRole}) would create a cyclic reference.
```

### Reproduction Steps

- git clone the repository https://github.com/aws-samples/bluegreen-to-amazon-ecs-using-aws-cdk-aws-codedeploy
- Change [this](https://github.com/aws-samples/bluegreen-to-amazon-ecs-using-aws-cdk-aws-codedeploy/blob/main/src/main/java/com/example/demo/Demo.java) and update the line 34 pointing SERVICE_REGION = 'us-east-1' (any region diffferent than "us-west-2")
- `mvn clean package`
- `cdk synth`

### Possible Solution

N/A

### Additional Information/Context

It works well in different scenarios:

- single region action
- cross-account action
- cross-account and cross-region action

### CDK CLI Version

2.79.0

### Framework Version

_No response_

### Node.js Version

18.10.0

### OS

macos and windows

### Language

Java

### Language Version

Java(8) and Java (11)

### Other information

I wonder whether it relates to the following issue:

https://github.com/aws/aws-cdk/issues/25605. Reason I say this is because we have a scenario with two stacks and a replication bucket similar to the scenario described in this issue. Here, this is all managed by CDK.

Contributor guide

Open the contributing guide

Research direction

Start with the Java reproduction in src/main/java/com/example/demo/Demo.java, change SERVICE_REGION as described, then run mvn clean package and cdk synth. Trace the CDKPipelines cross-region stack, replication bucket, and action-role dependencies; done means synthesis no longer reports an unresolvable cyclic reference while the listed scenarios continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, java, typescript
Domain
ci-cd, cloud, devops, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.