1.204.0 • Published 10 months ago

@aws-cdk/aws-route53 v1.204.0

Weekly downloads
287,276
License
Apache-2.0
Repository
github
Last release
10 months ago

Amazon Route53 Construct Library


End-of-Support

AWS CDK v1 has reached End-of-Support on 2023-06-01. This package is no longer being updated, and users should migrate to AWS CDK v2.

For more information on how to migrate, see the Migrating to AWS CDK v2 guide.

doc: https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html


To add a public hosted zone:

new route53.PublicHostedZone(this, 'HostedZone', {
  zoneName: 'fully.qualified.domain.com',
});

To add a private hosted zone, use PrivateHostedZone. Note that enableDnsHostnames and enableDnsSupport must have been enabled for the VPC you're configuring for private hosted zones.

declare const vpc: ec2.Vpc;

const zone = new route53.PrivateHostedZone(this, 'HostedZone', {
  zoneName: 'fully.qualified.domain.com',
  vpc,    // At least one VPC has to be added to a Private Hosted Zone.
});

Additional VPCs can be added with zone.addVpc().

Adding Records

To add a TXT record to your zone:

declare const myZone: route53.HostedZone;

new route53.TxtRecord(this, 'TXTRecord', {
  zone: myZone,
  recordName: '_foo',  // If the name ends with a ".", it will be used as-is;
                       // if it ends with a "." followed by the zone name, a trailing "." will be added automatically;
                       // otherwise, a ".", the zone name, and a trailing "." will be added automatically.
                       // Defaults to zone root if not specified.
  values: [            // Will be quoted for you, and " will be escaped automatically.
    'Bar!',
    'Baz?',
  ],
  ttl: Duration.minutes(90),       // Optional - default is 30 minutes
});

To add a NS record to your zone:

declare const myZone: route53.HostedZone;

new route53.NsRecord(this, 'NSRecord', {
  zone: myZone,
  recordName: 'foo',  
  values: [            
    'ns-1.awsdns.co.uk.',
    'ns-2.awsdns.com.',
  ],
  ttl: Duration.minutes(90),       // Optional - default is 30 minutes
});

To add a DS record to your zone:

declare const myZone: route53.HostedZone;

new route53.DsRecord(this, 'DSRecord', {
  zone: myZone,
  recordName: 'foo',
  values: [
    '12345 3 1 123456789abcdef67890123456789abcdef67890',
  ],
  ttl: Duration.minutes(90),       // Optional - default is 30 minutes
});

To add an A record to your zone:

declare const myZone: route53.HostedZone;

new route53.ARecord(this, 'ARecord', {
  zone: myZone,
  target: route53.RecordTarget.fromIpAddresses('1.2.3.4', '5.6.7.8'),
});

To add an A record for an EC2 instance with an Elastic IP (EIP) to your zone:

declare const instance: ec2.Instance;

const elasticIp = new ec2.CfnEIP(this, 'EIP', {
  domain: 'vpc',
  instanceId: instance.instanceId,
});

declare const myZone: route53.HostedZone;
new route53.ARecord(this, 'ARecord', {
  zone: myZone,
  target: route53.RecordTarget.fromIpAddresses(elasticIp.ref),
});

To add an AAAA record pointing to a CloudFront distribution:

import * as cloudfront from '@aws-cdk/aws-cloudfront';

declare const myZone: route53.HostedZone;
declare const distribution: cloudfront.CloudFrontWebDistribution;
new route53.AaaaRecord(this, 'Alias', {
  zone: myZone,
  target: route53.RecordTarget.fromAlias(new targets.CloudFrontTarget(distribution)),
});

Constructs are available for A, AAAA, CAA, CNAME, MX, NS, SRV and TXT records.

Use the CaaAmazonRecord construct to easily restrict certificate authorities allowed to issue certificates for a domain to Amazon only.

To add a NS record to a HostedZone in different account you can do the following:

In the account containing the parent hosted zone:

