Package software.amazon.awscdk.services.route53.targets
Route53 Alias Record Targets for the CDK Route53 Library
This library contains Route53 Alias Record targets for:
- API Gateway custom domains
import software.amazon.awscdk.services.apigateway.*; HostedZone zone; LambdaRestApi restApi; ARecord.Builder.create(this, "AliasRecord") .zone(zone) .target(RecordTarget.fromAlias(new ApiGateway(restApi))) .build();
- API Gateway V2 custom domains
import software.amazon.awscdk.services.apigatewayv2.*; HostedZone zone; DomainName domainName; ARecord.Builder.create(this, "AliasRecord") .zone(zone) .target(RecordTarget.fromAlias(new ApiGatewayv2DomainProperties(domainName.getRegionalDomainName(), domainName.getRegionalHostedZoneId()))) .build();
- AppSync custom domains
import software.amazon.awscdk.services.appsync.*; HostedZone zone; GraphqlApi graphqlApi; ARecord.Builder.create(this, "AliasRecord") .zone(zone) .target(RecordTarget.fromAlias(new AppSyncTarget(graphqlApi))) .build();
- CloudFront distributions
import software.amazon.awscdk.services.cloudfront.*; HostedZone zone; CloudFrontWebDistribution distribution; ARecord.Builder.create(this, "AliasRecord") .zone(zone) .target(RecordTarget.fromAlias(new CloudFrontTarget(distribution))) .build();
- ELBv2 load balancers
By providing optional properties, you can specify whether to evaluate target health.
import software.amazon.awscdk.services.elasticloadbalancingv2.*; HostedZone zone; ApplicationLoadBalancer lb; ARecord.Builder.create(this, "AliasRecord") .zone(zone) .target(RecordTarget.fromAlias( new LoadBalancerTarget(lb, Map.of( "evaluateTargetHealth", true)))) .build();
- Classic load balancers
By providing optional properties, you can specify whether to evaluate target health.
import software.amazon.awscdk.services.elasticloadbalancing.*; HostedZone zone; LoadBalancer lb; ARecord.Builder.create(this, "AliasRecord") .zone(zone) .target(RecordTarget.fromAlias( new ClassicLoadBalancerTarget(lb, Map.of( "evaluateTargetHealth", true)))) .build();
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
By providing optional properties, you can specify whether to evaluate target health.
import software.amazon.awscdk.services.globalaccelerator.*; HostedZone zone; Accelerator accelerator; ARecord.Builder.create(this, "AliasRecord") .zone(zone) .target(RecordTarget.fromAlias( new GlobalAcceleratorTarget(accelerator, Map.of( "evaluateTargetHealth", true)))) .build();
Important: If you use GlobalAcceleratorDomainTarget, passing 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.
import software.amazon.awscdk.services.ec2.*; HostedZone zone; InterfaceVpcEndpoint interfaceVpcEndpoint; ARecord.Builder.create(this, "AliasRecord") .zone(zone) .target(RecordTarget.fromAlias(new InterfaceVpcEndpointTarget(interfaceVpcEndpoint))) .build();
- S3 Bucket Website:
Important: The Bucket name must strictly match the full DNS name. See the Developer Guide for more info.
By providing optional properties, you can specify whether to evaluate target health.
import software.amazon.awscdk.services.s3.*; String recordName = "www"; String domainName = "example.com"; Bucket bucketWebsite = Bucket.Builder.create(this, "BucketWebsite") .bucketName(List.of(recordName, domainName).join(".")) // www.example.com .publicReadAccess(true) .websiteIndexDocument("index.html") .build(); IHostedZone zone = HostedZone.fromLookup(this, "Zone", HostedZoneProviderProps.builder().domainName(domainName).build()); // example.com // example.com ARecord.Builder.create(this, "AliasRecord") .zone(zone) .recordName(recordName) // www .target(RecordTarget.fromAlias( new BucketWebsiteTarget(bucketWebsite, Map.of( "evaluateTargetHealth", true)))) .build();
- User pool domain
import software.amazon.awscdk.services.cognito.*; HostedZone zone; UserPoolDomain domain; ARecord.Builder.create(this, "AliasRecord") .zone(zone) .target(RecordTarget.fromAlias(new UserPoolDomainTarget(domain))) .build();
- Route 53 record
HostedZone zone; ARecord record; ARecord.Builder.create(this, "AliasRecord") .zone(zone) .target(RecordTarget.fromAlias(new Route53RecordTarget(record))) .build();
- Elastic Beanstalk environment:
Important: Only supports Elastic Beanstalk environments created after 2016 that have a regional endpoint.
By providing optional properties, you can specify whether to evaluate target health.
HostedZone zone; String ebsEnvironmentUrl; ARecord.Builder.create(this, "AliasRecord") .zone(zone) .target(RecordTarget.fromAlias( new ElasticBeanstalkEnvironmentEndpointTarget(ebsEnvironmentUrl, Map.of( "evaluateTargetHealth", true)))) .build();
See the documentation of aws-cdk-lib/aws-route53
for more information.
-
ClassDescriptionDefines an API Gateway REST API as the alias target.Defines an API Gateway domain name as the alias target.Defines an API Gateway V2 domain name as the alias target.Defines an AppSync Graphql API as the alias target.Use a S3 as an alias record target.Use a classic ELB as an alias record target.Use a CloudFront Distribution as an alias record target.Use an Elastic Beanstalk environment URL as an alias record target.Use a Global Accelerator domain name as an alias record target.Use a Global Accelerator instance domain name as an alias record target.Properties the alias record target.Internal default implementation for
IAliasRecordTargetProps
.A proxy class which represents a concrete javascript instance of this type.Set an InterfaceVpcEndpoint as a target for an ARecord.Use an ELBv2 as an alias record target.Use another Route 53 record as an alias record target.Use a user pool domain as an alias record target.