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): improve constructs for basic records #2741

Merged
merged 7 commits into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions packages/@aws-cdk/aws-route53/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ To add a public hosted zone:
import route53 = require('@aws-cdk/aws-route53');

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

Expand All @@ -21,8 +21,8 @@ import route53 = require('@aws-cdk/aws-route53');
const vpc = new ec2.VpcNetwork(this, '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.
zoneName: 'fully.qualified.domain.com',
vpc // At least one VPC has to be added to a Private Hosted Zone.
});
```

Expand All @@ -34,24 +34,33 @@ To add a TXT record to your zone:
```ts
import route53 = require('@aws-cdk/aws-route53');

new route53.TxtRecord(zone, 'TXTRecord', {
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.
recordValue: 'Bar!', // Will be quoted for you, and " will be escaped automatically.
ttl: 90, // Optional - default is 1800
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: 90, // Optional - default is 1800
});
```

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

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

### Adding records to existing hosted zones

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

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

Expand All @@ -60,6 +69,6 @@ to discover and import it:

```ts
const zone = new HostedZoneProvider(this, {
domainName: 'example.com'
domainName: 'example.com'
}).findAndImport(this, 'MyZone');
```
22 changes: 20 additions & 2 deletions packages/@aws-cdk/aws-route53/lib/hosted-zone.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ec2 = require('@aws-cdk/aws-ec2');
import { Construct, Resource, Token } from '@aws-cdk/cdk';
import { HostedZoneAttributes, IHostedZone } from './hosted-zone-ref';
import { ZoneDelegationRecord } from './records';
import { CaaAmazonRecord, ZoneDelegationRecord } from './records';
import { CfnHostedZone } from './route53.generated';
import { validateZoneName } from './util';

Expand Down Expand Up @@ -107,7 +107,19 @@ export class HostedZone extends Resource implements IHostedZone {
}
}

export interface PublicHostedZoneProps extends CommonHostedZoneProps { }
/**
* Construction properties for a PublicHostedZone.
*/
export interface PublicHostedZoneProps extends CommonHostedZoneProps {
/**
* Whether to create a CAA record to restrict certificate authorities allowed
* to issue certificates for this domain to Amazon only.
*
* @default false
*/
readonly caaAmazon?: boolean;
}

export interface IPublicHostedZone extends IHostedZone { }

/**
Expand All @@ -127,6 +139,12 @@ export class PublicHostedZone extends HostedZone implements IPublicHostedZone {

constructor(scope: Construct, id: string, props: PublicHostedZoneProps) {
super(scope, id, props);

if (props.caaAmazon) {
new CaaAmazonRecord(this, 'CaaAmazon', {
zone: this
});
}
}

public addVpc(_vpc: ec2.IVpc) {
Expand Down
Loading