Skip to content

feat(ec2): implement IPeer to PrefixList to be usable as a connection peer #33617

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

Merged
merged 18 commits into from
May 28, 2025

Conversation

Tietew
Copy link
Contributor

@Tietew Tietew commented Feb 28, 2025

Issue # (if applicable)

Closes #33607.

Reason for this change

When we want to add a security group rule with PrefixList as a connection peer,
we should write redundant prefixList:

const pl = new ec2.PrefixList(this, 'PrefixList', { ... });
instance.connections.allowFrom(ec2.Peer.prefixList(pl.prefixListId), ec2.Port.XXX);

This PR allows us to write DRY:

const pl = new ec2.PrefixList(this, 'PrefixList', { ... });
instance.connections.allowFrom(pl, ec2.Port.XXX);

Description of changes

  • Modify the IPrefixList interface to extend IPeer
  • Implement the required IPeer methods in PrefixListBase

Describe any new or updated permissions being added

Nothing

Description of how you validated changes

Added unit tests and updated an integ test.

Checklist


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 February 28, 2025 02:02
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 star-contributor [Pilot] contributed between 25-49 PRs to the CDK labels Feb 28, 2025
Copy link

codecov bot commented Feb 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.38%. Comparing base (7f2ed96) to head (c209b9b).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #33617   +/-   ##
=======================================
  Coverage   82.38%   82.38%           
=======================================
  Files         120      120           
  Lines        6938     6938           
  Branches     1170     1170           
=======================================
  Hits         5716     5716           
  Misses       1119     1119           
  Partials      103      103           
Flag Coverage Δ
suite.unit 82.38% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk ∅ <ø> (∅)
packages/aws-cdk-lib/core 82.38% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Feb 28, 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)

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Mar 18, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review March 19, 2025 01:49

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

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Mar 19, 2025
@Tietew
Copy link
Contributor Author

Tietew commented May 21, 2025

@ozelalisen Added same jsdocs as IPeer

@ozelalisen ozelalisen self-assigned this May 22, 2025
@@ -8,7 +10,7 @@ import { propertyInjectable } from '../../core/lib/prop-injectable';
/**
* A prefix list
*/
export interface IPrefixList extends IResource {
export interface IPrefixList extends IResource, IPeer {
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I missed one major issue with this PR previously. So I have the following concern:

  • Extending IPrefixList with IPeer represents a backwards compatibility concern since any existing class that implements IPrefixList would now be required to implement additional IPeer interface methods, which would break existing custom implementations for clients.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops!

How about introducing a new interface inherits IPrefixList and IPeer?

// A new interface
export interface IPrefixListWithPeer extends IPrefixList, IPeer { };

// PrefixListBase implements the new interface
abstract class PrefixListBase extends Resource implements IPrefixListWithPeer {
  /* implement IPeer */
}

// PrefixList.fromXXX() returns the new interface
export class PrefixList extends PrefixListBase {
  public static fromPrefixListId(...): IPrefixListWithPeer;
  public static fromLookup(...): IPrefixListWithPeer;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

error: [awslint:from-signature:aws-cdk-lib.aws_ec2.PrefixList.fromPrefixListId] invalid method signature for fromXxx method. If the construct is using the "constructs" module, set the environment variable "AWSLINT_BASE_CONSTRUCT" and re-run (expected="aws-cdk-lib.aws_ec2.IPrefixList",actual="aws-cdk-lib.aws_ec2.IPrefixListWithPeer")

awslint failed. any solution?

Copy link
Member

Choose a reason for hiding this comment

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

@Tietew Sorry about the confusion on this! We had a discussion internally, and your changes by extending IPrefixList does not count as a breaking change, since it is related to implementation upgradability. Your changes are looking good, I will approve your PR.

Copy link
Contributor

mergify bot commented May 28, 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).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Copy link
Contributor

mergify bot commented May 28, 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 c277419 into aws:main May 28, 2025
16 checks passed
Copy link
Contributor

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 May 28, 2025
@Tietew Tietew deleted the ec2-prefixlist-ipeer branch May 29, 2025 04:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. star-contributor [Pilot] contributed between 25-49 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ec2: implement IPeer to PrefixList
4 participants