const parentZone = new route53.PublicHostedZone(this, 'HostedZone', {
  zoneName: 'someexample.com',
  crossAccountZoneDelegationPrincipal: new iam.AccountPrincipal('12345678901'),
  crossAccountZoneDelegationRoleName: 'MyDelegationRole',
});

In the account containing the child zone to be delegated:

const subZone = new route53.PublicHostedZone(this, 'SubZone', {
  zoneName: 'sub.someexample.com',
});

// import the delegation role by constructing the roleArn
const delegationRoleArn = Stack.of(this).formatArn({
  region: '', // IAM is global in each partition
  service: 'iam',
  account: 'parent-account-id',
  resource: 'role',
  resourceName: 'MyDelegationRole',
});
const delegationRole = iam.Role.fromRoleArn(this, 'DelegationRole', delegationRoleArn);

// create the record
new route53.CrossAccountZoneDelegationRecord(this, 'delegate', {
  delegatedZone: subZone,
  parentHostedZoneName: 'someexample.com', // or you can use parentHostedZoneId
  delegationRole,
});

Imports

If you don't know the ID of the Hosted Zone to import, you can use the HostedZone.fromLookup:

route53.HostedZone.fromLookup(this, 'MyZone', {
  domainName: 'example.com',
});

HostedZone.fromLookup requires an environment to be configured. Check out the documentation for more documentation and examples. CDK automatically looks into your ~/.aws/config file for the [default] profile. If you want to specify a different account run cdk deploy --profile [profile].

new MyDevStack(app, 'dev', { 
  env: { 
    account: process.env.CDK_DEFAULT_ACCOUNT, 
    region: process.env.CDK_DEFAULT_REGION,
  },
});

If you know the ID and Name of a Hosted Zone, you can import it directly:

const zone = route53.HostedZone.fromHostedZoneAttributes(this, 'MyZone', {
  zoneName: 'example.com',
  hostedZoneId: 'ZOJJZC49E0EPZ',
});

Alternatively, use the HostedZone.fromHostedZoneId to import hosted zones if you know the ID and the retrieval for the zoneName is undesirable.

const zone = route53.HostedZone.fromHostedZoneId(this, 'MyZone', 'ZOJJZC49E0EPZ');

You can import a Public Hosted Zone as well with the similar PubicHostedZone.fromPublicHostedZoneId and PubicHostedZone.fromPublicHostedZoneAttributes methods:

const zoneFromAttributes = route53.PublicHostedZone.fromPublicHostedZoneAttributes(this, 'MyZone', {
  zoneName: 'example.com',
  hostedZoneId: 'ZOJJZC49E0EPZ',
});

// Does not know zoneName
const zoneFromId = route53.PublicHostedZone.fromPublicHostedZoneId(this, 'MyZone', 'ZOJJZC49E0EPZ');

VPC Endpoint Service Private DNS

When you create a VPC endpoint service, AWS generates endpoint-specific DNS hostnames that consumers use to communicate with the service. For example, vpce-1234-abcdev-us-east-1.vpce-svc-123345.us-east-1.vpce.amazonaws.com. By default, your consumers access the service with that DNS name. This can cause problems with HTTPS traffic because the DNS will not match the backend certificate:

curl: (60) SSL: no alternative certificate subject name matches target host name 'vpce-abcdefghijklmnopq-rstuvwx.vpce-svc-abcdefghijklmnopq.us-east-1.vpce.amazonaws.com'

Effectively, the endpoint appears untrustworthy. To mitigate this, clients have to create an alias for this DNS name in Route53.

Private DNS for an endpoint service lets you configure a private DNS name so consumers can access the service using an existing DNS name without creating this Route53 DNS alias This DNS name can also be guaranteed to match up with the backend certificate.

Before consumers can use the private DNS name, you must verify that you have control of the domain/subdomain.

Assuming your account has ownership of the particular domain/subdomain, this construct sets up the private DNS configuration on the endpoint service, creates all the necessary Route53 entries, and verifies domain ownership.

import { Stack } from '@aws-cdk/core';
import { Vpc, VpcEndpointService } from '@aws-cdk/aws-ec2';
import { NetworkLoadBalancer } from '@aws-cdk/aws-elasticloadbalancingv2';
import { PublicHostedZone, VpcEndpointServiceDomainName } from '@aws-cdk/aws-route53';

const stack = new Stack();
const vpc = new Vpc(stack, 'VPC');
const nlb = new NetworkLoadBalancer(stack, 'NLB', {
  vpc,
});
const vpces = new VpcEndpointService(stack, 'VPCES', {
  vpcEndpointServiceLoadBalancers: [nlb],
});
// You must use a public hosted zone so domain ownership can be verified
const zone = new PublicHostedZone(stack, 'PHZ', {
  zoneName: 'aws-cdk.dev',
});
new VpcEndpointServiceDomainName(stack, 'EndpointDomain', {
  endpointService: vpces,
  domainName: 'my-stuff.aws-cdk.dev',
  publicHostedZone: zone,
});
cdk-infracicd_spa_websiteaws-infrastructure@myhelix-cdk/static-site@myhelix-cdk/unizonesix-foot-six-designs@autoguru/cdk@justinm/cdk-constructshiii-construct-util@yippiecloud/cdk-stack-static@yippiecloud/cdk-stack-sveltekit@serverless-toolkit/coredjango-cdk@infinitebrahmanuniverse/nolb-_aws-c@everything-registry/sub-chunk-101amplify-category-apiamplify-provider-awscloudformation@aws/aws-domain-redirector@aws-cdk/cloudformation-include@aws-quickstart/ssp-amazon-eks@aws-cdk/aws-ecs@aws-cdk/aws-ecs-patterns@aws-cdk/aws-route53-patterns@aws-cdk/aws-route53-targets@zigbang/appstream@aligent/aws-cdk-static-hosting-stack@aligent/cdk-shared-vpc@aligent/cdk-static-hosting@shipula/server@shipula/static@shipula/certificate@shipula/domain@serverlessui/construct@serverlessui/serverless-app@smorken/cdk-pipeline@taimos/cdk-construct-hosting@247studios/delivery@aws-cdk/aws-opensearchservice@aws-cdk/aws-elasticsearch@aws-cdk/aws-elasticloadbalancingv2@aws-cdk/aws-servicediscovery@aws-cdk/aws-certificatemanager@cdk-constructs-zone/super-ec2@badatt/infra-libaws-web-pubaws-activate@creativepenguin/cdk-static-site@ciruxx/nodejs-project-utils@cpmech/az-cdkaws-delegation53aws-cdk-google-workspaceaws-cdk-modules@c3l/static-cdn@c3l/web-containeraws-cdk-webflowaws-cdk-pure-hocaws-cdk-squarespaceaws-cdk-stack-buildersaws-cdk-static-https-siteaws-cdk-static-siteaws-scudplatform-constructswolox-core-infra@rnbw/aws-cdk-static-website@rnbw/aws-cdk-tls@rnbw/aws-cdk-s3-website@updraft/aws-lambdas-multi-handler@updraft/aws-static-site@strongishllama/faasd-cdk@swymbase/cdkcdk-datalake-constructscdk-fargate-patternscdk-cloudfront-deploycdk-cdn-construct@cloudmod/simple-web-uicdk-route53-record@devacour/auth-cdk@devacour/cdk-base@devacour/cdk-webservicecdk_utilscdkekscdk-websitecdk-vscode-fargatecdk-serverless-php-mpacdk-shoestring-docker-ecs-appcdk-static-web@damc-dev/cdk-static-sitecicd-spa-websitecrpmserverless-stack-mt-resources@ef-class/cli@fmtk/cf-static-site@flowaccount/aws-cdk-stack@flipboxlabs/shift-ec2-patternseasycdn@jshaftoe/core@justinm/cdk-accounts@justinm/cdk-infra@jbt/cli@jakepartusch/notlify
1.203.0

11 months ago

1.204.0

10 months ago

1.201.0

11 months ago

1.199.0

12 months ago

1.200.0

12 months ago

1.202.0

11 months ago

1.198.1

1 year ago

1.198.0

1 year ago

1.193.0

