1
+ import { ICertificate } from '@aws-cdk/aws-certificatemanager' ;
1
2
import { IUserPool } from '@aws-cdk/aws-cognito' ;
2
3
import { ManagedPolicy , Role , IRole , ServicePrincipal , Grant , IGrantable } from '@aws-cdk/aws-iam' ;
3
4
import { IFunction } from '@aws-cdk/aws-lambda' ;
4
5
import { ArnFormat , CfnResource , Duration , Expiration , IResolvable , Stack } from '@aws-cdk/core' ;
5
6
import { Construct } from 'constructs' ;
6
- import { CfnApiKey , CfnGraphQLApi , CfnGraphQLSchema } from './appsync.generated' ;
7
+ import { CfnApiKey , CfnGraphQLApi , CfnGraphQLSchema , CfnDomainName , CfnDomainNameApiAssociation } from './appsync.generated' ;
7
8
import { IGraphqlApi , GraphqlApiBase } from './graphqlapi-base' ;
8
9
import { Schema } from './schema' ;
9
10
import { IIntermediateType } from './schema-base' ;
@@ -254,6 +255,21 @@ export interface LogConfig {
254
255
readonly role ?: IRole ;
255
256
}
256
257
258
+ /**
259
+ * Domain name configuration for AppSync
260
+ */
261
+ export interface DomainOptions {
262
+ /**
263
+ * The certificate to use with the domain name.
264
+ */
265
+ readonly certificate : ICertificate ;
266
+
267
+ /**
268
+ * The actual domain name. For example, `api.example.com`.
269
+ */
270
+ readonly domainName : string ;
271
+ }
272
+
257
273
/**
258
274
* Properties for an AppSync GraphQL API
259
275
*/
@@ -292,6 +308,16 @@ export interface GraphqlApiProps {
292
308
* @default - false
293
309
*/
294
310
readonly xrayEnabled ?: boolean ;
311
+
312
+ /**
313
+ * The domain name configuration for the GraphQL API
314
+ *
315
+ * The Route 53 hosted zone and CName DNS record must be configured in addition to this setting to
316
+ * enable custom domain URL
317
+ *
318
+ * @default - no domain name
319
+ */
320
+ readonly domainName ?: DomainOptions ;
295
321
}
296
322
297
323
/**
@@ -391,7 +417,7 @@ export class GraphqlApi extends GraphqlApiBase {
391
417
class Import extends GraphqlApiBase {
392
418
public readonly apiId = attrs . graphqlApiId ;
393
419
public readonly arn = arn ;
394
- constructor ( s : Construct , i : string ) {
420
+ constructor ( s : Construct , i : string ) {
395
421
super ( s , i ) ;
396
422
}
397
423
}
@@ -450,7 +476,7 @@ export class GraphqlApi extends GraphqlApiBase {
450
476
const additionalModes = props . authorizationConfig ?. additionalAuthorizationModes ?? [ ] ;
451
477
const modes = [ defaultMode , ...additionalModes ] ;
452
478
453
- this . modes = modes . map ( ( mode ) => mode . authorizationType ) ;
479
+ this . modes = modes . map ( ( mode ) => mode . authorizationType ) ;
454
480
455
481
this . validateAuthorizationProps ( modes ) ;
456
482
@@ -472,6 +498,19 @@ export class GraphqlApi extends GraphqlApiBase {
472
498
this . schema = props . schema ?? new Schema ( ) ;
473
499
this . schemaResource = this . schema . bind ( this ) ;
474
500
501
+ if ( props . domainName ) {
502
+ new CfnDomainName ( this , 'DomainName' , {
503
+ domainName : props . domainName . domainName ,
504
+ certificateArn : props . domainName . certificate . certificateArn ,
505
+ description : `domain for ${ this . name } at ${ this . graphqlUrl } ` ,
506
+ } ) ;
507
+
508
+ new CfnDomainNameApiAssociation ( this , 'DomainAssociation' , {
509
+ domainName : props . domainName . domainName ,
510
+ apiId : this . apiId ,
511
+ } ) ;
512
+ }
513
+
475
514
if ( modes . some ( ( mode ) => mode . authorizationType === AuthorizationType . API_KEY ) ) {
476
515
const config = modes . find ( ( mode : AuthorizationMode ) => {
477
516
return mode . authorizationType === AuthorizationType . API_KEY && mode . apiKeyConfig ;
0 commit comments