aws / aws/aws-cdk

S3BucketOrigin.withOriginAccessControl: support for cross-stack (bucket and distribution in separate stacks)

Open
#31,462 24 comments 30 reactions 0 assignees View on GitHub
@aws-cdk/aws-s3 bug effort/medium p1
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

[Issue#21771 ](https://github.com/aws/aws-cdk/issues/21771) recently implemented an L2 construct solution for OAC, which is fantastic! However, for my use case it creates a cyclical dependency between our CloudFront Stack distribution `Resource.Ref` and a separate stack's bucket `Resource.RegionalDomainName`, where withOriginAccessIdentity does not.

Is it possible to allow buckets created outside of the CloudFront Distribution stack to work with the updated L2 as it does for the OAI implementation https://github.com/aws/aws-cdk/blob/v2.158.0/packages/aws-cdk-lib/aws-cloudfront-origins/lib/s3-bucket-origin.ts#L228?

I did double check that moving the bucket to the same stack resolved the cyclical dependency error, but that resolution will not work for our use case.

### Use Case

Unfortunately I am unable to link my code source as its a private emu.
Bucket is created in Stack A
Distribution is created in Stack B referencing bucket from Stack A.

Use case currently works with S3Origin, as well as the updated S3BucketOrigin.withOriginAccessIdentity.

### Proposed Solution

_No response_

### Other Information

_No response_

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

2.158.0

### Environment details (OS name and version, etc.)

Mac OS Sonoma 14.6.1

Contributor guide

Open the contributing guide

Research direction

Start in packages/aws-cdk-lib/aws-cloudfront-origins/lib/s3-bucket-origin.ts, comparing withOriginAccessControl to withOriginAccessIdentity and the existing S3Origin behavior. Reproduce the reported setup with the bucket in Stack A and the distribution in Stack B. Done means cross-stack OAC works without the cyclical dependency reported for the bucket's RegionalDomainName and distribution Resource.Ref.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.