-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aws-route53-targets): aws-apigatewayv2 target
- Loading branch information
1 parent
4de68c0
commit 28c5232
Showing
6 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/@aws-cdk/aws-route53-targets/lib/api-gatewayv2-domain-name.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { | ||
constructor(private readonly domainName: apigv2.IDomainName) { } | ||
|
||
public bind(_record: route53.IRecordSet): route53.AliasRecordTargetConfig { | ||
return { | ||
dnsName: this.domainName.regionalDomainName, | ||
hostedZoneId: this.domainName.regionalHostedZoneId, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/@aws-cdk/aws-route53-targets/test/apigatewayv2-target.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
})); | ||
}); |