1 year ago

1.192.0

1 year ago

1.195.0

1 year ago

1.194.0

1 year ago

1.197.0

1 year ago

1.196.0

1 year ago

1.187.0

1 year ago

1.191.0

1 year ago

1.186.0

1 year ago

1.186.1

1 year ago

1.190.0

1 year ago

1.189.0

1 year ago

1.188.0

1 year ago

1.185.0

1 year ago

1.181.0

1 year ago

1.181.1

1 year ago

1.178.0

1 year ago

1.180.0

1 year ago

1.177.0

2 years ago

1.183.0

1 year ago

1.182.0

1 year ago

1.179.0

1 year ago

1.184.0

1 year ago

1.184.1

1 year ago

1.176.0

2 years ago

1.175.0

2 years ago

1.170.0

2 years ago

1.170.1

2 years ago

1.172.0

2 years ago

1.171.0

2 years ago

1.174.0

2 years ago

1.169.0

2 years ago

1.173.0

2 years ago

1.164.0

2 years ago

1.163.0

2 years ago

1.163.2

2 years ago

1.163.1

2 years ago

1.166.1

2 years ago

1.165.0

2 years ago

1.160.0

2 years ago

1.168.0

2 years ago

1.167.0

2 years ago

1.162.0

2 years ago

1.159.0

2 years ago

1.161.0

2 years ago

1.158.0

2 years ago

1.155.0

2 years ago

1.154.0

2 years ago

1.157.0

2 years ago

1.156.0

2 years ago

1.156.1

2 years ago

1.149.0

2 years ago

1.153.0

2 years ago

1.153.1

2 years ago

1.148.0

2 years ago

1.152.0

2 years ago

1.151.0

2 years ago

1.150.0

2 years ago

1.147.0

2 years ago

1.146.0

2 years ago

1.141.0

2 years ago

1.138.2

2 years ago

1.138.1

2 years ago

1.138.0

2 years ago

1.140.0

2 years ago

1.137.0

2 years ago

1.143.0

2 years ago

1.142.0

2 years ago

1.139.0

2 years ago

1.145.0

2 years ago

1.144.0

2 years ago

1.136.0

2 years ago

1.135.0

2 years ago

1.132.0

2 years ago

1.131.0

2 years ago

1.134.0

2 years ago

1.133.0

2 years ago

1.130.0

2 years ago

1.129.0

2 years ago

1.126.0

3 years ago

1.128.0

3 years ago

1.127.0

3 years ago

1.125.0

3 years ago

1.124.0

3 years ago

1.123.0

3 years ago

1.122.0

3 years ago

1.121.0

3 years ago

1.120.0

3 years ago

1.119.0

3 years ago

1.118.0

3 years ago

1.117.0

3 years ago

1.116.0

3 years ago

1.115.0

3 years ago

1.114.0

3 years ago

1.113.0

3 years ago

1.112.0

3 years ago

1.111.0

3 years ago

1.110.1

3 years ago

1.110.0

3 years ago

1.109.0

3 years ago

1.108.0

3 years ago

1.108.1

3 years ago

1.107.0

3 years ago

1.106.1

3 years ago

1.106.0

3 years ago

1.103.0

3 years ago

1.102.0

3 years ago

1.101.0

3 years ago

1.105.0

3 years ago

1.104.0

3 years ago

1.100.0

3 years ago

1.99.0

3 years ago

1.98.0

3 years ago

1.97.0

3 years ago

1.96.0

3 years ago

1.95.2

3 years ago

1.95.1

3 years ago

1.95.0

3 years ago

1.94.1

3 years ago

1.94.0

3 years ago

1.93.0

3 years ago

1.92.0

3 years ago

1.91.0

3 years ago

1.90.1

3 years ago

1.90.0

3 years ago

1.89.0

3 years ago

1.88.0

3 years ago

1.87.1

3 years ago

1.87.0

3 years ago

1.86.0

3 years ago

1.85.0

3 years ago

1.84.0

3 years ago

1.83.0

3 years ago

1.82.0

3 years ago

1.81.0

3 years ago

1.80.0

3 years ago

1.79.0

3 years ago

1.78.0

3 years ago

1.77.0

3 years ago

1.76.0

3 years ago

1.75.0

3 years ago

1.74.0

3 years ago

1.73.0

3 years ago

1.72.0

3 years ago

1.71.0

3 years ago

1.70.0

3 years ago

1.69.0

3 years ago

1.68.0

4 years ago

1.67.0

4 years ago

1.66.0

4 years ago

1.65.0

4 years ago

1.64.1

4 years ago

1.64.0

4 years ago

1.63.0

4 years ago

1.62.0

4 years ago

1.61.1

4 years ago

1.61.0

4 years ago

1.60.0

4 years ago

1.59.0

4 years ago

1.58.0

4 years ago

1.57.0

4 years ago

1.56.0

4 years ago

1.55.0

4 years ago

1.54.0

4 years ago

1.53.0

4 years ago

1.52.0

4 years ago

1.51.0

4 years ago

1.50.0

4 years ago

1.49.1

4 years ago

1.49.0

4 years ago

1.48.0

4 years ago

1.47.1

4 years ago

1.47.0

4 years ago

1.46.0

4 years ago

1.45.0

4 years ago

1.44.0

4 years ago

1.43.0

4 years ago

1.42.1

4 years ago

1.42.0

4 years ago

1.41.0

4 years ago

1.40.0

4 years ago

1.39.0

4 years ago

1.38.0

4 years ago

1.37.0

4 years ago

1.36.1

4 years ago

1.36.0

4 years ago

1.35.0

4 years ago

1.34.1

4 years ago

1.34.0

4 years ago

1.33.1

4 years ago

1.33.0

4 years ago

1.32.2

4 years ago

1.32.1

4 years ago

1.32.0

4 years ago

1.31.0

4 years ago

1.29.0

4 years ago

1.30.0

4 years ago

1.28.0

4 years ago

1.27.0

4 years ago

1.26.0

4 years ago

1.25.0

4 years ago

1.24.0

4 years ago

1.23.0

4 years ago

1.22.0

4 years ago

1.21.1

4 years ago

1.21.0

4 years ago

1.20.0

4 years ago

1.19.0

4 years ago

1.18.0

4 years ago

1.17.1

4 years ago

1.17.0

4 years ago

1.16.3

4 years ago

1.16.2

4 years ago

1.16.1

4 years ago

1.16.0

4 years ago

1.15.0

4 years ago

1.14.0

4 years ago

1.13.1

5 years ago

1.13.0

5 years ago

1.12.0

5 years ago

1.11.0

5 years ago

1.10.1

5 years ago

1.10.0

5 years ago

1.9.0

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.1

5 years ago

1.6.0

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago

0.39.0

5 years ago

0.38.0

5 years ago

0.37.0

5 years ago

0.36.2

5 years ago

0.36.1

5 years ago

0.36.0

5 years ago

0.35.0

5 years ago

0.34.0

5 years ago

0.33.0

5 years ago

0.32.0

5 years ago

0.31.0

5 years ago

0.30.0

5 years ago

0.29.0

5 years ago

0.28.0

5 years ago

0.27.0

5 years ago

0.26.0

5 years ago

0.25.3

5 years ago

0.25.2

5 years ago

0.25.1

5 years ago

0.25.0

5 years ago

0.24.1

5 years ago

0.24.0

5 years ago

0.23.0

5 years ago

0.22.0

5 years ago

0.21.0

5 years ago

0.20.0

5 years ago

0.19.0

5 years ago

0.18.1

5 years ago

0.18.0

5 years ago

0.17.0

5 years ago

0.16.0

5 years ago

0.15.2

5 years ago

0.15.1

5 years ago

0.15.0

5 years ago

0.14.1

5 years ago

0.14.0

5 years ago

0.13.0

6 years ago

0.12.0

6 years ago

0.11.0

6 years ago

0.10.0

6 years ago

0.9.2

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.2

6 years ago

0.8.1

6 years ago

0.8.0

6 years ago