aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

feat(route53): ip-based routing

Open badmintoncryer opened this issue 2 years ago • 7 comments

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

badmintoncryer avatar Jan 23 '24 20:01 badmintoncryer

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 avatar Feb 08 '24 00:02 aws-cdk-automation

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 avatar Feb 09 '24 00:02 aws-cdk-automation

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 avatar Feb 10 '24 00:02 aws-cdk-automation

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 avatar Apr 01 '24 00:04 aws-cdk-automation

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.

aws-cdk-automation avatar May 08 '24 00:05 aws-cdk-automation

oh.. I've forgotten this.

badmintoncryer avatar May 08 '24 00:05 badmintoncryer

AWS CodeBuild CI Report

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

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

aws-cdk-automation avatar May 14 '24 00:05 aws-cdk-automation

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 avatar Jun 05 '24 00:06 aws-cdk-automation

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 avatar Jun 12 '24 00:06 aws-cdk-automation