-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route53-targets): Add AppSync target
- Loading branch information
1 parent
4e715b8
commit a3d6535
Showing
4 changed files
with
91 additions
and
0 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
23 changes: 23 additions & 0 deletions
23
packages/aws-cdk-lib/aws-route53-targets/lib/appsync-target.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,23 @@ | ||
import { CloudFrontTarget } from './cloudfront-target'; | ||
import { GraphqlApi } from '../../aws-appsync'; | ||
import { | ||
AliasRecordTargetConfig, | ||
IAliasRecordTarget, | ||
IHostedZone, | ||
IRecordSet, | ||
} from '../../aws-route53'; | ||
|
||
/** | ||
* Defines an AppSync Graphql API as the alias target. Requires that the domain | ||
* name will be defined through `GraphqlApiProps.domainName`. | ||
*/ | ||
export class AppSync implements IAliasRecordTarget { | ||
constructor(private readonly graphqlApi: GraphqlApi) {} | ||
|
||
public bind(_record: IRecordSet, _zone?: IHostedZone): AliasRecordTargetConfig { | ||
return { | ||
dnsName: this.graphqlApi.appSyncDomainName, | ||
hostedZoneId: CloudFrontTarget.getHostedZoneId(this.graphqlApi), | ||
}; | ||
} | ||
} |
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
54 changes: 54 additions & 0 deletions
54
packages/aws-cdk-lib/aws-route53-targets/test/appsync-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,54 @@ | ||
import { join } from 'path'; | ||
import { Template } from '../../assertions'; | ||
import * as appsync from '../../aws-appsync'; | ||
import * as acm from '../../aws-certificatemanager'; | ||
import * as route53 from '../../aws-route53'; | ||
import { Stack } from '../../core'; | ||
import * as targets from '../lib'; | ||
|
||
test('targets.AppSync can be used to the default domain of an AppSync GraphqlApi', () => { | ||
// GIVEN | ||
const stack = new Stack(); | ||
const cert = new acm.Certificate(stack, 'cert', { domainName: 'example.com' }); | ||
const api = new appsync.GraphqlApi(stack, 'api', { | ||
definition: appsync.Definition.fromFile(join(__dirname, '..', '..', 'aws-appsync', 'test', 'appsync.test.graphql')), | ||
domainName: { | ||
domainName: 'example.com', | ||
certificate: cert, | ||
}, | ||
name: 'api', | ||
}); | ||
const zone = new route53.HostedZone(stack, 'zone', { | ||
zoneName: 'example.com', | ||
}); | ||
|
||
// WHEN | ||
new route53.ARecord(stack, 'A', { | ||
zone, | ||
target: route53.RecordTarget.fromAlias(new targets.AppSync(api)), | ||
}); | ||
|
||
// THEN | ||
Template.fromStack(stack).hasResourceProperties('AWS::Route53::RecordSet', { | ||
Name: 'example.com.', | ||
Type: 'A', | ||
AliasTarget: { | ||
DNSName: { | ||
'Fn::GetAtt': [ | ||
'apiDomainNameBBFE36A4', | ||
'AppSyncDomainName', | ||
], | ||
}, | ||
HostedZoneId: { | ||
'Fn::FindInMap': [ | ||
'AWSCloudFrontPartitionHostedZoneIdMap', | ||
{ Ref: 'AWS::Partition' }, | ||
'zoneId', | ||
], | ||
}, | ||
}, | ||
HostedZoneId: { | ||
Ref: 'zoneEB40FF1E', | ||
}, | ||
}); | ||
}); |