-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws-cdk/aws-s3: cyclic dependency created when adding bucket inventory config cross-stack in a stage #25605
Comments
Could add a check in the code you linked to make sure the scope of the Bucket is in the same stack, and throwing an error otherwise telling the user to import the Bucket like you've done in the workaround. Maybe there's a better solution though |
|
I was finally able to recreate the issue in a unit test, and additionally I can confirm the problem only occurs if the two stacks are both defined on the same The unit test demonstrating the behaviour is here: https://github.com/cloventt/aws-cdk/blob/b5b0025d00ee7087c291b27399d3530a37f8fc6d/packages/aws-cdk-lib/aws-s3/test/bucket.test.ts#L2868-L2922 The test fails with the following output:
It may be relevant to note that the cyclic dependency is only created when using a const parentApp = new cdk.App();
const parentStack = new cdk.Stack(parentApp, 'parent-stage');
const inventoryStack = new cdk.Stack(parentStack, 'inv-stack');
const bucketStack = new cdk.Stack(parentStack, 'bucket-stack'); |
@peterwoodworth would you be able to re-triage this issue? It might be that this is the intended behaviour when constructing stacks inside stages. |
Thanks @cloventt, I'm finding the same behavior. I hadn't noticed this only occurred on synth when using a stage. It's a bug on our end that we're not throwing this on synth without a Stage (I also tested this out with nested stacks just now, it only seems to throw with a Stage as the parent). If you attempt to deploy what gets synthesized, you'll find that the
|
This is a decent preventative solution for the problem still, but there's this other issue you've brought up that it's not properly generating the cross-stack references for some reason when not using a stage. There's probably elsewhere in the codebase that's affected by this bug |
I created a new tracking issue for the problem I described #25621 |
Describe the bug
A cyclic dependency is created when:
Expected Behavior
Buckets should be able to add an inventory config referencing another bucket cross-stack.
Current Behavior
Adding a cross-stack bucket inventory config inside a stage creates a cyclic dependency, causing the build to fail.
Reproduction Steps
bucket.addInventory()
on bucket B, setting bucket A as the destinationPossible Solution
I think the issue occurs because of this code here:
aws-cdk/packages/aws-cdk-lib/aws-s3/lib/bucket.ts
Lines 2357 to 2372 in b885ece
Essentially, the lib is trying to be helpful and add a policy on the destination bucket to make sure the source bucket can write to the destination correctly. However, there is no way to disable this behaviour if for example you want to manage your own bucket policies in the stacks separately. Doing so would allow me to remove the cyclic dependency.
Alternatively, allowing the user to optionally pass a bucket name instead of the entire
Bucket
object to thes3.InventoryDestination
would allow this cycle to be broken.Additional Information/Context
A workaround is to move the buckets to both be on the same stack.
I found another workaround which was to do something like this:
The
Bucket.fromBucketArn()
static method returns anIBucket
which does not trigger the addition of the inline policy on the destination bucket.CDK CLI Version
2.79.1
Framework Version
No response
Node.js Version
19
OS
Linux
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: