-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmesh-v2-stack.ts
More file actions
601 lines (541 loc) · 21.5 KB
/
Copy pathmesh-v2-stack.ts
File metadata and controls
601 lines (541 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
import * as cdk from 'aws-cdk-lib/core';
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as appsync from 'aws-cdk-lib/aws-appsync';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as wafv2 from 'aws-cdk-lib/aws-wafv2';
import * as route53 from 'aws-cdk-lib/aws-route53';
import * as acm from 'aws-cdk-lib/aws-certificatemanager';
import * as targets from 'aws-cdk-lib/aws-route53-targets';
import * as path from 'path';
import { Construct } from 'constructs';
export class MeshV2Stack extends cdk.Stack {
public readonly table: dynamodb.Table;
public readonly api: appsync.GraphqlApi;
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
// Stage取得(優先順位: --context stage=..., .envのSTAGE, デフォルト: stg)
const stage = this.node.tryGetContext('stage') || process.env.STAGE || 'stg';
const stageSuffix = stage === 'prod' ? '' : `-${stage}`;
// Custom Domain configuration from environment variables
const parentZoneName = process.env.ROUTE53_PARENT_ZONE_NAME || 'api.smalruby.app';
const defaultCustomDomain = stage === 'prod' ? `graphql.${parentZoneName}` : `${stage}.graphql.${parentZoneName}`;
const customDomain = process.env.APPSYNC_CUSTOM_DOMAIN === 'false'
? undefined
: (process.env.APPSYNC_CUSTOM_DOMAIN || defaultCustomDomain);
let domainOptions: appsync.DomainOptions | undefined;
let zone: route53.IHostedZone | undefined;
if (customDomain) {
zone = route53.HostedZone.fromLookup(this, 'HostedZone', {
domainName: parentZoneName,
});
const certificate = new acm.DnsValidatedCertificate(this, 'ApiCertificate', {
domainName: customDomain,
hostedZone: zone,
region: 'us-east-1',
});
domainOptions = {
certificate,
domainName: customDomain,
};
}
// Stack全体にタグ付与
cdk.Tags.of(this).add('Project', 'MeshV2');
cdk.Tags.of(this).add('Stage', stage);
cdk.Tags.of(this).add('Service', 'AppSync');
cdk.Tags.of(this).add('ManagedBy', 'CDK');
// DynamoDB Table for Mesh v2
this.table = new dynamodb.Table(this, 'MeshV2Table', {
tableName: `MeshV2Table${stageSuffix}`,
partitionKey: {
name: 'pk',
type: dynamodb.AttributeType.STRING,
},
sortKey: {
name: 'sk',
type: dynamodb.AttributeType.STRING,
},
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
removalPolicy: cdk.RemovalPolicy.DESTROY, // For development only
pointInTimeRecoverySpecification: {
pointInTimeRecoveryEnabled: false, // Disable for cost optimization in dev
},
timeToLiveAttribute: 'ttl',
});
// DynamoDB Tableにタグ付与
cdk.Tags.of(this.table).add('ResourceType', 'DynamoDB');
// GSI: GroupIdIndex for reverse lookup (groupId -> domain)
this.table.addGlobalSecondaryIndex({
indexName: 'GroupIdIndex',
partitionKey: {
name: 'gsi_pk',
type: dynamodb.AttributeType.STRING,
},
sortKey: {
name: 'gsi_sk',
type: dynamodb.AttributeType.STRING,
},
projectionType: dynamodb.ProjectionType.ALL,
});
// Output table name
new cdk.CfnOutput(this, 'TableName', {
value: this.table.tableName,
description: 'DynamoDB table name for Mesh v2',
});
// Output table ARN
new cdk.CfnOutput(this, 'TableArn', {
value: this.table.tableArn,
description: 'DynamoDB table ARN for Mesh v2',
});
// Environment variables defaults based on stage
const defaultMaxConnTimeSeconds = stage === 'prod' ? '1500' : '300';
// AppSync GraphQL API for Mesh v2
this.api = new appsync.GraphqlApi(this, 'MeshV2Api', {
name: `MeshV2Api${stageSuffix}`,
definition: appsync.Definition.fromFile(path.join(__dirname, '../graphql/schema.graphql')),
domainName: domainOptions,
authorizationConfig: {
defaultAuthorization: {
authorizationType: appsync.AuthorizationType.API_KEY,
apiKeyConfig: {
expires: cdk.Expiration.after(cdk.Duration.days(365)), // 1 year for development
},
},
},
environmentVariables: {
TABLE_NAME: this.table.tableName,
MESH_HOST_HEARTBEAT_INTERVAL_SECONDS: process.env.MESH_HOST_HEARTBEAT_INTERVAL_SECONDS || '60',
MESH_HOST_HEARTBEAT_TTL_SECONDS: process.env.MESH_HOST_HEARTBEAT_TTL_SECONDS || '150',
MESH_MEMBER_HEARTBEAT_INTERVAL_SECONDS: process.env.MESH_MEMBER_HEARTBEAT_INTERVAL_SECONDS || '120',
MESH_MEMBER_HEARTBEAT_TTL_SECONDS: process.env.MESH_MEMBER_HEARTBEAT_TTL_SECONDS || '600',
MESH_MAX_CONNECTION_TIME_SECONDS: process.env.MESH_MAX_CONNECTION_TIME_SECONDS || defaultMaxConnTimeSeconds,
MESH_EVENT_TTL_SECONDS: process.env.MESH_EVENT_TTL_SECONDS || '10',
MESH_POLLING_INTERVAL_SECONDS: process.env.MESH_POLLING_INTERVAL_SECONDS || '2',
},
xrayEnabled: true,
logConfig: {
fieldLogLevel: appsync.FieldLogLevel.ALL,
excludeVerboseContent: false,
},
});
// WAF configuration (Only for production)
if (stage === 'prod') {
const allowedOrigins = [
'https://smalruby.app',
'https://smalruby.jp'
];
const webAcl = new wafv2.CfnWebACL(this, 'MeshV2ApiWebAcl', {
defaultAction: { block: {} },
scope: 'REGIONAL',
visibilityConfig: {
cloudWatchMetricsEnabled: true,
metricName: 'MeshV2ApiWebAcl',
sampledRequestsEnabled: true,
},
rules: [
{
name: 'AllowPreflightOptions',
priority: 0,
action: { allow: {} },
statement: {
andStatement: {
statements: [
{
byteMatchStatement: {
fieldToMatch: {
method: {},
},
positionalConstraint: 'EXACTLY',
searchString: 'OPTIONS',
textTransformations: [
{
priority: 0,
type: 'NONE',
},
],
},
},
{
orStatement: {
statements: allowedOrigins.map(origin => ({
byteMatchStatement: {
fieldToMatch: {
singleHeader: {
Name: 'origin',
},
},
positionalConstraint: 'EXACTLY',
searchString: origin,
textTransformations: [
{
priority: 0,
type: 'LOWERCASE',
},
],
},
})),
},
},
],
},
},
visibilityConfig: {
cloudWatchMetricsEnabled: true,
metricName: 'AllowPreflightOptions',
sampledRequestsEnabled: true,
},
},
{
name: 'AllowSpecificOrigins',
priority: 1,
action: { allow: {} },
statement: {
orStatement: {
statements: allowedOrigins.map(origin => ({
byteMatchStatement: {
fieldToMatch: {
singleHeader: {
Name: 'origin',
},
},
positionalConstraint: 'EXACTLY',
searchString: origin,
textTransformations: [
{
priority: 0,
type: 'LOWERCASE',
},
],
},
})),
},
},
visibilityConfig: {
cloudWatchMetricsEnabled: true,
metricName: 'AllowSpecificOrigins',
sampledRequestsEnabled: true,
},
},
],
});
new wafv2.CfnWebACLAssociation(this, 'MeshV2ApiWebAclAssociation', {
resourceArn: this.api.arn,
webAclArn: webAcl.attrArn,
});
}
// Route53 Alias record for Custom Domain
if (customDomain && zone) {
// Extract subdomain from customDomain (e.g., "graphql.api.smalruby.app" -> "graphql")
const subdomain = customDomain.replace(`.${parentZoneName}`, '');
new route53.ARecord(this, 'ApiAliasRecord', {
zone,
recordName: subdomain,
target: route53.RecordTarget.fromAlias(new targets.AppSyncTarget(this.api)),
});
}
// AppSync APIにタグ付与
cdk.Tags.of(this.api).add('ResourceType', 'GraphQLAPI');
// DynamoDB Data Source
const dynamoDbDataSource = this.api.addDynamoDbDataSource(
'MeshV2TableDataSource',
this.table
);
// None Data Source for event pass-through
const noneDataSource = this.api.addNoneDataSource('NoneDataSource');
// Lambda function for complex operations (Dissolve, Leave, RecordEvents, etc.)
const meshV2Lambda = new lambda.Function(this, 'MeshV2LambdaFunction', {
functionName: `MeshV2-GraphQL${stageSuffix}`,
runtime: lambda.Runtime.RUBY_3_4,
handler: 'handlers/appsync_handler.lambda_handler',
code: lambda.Code.fromAsset(path.join(__dirname, '../lambda')),
environment: {
LANG: 'en_US.UTF-8',
LC_ALL: 'en_US.UTF-8',
DYNAMODB_TABLE_NAME: this.table.tableName,
MESH_SECRET_KEY: process.env.MESH_SECRET_KEY || 'default-secret-key',
MESH_HOST_HEARTBEAT_INTERVAL_SECONDS: process.env.MESH_HOST_HEARTBEAT_INTERVAL_SECONDS || '60',
MESH_HOST_HEARTBEAT_TTL_SECONDS: process.env.MESH_HOST_HEARTBEAT_TTL_SECONDS || '150',
MESH_MEMBER_HEARTBEAT_INTERVAL_SECONDS: process.env.MESH_MEMBER_HEARTBEAT_INTERVAL_SECONDS || '120',
MESH_MEMBER_HEARTBEAT_TTL_SECONDS: process.env.MESH_MEMBER_HEARTBEAT_TTL_SECONDS || '600',
MESH_MAX_CONNECTION_TIME_SECONDS: process.env.MESH_MAX_CONNECTION_TIME_SECONDS || defaultMaxConnTimeSeconds,
MESH_EVENT_TTL_SECONDS: process.env.MESH_EVENT_TTL_SECONDS || '10',
MESH_POLLING_INTERVAL_SECONDS: process.env.MESH_POLLING_INTERVAL_SECONDS || '2',
},
timeout: cdk.Duration.seconds(30),
});
// Grant Lambda permissions to DynamoDB
this.table.grantReadWriteData(meshV2Lambda);
// Lambda Data Source
const meshV2DataSource = this.api.addLambdaDataSource(
'MeshV2LambdaDataSource',
meshV2Lambda
);
// Function: checkGroupExists (共通のグループ存在確認)
const checkGroupExistsFunction = new appsync.AppsyncFunction(this, 'CheckGroupExistsFunction', {
name: 'checkGroupExists',
api: this.api,
dataSource: dynamoDbDataSource,
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/functions/checkGroupExists.js'))
});
// Grant additional permissions for TransactWriteItems
this.table.grantReadWriteData(dynamoDbDataSource.grantPrincipal);
// Resolvers for Phase 2-1: Group Management
// Query: listGroupsByDomain
dynamoDbDataSource.createResolver('ListGroupsByDomainResolver', {
typeName: 'Query',
fieldName: 'listGroupsByDomain',
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/resolvers/Query.listGroupsByDomain.js'))
});
// Query: listGroupStatuses
dynamoDbDataSource.createResolver('ListGroupStatusesResolver', {
typeName: 'Query',
fieldName: 'listGroupStatuses',
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/resolvers/Query.listGroupStatuses.js'))
});
// Query: getNodeStatus (Pipeline Resolver for better reliability)
const findNodeMetadataFunction = new appsync.AppsyncFunction(this, 'FindNodeMetadataFunction', {
name: 'findNodeMetadata',
api: this.api,
dataSource: dynamoDbDataSource,
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/functions/findNodeMetadata.js'))
});
const fetchNodeStatusFunction = new appsync.AppsyncFunction(this, 'FetchNodeStatusFunction', {
name: 'fetchNodeStatus',
api: this.api,
dataSource: dynamoDbDataSource,
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/functions/fetchNodeStatus.js'))
});
new appsync.Resolver(this, 'GetNodeStatusResolver', {
api: this.api,
typeName: 'Query',
fieldName: 'getNodeStatus',
runtime: appsync.FunctionRuntime.JS_1_0_0,
pipelineConfig: [findNodeMetadataFunction, fetchNodeStatusFunction],
code: appsync.Code.fromInline(`
export function request(ctx) {
return {};
}
export function response(ctx) {
return ctx.prev.result;
}
`)
});
// Query: listNodesInGroup
dynamoDbDataSource.createResolver('ListNodesInGroupResolver', {
typeName: 'Query',
fieldName: 'listNodesInGroup',
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/resolvers/Query.listNodesInGroup.js'))
});
// Mutation: createGroup (Pipeline Resolver for idempotency)
// Function 1: Check if group already exists for this hostId + domain
const checkExistingGroupFunction = new appsync.AppsyncFunction(this, 'CheckExistingGroupFunction', {
name: 'checkExistingGroup',
api: this.api,
dataSource: dynamoDbDataSource,
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/functions/checkExistingGroup.js'))
});
// Function 2: Create group if not exists, or return existing group
const createGroupIfNotExistsFunction = new appsync.AppsyncFunction(this, 'CreateGroupIfNotExistsFunction', {
name: 'createGroupIfNotExists',
api: this.api,
dataSource: dynamoDbDataSource,
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/functions/createGroupIfNotExists.js'))
});
// Pipeline Resolver: createGroup
new appsync.Resolver(this, 'CreateGroupPipelineResolver', {
api: this.api,
typeName: 'Mutation',
fieldName: 'createGroup',
runtime: appsync.FunctionRuntime.JS_1_0_0,
pipelineConfig: [checkExistingGroupFunction, createGroupIfNotExistsFunction],
code: appsync.Code.fromInline(`
// Pipeline resolver: pass through
export function request(ctx) {
return {};
}
export function response(ctx) {
return ctx.prev.result;
}
`)
});
// Mutation: joinGroup (Pipeline Resolver for consistency and expiresAt validation)
const joinGroupFunction = new appsync.AppsyncFunction(this, 'JoinGroupFunction', {
name: 'joinGroupFunction',
api: this.api,
dataSource: dynamoDbDataSource,
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/functions/joinGroupFunction.js'))
});
this.api.createResolver('JoinGroupResolver', {
typeName: 'Mutation',
fieldName: 'joinGroup',
runtime: appsync.FunctionRuntime.JS_1_0_0,
pipelineConfig: [checkGroupExistsFunction, joinGroupFunction],
code: appsync.Code.fromInline(`
// Pipeline resolver: pass through
export function request(ctx) {
return {};
}
export function response(ctx) {
return ctx.prev.result;
}
`)
});
// Resolvers for Phase 2-2: High-Frequency Mutations
// Mutation: renewHeartbeat
const renewHeartbeatFunction = new appsync.AppsyncFunction(this, 'RenewHeartbeatFunction', {
name: 'renewHeartbeatFunction',
api: this.api,
dataSource: dynamoDbDataSource,
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/functions/renewHeartbeatFunction.js'))
});
new appsync.Resolver(this, 'RenewHeartbeatResolver', {
api: this.api,
typeName: 'Mutation',
fieldName: 'renewHeartbeat',
runtime: appsync.FunctionRuntime.JS_1_0_0,
pipelineConfig: [checkGroupExistsFunction, renewHeartbeatFunction],
code: appsync.Code.fromInline(`
// Pipeline resolver: pass through
export function request(ctx) {
return {};
}
export function response(ctx) {
return ctx.prev.result;
}
`)
});
// Function: updateNodeTTL
const updateNodeTTLFunction = new appsync.AppsyncFunction(this, 'UpdateNodeTTLFunction', {
name: 'updateNodeTTL',
api: this.api,
dataSource: dynamoDbDataSource,
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/functions/updateNodeTTL.js'))
});
// Pipeline Resolver: sendMemberHeartbeat (グループ存在確認 → Node TTL更新)
new appsync.Resolver(this, 'SendMemberHeartbeatResolver', {
api: this.api,
typeName: 'Mutation',
fieldName: 'sendMemberHeartbeat',
runtime: appsync.FunctionRuntime.JS_1_0_0,
pipelineConfig: [checkGroupExistsFunction, updateNodeTTLFunction],
code: appsync.Code.fromInline(`
// Pipeline resolver: pass through
export function request(ctx) {
return {};
}
export function response(ctx) {
return ctx.prev.result;
}
`)
});
// Function: reportDataByNode (main logic)
const reportDataByNodeFunction = new appsync.AppsyncFunction(this, 'ReportDataByNodeFunction', {
name: 'reportDataByNode',
api: this.api,
dataSource: dynamoDbDataSource,
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/resolvers/Mutation.reportDataByNode.js'))
});
// Pipeline Resolver: reportDataByNode (グループ存在確認 → データ報告)
new appsync.Resolver(this, 'ReportDataByNodePipelineResolver', {
api: this.api,
typeName: 'Mutation',
fieldName: 'reportDataByNode',
runtime: appsync.FunctionRuntime.JS_1_0_0,
pipelineConfig: [checkGroupExistsFunction, reportDataByNodeFunction],
code: appsync.Code.fromInline(`
// Pipeline resolver: pass through
export function request(ctx) {
return {};
}
export function response(ctx) {
return ctx.prev.result;
}
`)
});
// Function: fireEventsByNode (main logic for batch)
const fireEventsByNodeFunction = new appsync.AppsyncFunction(this, 'FireEventsByNodeFunction', {
name: 'fireEventsByNode',
api: this.api,
dataSource: noneDataSource,
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/resolvers/Mutation.fireEventsByNode.js'))
});
// Pipeline Resolver: fireEventsByNode (グループ存在確認 → バッチイベント発火)
new appsync.Resolver(this, 'FireEventsByNodePipelineResolver', {
api: this.api,
typeName: 'Mutation',
fieldName: 'fireEventsByNode',
runtime: appsync.FunctionRuntime.JS_1_0_0,
pipelineConfig: [checkGroupExistsFunction, fireEventsByNodeFunction],
code: appsync.Code.fromInline(`
// Pipeline resolver: pass through
export function request(ctx) {
return {};
}
export function response(ctx) {
return ctx.prev.result;
}
`)
});
// Mutation: recordEventsByNode (Lambda resolver due to BatchPutItem restrictions in JS)
meshV2DataSource.createResolver('RecordEventsByNodeResolver', {
typeName: 'Mutation',
fieldName: 'recordEventsByNode',
});
// Query: getEventsSince
dynamoDbDataSource.createResolver('GetEventsSinceResolver', {
typeName: 'Query',
fieldName: 'getEventsSince',
runtime: appsync.FunctionRuntime.JS_1_0_0,
code: appsync.Code.fromAsset(path.join(__dirname, '../js/resolvers/Query.getEventsSince.js'))
});
// Mutation: dissolveGroup (Lambda resolver)
meshV2DataSource.createResolver('DissolveGroupResolver', {
typeName: 'Mutation',
fieldName: 'dissolveGroup',
});
// Mutation: createDomain (Lambda resolver)
meshV2DataSource.createResolver('CreateDomainResolver', {
typeName: 'Mutation',
fieldName: 'createDomain',
});
// Mutation: leaveGroup (Lambda resolver)
meshV2DataSource.createResolver('LeaveGroupResolver', {
typeName: 'Mutation',
fieldName: 'leaveGroup',
});
// Output API endpoint
new cdk.CfnOutput(this, 'GraphQLApiEndpoint', {
value: this.api.graphqlUrl,
description: 'AppSync GraphQL API endpoint',
});
// Output API key
new cdk.CfnOutput(this, 'GraphQLApiKey', {
value: this.api.apiKey || '',
description: 'AppSync API Key',
});
// Output API ID
new cdk.CfnOutput(this, 'GraphQLApiId', {
value: this.api.apiId,
description: 'AppSync GraphQL API ID',
});
// Output Custom Domain URL
if (customDomain) {
new cdk.CfnOutput(this, 'CustomDomainUrl', {
value: `https://${customDomain}/graphql`,
description: 'AppSync Custom Domain URL',
});
}
}
}