Skip to content

Conversation

@otaviomacedo
Copy link
Contributor

@otaviomacedo otaviomacedo commented Jul 22, 2025

This PR introduces a new set of minimal L1 interfaces to address resources in the CDK APIs.

New interfaces

They are named like IBucketRef (and IInstanceRef, IKeyRef, etc), which is an interface similar to IBucket but lives at the L1 level instead of the L2 level. It allows "pointing to a bucket" in a typed way. The L1 CfnBucket implements IBucketRef, and the L2 IBucket extends IBucketRef. IBucketRef doesn't have any of the additional handwritten conveniences afforded by IBucket, but because it doesn't involve any handwritten code this it to be implemented by the L1 CfnBucket.

We've then gone through all APIs where an IBucket was expected, and if that call site didn't use any of the facilities exposed by IBucket we've replaced the type with IBucketRef.

The result is that in those APIs, it is now possible to transparently pass both L1 and L2 resources, instead of only L2 resources. This gives you the freedom of picking between L1s and L2s as your need dictate.

If you are implementing IBucket yourself

If you are writing classes that implement IBucket, you now have an additional implementation burden:

interface IBucketRef {
  /** This property is new */
  public readonly bucketRef: BucketReference;
}

You should copy this value from elsewhere, for example from CfnBucket or a Bucket you wrap:

export MyBucketClass implements IBucket {
  
  /** Add a getter for it */
  public get bucketRef(): BucketReference {
    return this.wrappedBucket.bucketRef;
  }
}

Future work

This work is the first step in a series of changes that will make it easier for L1 and L2 classes to interoperate, and to progressively add enhancements to L1s in a way that doesn't require implementing full L2s. The goal is to make CDK more expressive with less upfront work.

Experimental

This work is considered experimental, and it may change; we may still add { account; region } to to the BucketReference struct (which is why you should copy it an underlying object, and not try to construct one yourself).

We may also roll back this change entirely and remove the interfaces we introduced here, so don't start referencing IBucketRef in your own code just yet.

To limit the impact, these are introduced currently only for the following services: IAM, S3, EC2, KMS, CloudFront.

Feedback

If you have opinions on this change, don't hesitate to let us know via the issue tracker or via a Direct Message on Slack.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team July 22, 2025 16:05
@github-actions github-actions bot added the p2 label Jul 22, 2025
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jul 22, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

@otaviomacedo otaviomacedo added pr-linter/exempt-readme The PR linter will not require README changes pr-linter/exempt-integ-test The PR linter will not require integ test changes labels Jul 23, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review July 23, 2025 09:03

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jul 23, 2025
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: b00f7bc
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@jiayiwang7 jiayiwang7 requested a review from rix0rrr August 6, 2025 14:50
@otaviomacedo otaviomacedo marked this pull request as draft August 8, 2025 09:20
@otaviomacedo otaviomacedo marked this pull request as ready for review August 11, 2025 08:38
@rix0rrr
Copy link
Contributor

rix0rrr commented Aug 12, 2025

  • I think we probably need to extend IResource rather than IConstruct.

  • I wonder if ICfnAlias sends the wrong message. I was thinking IAliasRef might be nicer (but I'm open to better ideas)

@otaviomacedo
Copy link
Contributor Author

I think we probably need to extend IResource rather than IConstruct.

But IResource extends IConstruct, and then we have the same problem.

I wonder if ICfnAlias sends the wrong message. I was thinking IAliasRef might be nicer (but I'm open to better ideas)

Not particularly attached to any name. I can change it to I[Resource]Ref, but it's going to be even harder to exclude these interfaces from the construct-interface-extends-iconstruct rule.

@otaviomacedo otaviomacedo added the pr/do-not-merge This PR should not be merged at this time. label Aug 13, 2025
@rix0rrr rix0rrr changed the title feat: new resource reference interfaces feat: new resource reference interfaces (ref-interfaces #1) Aug 19, 2025
rix0rrr and others added 8 commits August 19, 2025 16:59
…#2) (#35271)

Implementing the interfaces from
#35032 for L2s.

----

*By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license*

---------

Co-authored-by: Otavio Macedo <[email protected]>
@rix0rrr rix0rrr changed the title feat: new resource reference interfaces (ref-interfaces #1) feat: new resource reference interfaces Sep 2, 2025
@rix0rrr rix0rrr changed the title feat: new resource reference interfaces feat: new resource interfaces shared by both L1s and L2s Sep 2, 2025
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 2, 2025
otaviomacedo and others added 2 commits September 2, 2025 16:26
…erfaces #3) (#35282)

Using the updated interfaces from
#35271.

----

*By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license*

---------

Co-authored-by: Rico Huijbers <[email protected]>
Co-authored-by: Feng He <[email protected]>
Co-authored-by: Kazuho Cryer-Shinozuka <[email protected]>
Co-authored-by: Chooi Je Qin <[email protected]>
Co-authored-by: claypack <[email protected]>
Co-authored-by: Hung Tran <[email protected]>
Co-authored-by: matoom-nomu <[email protected]>
@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Sep 3, 2025
@mergify
Copy link
Contributor

mergify bot commented Sep 3, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Sep 3, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 5e8c0d5 into main Sep 3, 2025
18 checks passed
@mergify mergify bot deleted the otaviom/resource-ref-interface branch September 3, 2025 12:57
@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-readme The PR linter will not require README changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants