aws-cdk: [aws-codepipeline] Cyclic reference error when importing an S3 bucket in a code pipeline defined in a different stack
❓ General Issue
Hi- I am using CDK to create a code pipeline with an S3 bucket as its source. The S3 bucket and code pipeline are defined in different stacks and per the AWS documentation we can access resources in a different stack as long as they are in the same account and AWS region: https://docs.aws.amazon.com/cdk/latest/guide/resources.html#resource_stack
The Question
This doesn’t seem to be working and I am getting a “Cyclic reference” error. Does this mean the AWS documentation is wrong? Or is there something in particular that’s missing to make this work? Sample code below
const pipelineSourceActionOutput = new Artifact();
const pipelineSourceAction = new S3SourceAction({
actionName: "S3SourceAction",
bucket: s3Bucket, // Versioned Bucket (and CloudTrail) defined in a different stack
bucketKey: `${id}/upload.zip`,
output: pipelineSourceActionOutput,
trigger: S3Trigger.EVENTS,
runOrder: 1,
});
new Pipeline(this, pipelineId, {
pipelineName: pipelineId,
stages: [
{
stageName: "Source",
actions: [pipelineSourceAction],
}
],
});
I think this line of code is causing the dependency of my stack containing S3 bucket on the stack that defined code pipeline infra: https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/aws-codepipeline-actions/lib/s3/source-action.ts#L120-L124
Environment
- CDK CLI Version: 1.45.0
- Module Version:
- Node.js Version: 12.x.31654.0
- OS: OSX Mojave
- Language (Version): TypeScript
Other information
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (11 by maintainers)
Commits related to this issue
- fix(codepipeline-actions): cross stack reference causes stack cycle in sources that use CloudWatch Events (#20149) When using a newly-created, CDK-managed resource, such as an S3 Bucket or a CodeComm... — committed to aws/aws-cdk by skinny85 2 years ago
- fix(codepipeline-actions): cross stack reference causes stack cycle in sources that use CloudWatch Events (#20149) When using a newly-created, CDK-managed resource, such as an S3 Bucket or a CodeComm... — committed to josephedward/aws-cdk by skinny85 2 years ago
@jzybert in the pipeline, you shouldn’t provide
sourceandartifactsfor a CodeBuild Project, because those are controlled through the pipeline itself.Use the
PipelineProjectclass instead ofProject, and that will become much more clear 🙂.