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-targets): aws-apigatewayv2 target #10191

Merged
merged 2 commits into from
Nov 6, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
15 changes: 11 additions & 4 deletions packages/@aws-cdk/aws-route53-targets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ This library contains Route53 Alias Record targets for:
// or - route53.RecordTarget.fromAlias(new alias.ApiGatewayDomain(domainName)),
});
```
* API Gateway V2 custom domains
```ts
new route53.ARecord(this, 'AliasRecord', {
zone,
target: route53.RecordTarget.fromAlias(new alias.ApiGatewayv2Domain(domainName)),
shivlaks marked this conversation as resolved.
Show resolved Hide resolved
});
```
* CloudFront distributions
```ts
new route53.ARecord(this, 'AliasRecord', {
Expand Down Expand Up @@ -55,17 +62,17 @@ For example, if the Amazon-provided DNS for the load balancer is `ALB-xxxxxxx.us
```
* S3 Bucket Website:

**Important:** The Bucket name must strictly match the full DNS name.
See [the Developer Guide](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/getting-started.html) for more info.
**Important:** The Bucket name must strictly match the full DNS name.
See [the Developer Guide](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/getting-started.html) for more info.
```ts
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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as route53 from '@aws-cdk/aws-route53';
* Defines an API Gateway domain name as the alias target.
*
* Use the `ApiGateway` class if you wish to map the alias to an REST API with a
* domain name defined throug the `RestApiProps.domainName` prop.
* domain name defined through the `RestApiProps.domainName` prop.
shivlaks marked this conversation as resolved.
Show resolved Hide resolved
*/
export class ApiGatewayDomain implements route53.IAliasRecordTarget {
constructor(private readonly domainName: apig.IDomainName) { }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as apigv2 from '@aws-cdk/aws-apigatewayv2';
import * as route53 from '@aws-cdk/aws-route53';

/**
* Defines an API Gateway V2 domain name as the alias target.
*/
export class ApiGatewayv2Domain implements route53.IAliasRecordTarget {
shivlaks marked this conversation as resolved.
Show resolved Hide resolved
constructor(private readonly domainName: apigv2.IDomainName) { }

public bind(_record: route53.IRecordSet): route53.AliasRecordTargetConfig {
return {
dnsName: this.domainName.regionalDomainName,
hostedZoneId: this.domainName.regionalHostedZoneId,
};
}
}
1 change: 1 addition & 0 deletions packages/@aws-cdk/aws-route53-targets/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './api-gateway-domain-name';
export * from './api-gatewayv2-domain-name';
export * from './bucket-website-target';
export * from './classic-load-balancer-target';
export * from './cloudfront-target';
Expand Down
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-route53-targets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
},
"dependencies": {
"@aws-cdk/aws-apigateway": "0.0.0",
"@aws-cdk/aws-apigatewayv2": "0.0.0",
"@aws-cdk/aws-cloudfront": "0.0.0",
"@aws-cdk/aws-cognito": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
Expand All @@ -89,6 +90,7 @@
"homepage": "https://github.com/aws/aws-cdk",
"peerDependencies": {
"@aws-cdk/aws-apigateway": "0.0.0",
"@aws-cdk/aws-apigatewayv2": "0.0.0",
"@aws-cdk/aws-cloudfront": "0.0.0",
"@aws-cdk/aws-cognito": "0.0.0",
"@aws-cdk/aws-ec2": "0.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { expect as expectStack, haveResource } from '@aws-cdk/assert';
import * as apigwv2 from '@aws-cdk/aws-apigatewayv2';
import * as acm from '@aws-cdk/aws-certificatemanager';
import * as route53 from '@aws-cdk/aws-route53';
import { Stack } from '@aws-cdk/core';
import * as targets from '../lib';

test('targets.ApiGatewayv2Domain can be used to directly reference a domain', () => {
// GIVEN
const stack = new Stack();
const domainName = 'example.com';
const cert = new acm.Certificate(stack, 'cert', { domainName });
const dn = new apigwv2.DomainName(stack, 'DN', {
domainName,
certificate: cert,
});
const zone = new route53.HostedZone(stack, 'zone', {
zoneName: 'example.com',
});

// WHEN
new route53.ARecord(stack, 'A', {
zone,
target: route53.RecordTarget.fromAlias(new targets.ApiGatewayv2Domain(dn)),
});

// THEN
expectStack(stack).to(haveResource('AWS::Route53::RecordSet', {
Name: 'example.com.',
Type: 'A',
AliasTarget: {
DNSName: {
'Fn::GetAtt': [
'DNFDC76583',
'RegionalDomainName',
],
},
HostedZoneId: {
'Fn::GetAtt': [
'DNFDC76583',
'RegionalHostedZoneId',
],
},
},
HostedZoneId: {
Ref: 'zoneEB40FF1E',
},
}));
});