Skip to content
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

feat(route53): ip-based routing #28833

Closed
wants to merge 16 commits into from

Conversation

badmintoncryer
Copy link
Contributor

@badmintoncryer badmintoncryer commented Jan 23, 2024

In this PR, I have implemented support for IP-based routing.
We can configure it from the cidrRoutingConfig as shown in the following example:

declare const myZone: route53.HostedZone;

const record1 = new route53.ARecord(this, 'ARecordIpBased1', {
  zone: myZone,
  recordName: 'test',
  target: route53.RecordTarget.fromIpAddresses('1.2.3.4'),
  cidrRoutingConfig: {
    cidrList: ['192.168.1.0/24', '192.168.16.0/20'],
    locationName: 'TokyoServer',
    collectionName: 'myCollection',
  },
});

// You can also add a new Location to an existing CidrCollection
// Ensure all locations for the same record set name and type are part of the same CIDR collection to guarantee consistent routing.
const record2 = new route53.ARecord(this, 'ARecordIpBased2', {
  zone: myZone,
  recordName: 'test',
  target: route53.RecordTarget.fromIpAddresses('2.3.4.5'),
  cidrRoutingConfig: {
    cidrList: ['192.168.2.0/24', '192.168.48.0/20'],
    locationName: 'LondonServer',
    collection: record1.cidrCollection,
  },
});

// To define a zero bit CIDR block (0.0.0.0/0 or ::/0), use the default ("*") location.
const record3 = new route53.ARecord(this, 'ARecordIpBased3', {
  zone: myZone,
  recordName: 'default',
  target: route53.RecordTarget.fromIpAddresses('1.2.3.4'),
  cidrRoutingConfig: {
    locationName: '*',
  },
});

Question

As mentioned above, the existing cidrCollection can be passed as collection argument.
During this process, a new Location is added to the existing Locations in the cidrCollection.
This code works, but I am not confident about the implementation approach. I would greatly appreciate any candid feedback.

if (cidrRoutingConfig.collection) {
      this._cidrCollection = cidrRoutingConfig.collection;
      const currentLocations = this._cidrCollection.locations ?? [];
      const locationsAsArray = Array.isArray(currentLocations) ? currentLocations : [currentLocations];
      this._cidrCollection.addPropertyOverride('Locations', [...locationsAsArray.map((location) => {
        // Since the location is either CfnCidrCollection.LocationProperty or IResolvable,
        // use a type guard function to ascertain its exact type.
        if ('cidrList' in location && 'locationName' in location) {
          return {
            CidrList: location.cidrList,
            LocationName: location.locationName,
          };
        }
        return location;
      }), {
        CidrList: cidrList,
        LocationName: locationName,
      }]);
    }

Closes #28801.


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

@github-actions github-actions bot added the admired-contributor [Pilot] contributed between 13-24 PRs to the CDK label Jan 23, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team January 23, 2024 20:44
@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 labels Jan 23, 2024
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.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@badmintoncryer badmintoncryer force-pushed the 28801-ipBasedRouting branch 3 times, most recently from 130f681 to 660e616 Compare January 26, 2024 15:37
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 26, 2024 17:43

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

@badmintoncryer badmintoncryer marked this pull request as ready for review January 26, 2024 17:47
@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 Jan 26, 2024
*
* @default - Create a new CIDR Collection
*/
collection?: CfnCidrCollection;
Copy link
Contributor Author

@badmintoncryer badmintoncryer Jan 28, 2024

Choose a reason for hiding this comment

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

I understand that it is not preferable to accept L1 resources as arguments. However, there is no L2 construct for CidrCollection, I am using CfnCidrCollection as an argument.

I really wanted to accept an ICidrCollection as an argument. (Is it okay to create an L2 of CidrCollection in this PR?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's fine. Though, it looks like the CidrCollection would just be the first two props here.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

2 similar comments
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

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.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@badmintoncryer badmintoncryer changed the title feat(route53): IP-based routing feat(route53): ip-based routing Feb 10, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review February 10, 2024 07:01

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

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. I see that you've been making progressive changes in this package and we very much appreciate that work. I do see, however, that a lot of props have been added that interact with each other. I think I'd like to know what else you plan to add so that we can work on an overall contract for all those features. Just adding additional optional props that don't always work together is a pattern we avoid now because it isn't a very good user experience.

Comment on lines 257 to 264
cidrList?: string[];
/**
* The name of the location.
*
* When '*' is specified, it is treated as the default location.
* In this case, the cidrList cannot be specified.
*/
locationName: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should't have two props that are reliant on the value of the other to work or not work. Since these two seem to be tightly coupled, we want the contract to enforce that.

Comment on lines 272 to 283
collectionName?: string;
/**
* Existing Cidr Collection.
*
* Use this to add a new Location to an existing Cidr Collection.
* Note that for IP-based routing, all resource record sets for the same record set name and type must reference the same CIDR collection.
*
* @see https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy-ipbased.html
*
* @default - Create a new CIDR Collection
*/
collection?: CfnCidrCollection;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment as above. The peculiarities of how these four props interact should be enforced in the contract.

*
* @default - Create a new CIDR Collection
*/
collection?: CfnCidrCollection;
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's fine. Though, it looks like the CidrCollection would just be the first two props here.

@@ -302,7 +354,14 @@ export class RecordSet extends Resource implements IRecordSet {
if (props.setIdentifier && (props.setIdentifier.length < 1 || props.setIdentifier.length > 128)) {
throw new Error(`setIdentifier must be between 1 and 128 characters long, got: ${props.setIdentifier.length}`);
}
if (props.setIdentifier && props.weight === undefined && !props.geoLocation && !props.region && !props.multiValueAnswer) {
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

We have a problem with the contract here already. I see that a lot of these were newly added. We might need to deprecate a bunch of these and restructure the props here. We shouldn't have so many mutually exclusive options.

@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 Apr 16, 2024
@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@badmintoncryer
Copy link
Contributor Author

oh.. I've forgotten this.

@badmintoncryer badmintoncryer marked this pull request as draft May 10, 2024 03:12
@mergify mergify bot dismissed TheRealAmazonKendra’s stale review May 10, 2024 03:20

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the BUILD FAILING state for 3 weeks, and looks abandoned. To keep this PR from being closed, please continue work on it. If not, it will automatically be closed in a week.

@aws-cdk-automation
Copy link
Collaborator

This PR has been deemed to be abandoned, and will be automatically closed. Please create a new PR for these changes if you think this decision has been made in error.

@aws-cdk-automation aws-cdk-automation added the closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. label Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

route53: support IP-based routing
3 participants