Skip to content

Latest commit

 

History

History
122 lines (90 loc) · 4.27 KB

File metadata and controls

122 lines (90 loc) · 4.27 KB

Route53 Alias Record Targets for the CDK Route53 Library


cdk-constructs: Stable


This library contains Route53 Alias Record targets for:

  • API Gateway custom domains

    new route53.ARecord(this, 'AliasRecord', {
      zone,
      target: route53.RecordTarget.fromAlias(new alias.ApiGateway(restApi)),
      // or - route53.RecordTarget.fromAlias(new alias.ApiGatewayDomain(domainName)),
    });
  • API Gateway V2 custom domains

    new route53.ARecord(this, 'AliasRecord', {
      zone,
      target: route53.RecordTarget.fromAlias(new alias.ApiGatewayv2Domain(domainName)),
    });
  • CloudFront distributions

    new route53.ARecord(this, 'AliasRecord', {
      zone,
      target: route53.RecordTarget.fromAlias(new alias.CloudFrontTarget(distribution)),
    });
  • ELBv2 load balancers

    new route53.ARecord(this, 'AliasRecord', {
      zone,
      target: route53.RecordTarget.fromAlias(new alias.LoadBalancerTarget(elbv2)),
      // or - route53.RecordTarget.fromAlias(new alias.ApiGatewayDomain(domainName)),
    });
  • Classic load balancers

    new route53.ARecord(this, 'AliasRecord', {
      zone,
      target: route53.RecordTarget.fromAlias(new alias.ClassicLoadBalancerTarget(elb)),
      // or - route53.RecordTarget.fromAlias(new alias.ApiGatewayDomain(domainName)),
    });

Important: Based on AWS documentation, all alias record in Route 53 that points to a Elastic Load Balancer will always include dualstack for the DNSName to resolve IPv4/IPv6 addresses (without dualstack IPv6 will not resolve).

For example, if the Amazon-provided DNS for the load balancer is ALB-xxxxxxx.us-west-2.elb.amazonaws.com, CDK will create alias target in Route 53 will be dualstack.ALB-xxxxxxx.us-west-2.elb.amazonaws.com.

  • GlobalAccelerator

    new route53.ARecord(stack, 'AliasRecord', {
      zone,
      target: route53.RecordTarget.fromAlias(new targets.GlobalAcceleratorTarget(accelerator)),
      // or - route53.RecordTarget.fromAlias(new targets.GlobalAcceleratorTarget('xyz.awsglobalaccelerator.com')),
    });

Important: If you pass the global accelerator target a string rather than an instance of IAccelerator, ensure that the string is a valid domain name of an existing Global Accelerator instance. See the documentation on DNS addressing with Global Accelerator for more info.

  • InterfaceVpcEndpoints

Important: Based on the CFN docs for VPCEndpoints - see here - the attributes returned for DnsEntries in CloudFormation is a combination of the hosted zone ID and the DNS name. The entries are ordered as follows: regional public DNS, zonal public DNS, private DNS, and wildcard DNS. This order is not enforced for AWS Marketplace services, and therefore this CDK construct is ONLY guaranteed to work with non-marketplace services.

new route53.ARecord(stack, "AliasRecord", {
  zone,
  target: route53.RecordTarget.fromAlias(new alias.InterfaceVpcEndpointTarget(interfaceVpcEndpoint))
});
  • S3 Bucket Website:

Important: The Bucket name must strictly match the full DNS name. See the Developer Guide for more info.

const [recordName, domainName] = ['www', 'example.com'];

const bucketWebsite = new Bucket(this, 'BucketWebsite', {
  bucketName: [recordName, domainName].join('.'), // www.example.com
  publicReadAccess: true,
  websiteIndexDocument: 'index.html',
});

const zone = HostedZone.fromLookup(this, 'Zone', {domainName}); // example.com

new route53.ARecord(this, 'AliasRecord', {
  zone,
  recordName, // www
  target: route53.RecordTarget.fromAlias(new alias.BucketWebsiteTarget(bucket)),
});
  • User pool domain

    new route53.ARecord(this, 'AliasRecord', {
      zone,
      target: route53.RecordTarget.fromAlias(new alias.UserPoolDomainTarget(domain)),
    });

See the documentation of @aws-cdk/aws-route53 for more information.