@gradientedge/cdk-utils 4.7.0 → 4.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,7 @@
23
23
  "glob@^7.1.3": "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023",
24
24
  "inflight@^1.0.4": "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9",
25
25
  "inherits@2": "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c",
26
- "minimatch@^3.0.4": "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.1.tgz#879ad447200773912898b46cd516a7abbb5e50b0",
26
+ "minimatch@^3.0.4": "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b",
27
27
  "mkdirp@^1.0.4": "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e",
28
28
  "once@^1.3.0": "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1",
29
29
  "path-is-absolute@^1.0.0": "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f",
@@ -80,36 +80,100 @@ export declare class ApiToEventBridgeTarget extends CommonConstruct {
80
80
  * @protected
81
81
  */
82
82
  protected createApiDestinedLambdaFunction(): void;
83
+ /**
84
+ * @summary Method to create or use an existing eventbus for api destined payload deliveries
85
+ * @protected
86
+ */
83
87
  protected createApiDestinedEventBus(): void;
88
+ /**
89
+ * @summary Method to create a log group for successful api destined payload deliveries
90
+ * @protected
91
+ */
84
92
  protected createApiDestinationLogGroupSuccess(): void;
85
93
  /**
86
94
  * Method to create EventBridge rule with lambda target for success
87
95
  * @protected
88
96
  */
89
97
  protected createApiDestinationRuleSuccess(): void;
98
+ /**
99
+ * @summary Method to create a log group for failed api destined payload deliveries
100
+ * @protected
101
+ */
90
102
  protected createApiDestinationLogGroupFailure(): void;
91
103
  /**
92
104
  * Method to create EventBridge rule with lambda target for failure
93
105
  * @protected
94
106
  */
95
107
  protected createApiDestinationRuleFailure(): void;
108
+ /**
109
+ * @summary Method to create a role for sns topic
110
+ * @protected
111
+ */
96
112
  protected createApiDestinedTopicRole(): void;
113
+ /**
114
+ * @summary Method to create API destined SNS topic
115
+ * @protected
116
+ */
97
117
  protected createApiDestinedTopic(): void;
118
+ /**
119
+ * @summary Method to create api integration request parameters
120
+ * @protected
121
+ */
98
122
  protected createApiDestinedIntegrationRequestParameters(): void;
123
+ /**
124
+ * @summary Method to create api integration request templates
125
+ * @protected
126
+ */
99
127
  protected createApiDestinedIntegrationRequestTemplates(): void;
128
+ /**
129
+ * @summary Method to create api integration response
130
+ * @protected
131
+ */
100
132
  protected createApiDestinedIntegrationResponse(): void;
133
+ /**
134
+ * @summary Method to create api integration error response
135
+ * @protected
136
+ */
101
137
  protected createApiDestinedIntegrationErrorResponse(): void;
138
+ /**
139
+ * @summary Method to create api integration
140
+ * @protected
141
+ */
102
142
  protected createApiDestinedIntegration(): void;
143
+ /**
144
+ * @summary Method to create api integration method response
145
+ * @protected
146
+ */
103
147
  protected createApiDestinedMethodResponse(): void;
148
+ /**
149
+ * @summary Method to create api integration method error response
150
+ * @protected
151
+ */
104
152
  protected createApiDestinedMethodErrorResponse(): void;
105
153
  /**
106
154
  * @summary Method to create rest restApi for Api
107
155
  * @protected
108
156
  */
109
157
  protected createApiDestinedRestApi(): void;
158
+ /**
159
+ * @summary Method to create api integration response model
160
+ * @protected
161
+ */
110
162
  protected createApiDestinedResponseModel(): void;
163
+ /**
164
+ * @summary Method to create api integration error response model
165
+ * @protected
166
+ */
111
167
  protected createApiDestinedErrorResponseModel(): void;
168
+ /**
169
+ * @summary Method to create api integration resource
170
+ * @protected
171
+ */
112
172
  protected createApiDestinedResource(): void;
173
+ /**
174
+ * @summary Method to create api integration resource method
175
+ * @protected
176
+ */
113
177
  protected createApiDestinedResourceMethod(): void;
114
178
  /**
115
179
  * @summary Method to create custom restApi domain for Api API
@@ -22,6 +22,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
22
22
  exports.ApiToEventBridgeTarget = void 0;
23
23
  const cdk = __importStar(require("aws-cdk-lib"));
24
24
  const apig = __importStar(require("aws-cdk-lib/aws-apigateway"));
25
+ const events = __importStar(require("aws-cdk-lib/aws-events"));
25
26
  const eventstargets = __importStar(require("aws-cdk-lib/aws-events-targets"));
26
27
  const iam = __importStar(require("aws-cdk-lib/aws-iam"));
27
28
  const destinations = __importStar(require("aws-cdk-lib/aws-lambda-destinations"));
@@ -214,13 +215,23 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
214
215
  },
215
216
  }, this.apiDestinedLambda.role, this.apiDestinedLambda.layers, this.props.lambda.source, this.props.lambda.handler ?? 'lambda.handler', this.apiDestinedLambda.environment);
216
217
  }
218
+ /**
219
+ * @summary Method to create or use an existing eventbus for api destined payload deliveries
220
+ * @protected
221
+ */
217
222
  createApiDestinedEventBus() {
218
- if (this.props.api.useExisting)
223
+ if (this.props.api.useExisting) {
224
+ this.apiEvent.eventBus = events.EventBus.fromEventBusName(this, `${this.id}-destined-event-bus`, `${this.props.event.eventBusName}-${this.props.stage}`);
219
225
  return;
226
+ }
220
227
  this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-destined-event-bus`, this, {
221
228
  eventBusName: `${this.props.event.eventBusName}`,
222
229
  });
223
230
  }
231
+ /**
232
+ * @summary Method to create a log group for successful api destined payload deliveries
233
+ * @protected
234
+ */
224
235
  createApiDestinationLogGroupSuccess() {
225
236
  if (this.props.api.useExisting)
226
237
  return;
@@ -257,6 +268,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
257
268
  };
258
269
  this.apiEvent.ruleSuccess = this.eventManager.createRule(`${this.id}-api-destination-rule-success`, this, this.props.event.ruleSuccess, this.apiEvent.eventBus, [new eventstargets.CloudWatchLogGroup(this.apiEvent.logGroupSuccess)]);
259
270
  }
271
+ /**
272
+ * @summary Method to create a log group for failed api destined payload deliveries
273
+ * @protected
274
+ */
260
275
  createApiDestinationLogGroupFailure() {
261
276
  if (this.props.api.useExisting)
262
277
  return;
@@ -289,11 +304,19 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
289
304
  };
290
305
  this.apiEvent.ruleFailure = this.eventManager.createRule(`${this.id}-api-destination-rule-failure`, this, this.props.event.ruleFailure, this.apiEvent.eventBus, [new eventstargets.CloudWatchLogGroup(this.apiEvent.logGroupFailure)]);
291
306
  }
307
+ /**
308
+ * @summary Method to create a role for sns topic
309
+ * @protected
310
+ */
292
311
  createApiDestinedTopicRole() {
293
312
  this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
294
313
  assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
295
314
  });
296
315
  }
316
+ /**
317
+ * @summary Method to create API destined SNS topic
318
+ * @protected
319
+ */
297
320
  createApiDestinedTopic() {
298
321
  if (!this.props.api.withResource)
299
322
  return;
@@ -302,6 +325,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
302
325
  }, this.apiDestinedLambda.function);
303
326
  this.apiDestinedRestApi.topic.grantPublish(this.apiDestinedRestApi.topicRole);
304
327
  }
328
+ /**
329
+ * @summary Method to create api integration request parameters
330
+ * @protected
331
+ */
305
332
  createApiDestinedIntegrationRequestParameters() {
306
333
  if (!this.props.api.withResource)
307
334
  return;
@@ -309,6 +336,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
309
336
  'integration.request.header.Content-Type': "'application/x-www-form-urlencoded'",
310
337
  };
311
338
  }
339
+ /**
340
+ * @summary Method to create api integration request templates
341
+ * @protected
342
+ */
312
343
  createApiDestinedIntegrationRequestTemplates() {
313
344
  if (!this.props.api.withResource)
314
345
  return;
@@ -321,6 +352,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
321
352
  ].join('&'),
322
353
  };
323
354
  }
355
+ /**
356
+ * @summary Method to create api integration response
357
+ * @protected
358
+ */
324
359
  createApiDestinedIntegrationResponse() {
325
360
  if (!this.props.api.withResource)
326
361
  return;
@@ -334,6 +369,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
334
369
  ...this.props.api.integrationResponse,
335
370
  };
336
371
  }
372
+ /**
373
+ * @summary Method to create api integration error response
374
+ * @protected
375
+ */
337
376
  createApiDestinedIntegrationErrorResponse() {
338
377
  if (!this.props.api.withResource)
339
378
  return;
@@ -356,6 +395,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
356
395
  ...this.props.api.integrationErrorResponse,
357
396
  };
358
397
  }
398
+ /**
399
+ * @summary Method to create api integration
400
+ * @protected
401
+ */
359
402
  createApiDestinedIntegration() {
360
403
  if (!this.props.api.withResource)
361
404
  return;
@@ -378,6 +421,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
378
421
  },
379
422
  });
380
423
  }
424
+ /**
425
+ * @summary Method to create api integration method response
426
+ * @protected
427
+ */
381
428
  createApiDestinedMethodResponse() {
382
429
  if (!this.props.api.withResource)
383
430
  return;
@@ -396,6 +443,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
396
443
  ...this.props.api.methodResponse,
397
444
  };
398
445
  }
446
+ /**
447
+ * @summary Method to create api integration method error response
448
+ * @protected
449
+ */
399
450
  createApiDestinedMethodErrorResponse() {
400
451
  if (!this.props.api.withResource)
401
452
  return;
@@ -451,6 +502,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
451
502
  this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId);
452
503
  this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiDestinedRestApi.api.root.resourceId);
453
504
  }
505
+ /**
506
+ * @summary Method to create api integration response model
507
+ * @protected
508
+ */
454
509
  createApiDestinedResponseModel() {
455
510
  if (!this.props.api.withResource)
456
511
  return;
@@ -469,6 +524,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
469
524
  ...this.props.api.responseModel,
470
525
  });
471
526
  }
527
+ /**
528
+ * @summary Method to create api integration error response model
529
+ * @protected
530
+ */
472
531
  createApiDestinedErrorResponseModel() {
473
532
  if (!this.props.api.withResource)
474
533
  return;
@@ -490,6 +549,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
490
549
  ...this.props.api.errorResponseModel,
491
550
  });
492
551
  }
552
+ /**
553
+ * @summary Method to create api integration resource
554
+ * @protected
555
+ */
493
556
  createApiDestinedResource() {
494
557
  if (!this.props.api.withResource)
495
558
  return;
@@ -506,10 +569,15 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
506
569
  }
507
570
  this.apiDestinedRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource);
508
571
  }
572
+ /**
573
+ * @summary Method to create api integration resource method
574
+ * @protected
575
+ */
509
576
  createApiDestinedResourceMethod() {
510
577
  if (!this.props.api.withResource)
511
578
  return;
512
579
  this.apiDestinedRestApi.method = this.apiDestinedRestApi.resource.addMethod('POST', this.apiDestinedRestApi.integration, {
580
+ authorizer: this.apiDestinedRestApi.authoriser,
513
581
  methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
514
582
  });
515
583
  }
@@ -188,7 +188,14 @@ class GraphQLApiLambda extends common_1.CommonConstruct {
188
188
  stage: this.graphQLApi.deploymentStage,
189
189
  }));
190
190
  });
191
+ return;
191
192
  }
193
+ // add default mapping if apiRootPaths not set
194
+ new apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
195
+ domainName: this.graphQLApiDomain,
196
+ restApi: this.graphQLApi,
197
+ stage: this.graphQLApi.deploymentStage,
198
+ });
192
199
  }
193
200
  /**
194
201
  * @summary Method to create route53 records for GraphQL API
@@ -30,7 +30,6 @@ export declare class GraphQLApiLambdaWithCache extends GraphQLApiLambda {
30
30
  graphQLVpc: ec2.IVpc;
31
31
  graphQLElastiCache: elasticache.CfnCacheCluster;
32
32
  graphQLSecurityGroup: ec2.ISecurityGroup;
33
- securityGroupStackName: string;
34
33
  securityGroupExportName: string;
35
34
  vpcExportName: string;
36
35
  constructor(parent: Construct, id: string, props: GraphQlApiLambdaWithCacheProps);
@@ -54,7 +54,6 @@ class GraphQLApiLambdaWithCache extends __1.GraphQLApiLambda {
54
54
  graphQLVpc;
55
55
  graphQLElastiCache;
56
56
  graphQLSecurityGroup;
57
- securityGroupStackName;
58
57
  securityGroupExportName;
59
58
  vpcExportName;
60
59
  constructor(parent, id, props) {
@@ -73,8 +72,8 @@ class GraphQLApiLambdaWithCache extends __1.GraphQLApiLambda {
73
72
  * @protected
74
73
  */
75
74
  setVpc() {
76
- if (this.props.vpcExportName) {
77
- this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcExportName);
75
+ if (this.props.useExistingVpc) {
76
+ this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcName);
78
77
  }
79
78
  else {
80
79
  this.graphQLVpc = this.vpcManager.createCommonVpc(this, this.props.graphQLVpc, this.props.graphQLVpc.vpcName);
@@ -40,4 +40,24 @@ export declare class ApiManager {
40
40
  * @param certificate the certificate used for custom restApi domain
41
41
  */
42
42
  createApiDomain(id: string, scope: common.CommonConstruct, domainName: string, certificate: acm.ICertificate): apig.DomainName;
43
+ /**
44
+ * @summary Method to create an API gateway resource
45
+ * @param {string} id
46
+ * @param {common.CommonConstruct} scope
47
+ * @param {apig.IResource} parent
48
+ * @param {string} path
49
+ * @param {apig.Integration} integration
50
+ * @param {boolean} addProxy
51
+ * @param {string[]?} allowedOrigins
52
+ * @param {string[]?} allowedMethods
53
+ * @param {string[]?} allowedHeaders
54
+ */
55
+ createApiResource(id: string, scope: common.CommonConstruct, parent: apig.IResource, path: string, integration: apig.Integration, addProxy: boolean, allowedOrigins?: string[], allowedMethods?: string[], allowedHeaders?: string[]): apig.Resource;
56
+ /**
57
+ * @summary Method to create an api deployment
58
+ * @param {string} id
59
+ * @param {common.CommonConstruct} scope
60
+ * @param {apig.IRestApi} restApi
61
+ */
62
+ createApiDeployment(id: string, scope: common.CommonConstruct, restApi: apig.IRestApi): void;
43
63
  }
@@ -84,7 +84,7 @@ class ApiManager {
84
84
  restApiName: `${props.restApiName}-${scope.props.stage}`,
85
85
  handler: lambdaFunction,
86
86
  defaultCorsPreflightOptions: props.defaultCorsPreflightOptions,
87
- proxy: props.proxy || true,
87
+ proxy: props.proxy ?? true,
88
88
  });
89
89
  utils.createCfnOutput(`${id}-restApiId`, scope, api.restApiId);
90
90
  utils.createCfnOutput(`${id}-restApiName`, scope, api.restApiName);
@@ -107,5 +107,55 @@ class ApiManager {
107
107
  utils.createCfnOutput(`${id}-customDomainName`, scope, apiDomain.domainName);
108
108
  return apiDomain;
109
109
  }
110
+ /**
111
+ * @summary Method to create an API gateway resource
112
+ * @param {string} id
113
+ * @param {common.CommonConstruct} scope
114
+ * @param {apig.IResource} parent
115
+ * @param {string} path
116
+ * @param {apig.Integration} integration
117
+ * @param {boolean} addProxy
118
+ * @param {string[]?} allowedOrigins
119
+ * @param {string[]?} allowedMethods
120
+ * @param {string[]?} allowedHeaders
121
+ */
122
+ createApiResource(id, scope, parent, path, integration, addProxy, allowedOrigins, allowedMethods, allowedHeaders) {
123
+ const methods = allowedMethods ?? apig.Cors.ALL_METHODS;
124
+ const resource = parent.addResource(path, {
125
+ defaultCorsPreflightOptions: {
126
+ allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
127
+ allowMethods: [...methods, 'OPTIONS'],
128
+ allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
129
+ allowCredentials: true,
130
+ },
131
+ });
132
+ methods.forEach(method => resource.addMethod(method, integration));
133
+ utils.createCfnOutput(`${id}-${path}ResourceId`, scope, resource.resourceId);
134
+ if (addProxy) {
135
+ const resourceProxy = resource.addResource(`{${path}+}`, {
136
+ defaultCorsPreflightOptions: {
137
+ allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
138
+ allowMethods: [...methods, 'OPTIONS'],
139
+ allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
140
+ allowCredentials: true,
141
+ },
142
+ });
143
+ methods.forEach(method => resourceProxy.addMethod(method, integration));
144
+ utils.createCfnOutput(`${id}-${path}ProxyResourceId`, scope, resourceProxy.resourceId);
145
+ }
146
+ return resource;
147
+ }
148
+ /**
149
+ * @summary Method to create an api deployment
150
+ * @param {string} id
151
+ * @param {common.CommonConstruct} scope
152
+ * @param {apig.IRestApi} restApi
153
+ */
154
+ createApiDeployment(id, scope, restApi) {
155
+ new apig.Deployment(scope, `${id}`, {
156
+ api: restApi,
157
+ retainDeployments: false,
158
+ });
159
+ }
110
160
  }
111
161
  exports.ApiManager = ApiManager;
@@ -152,7 +152,8 @@ export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
152
152
  graphQLVpc: ec2.VpcProps;
153
153
  graphQLElastiCache: ElastiCacheProps;
154
154
  securityGroupExportName: string;
155
- vpcExportName: string;
155
+ useExistingVpc: boolean;
156
+ vpcName?: string;
156
157
  }
157
158
  /**
158
159
  * @category cdk-utils.api-to-eventbridge-target
@@ -171,6 +172,7 @@ export interface ApiDestinationEventType {
171
172
  */
172
173
  export interface ApiDestinedRestApiType {
173
174
  api: apig.IRestApi;
175
+ authoriser?: apig.IAuthorizer;
174
176
  certificate: acm.ICertificate;
175
177
  domain: apig.DomainName;
176
178
  errorResponseModel: apig.Model;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "4.7.0",
3
+ "version": "4.9.1",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -1,5 +1,6 @@
1
1
  import * as cdk from 'aws-cdk-lib'
2
2
  import * as apig from 'aws-cdk-lib/aws-apigateway'
3
+ import * as events from 'aws-cdk-lib/aws-events'
3
4
  import * as eventstargets from 'aws-cdk-lib/aws-events-targets'
4
5
  import * as iam from 'aws-cdk-lib/aws-iam'
5
6
  import * as lambda from 'aws-cdk-lib/aws-lambda'
@@ -245,13 +246,28 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
245
246
  )
246
247
  }
247
248
 
249
+ /**
250
+ * @summary Method to create or use an existing eventbus for api destined payload deliveries
251
+ * @protected
252
+ */
248
253
  protected createApiDestinedEventBus() {
249
- if (this.props.api.useExisting) return
254
+ if (this.props.api.useExisting) {
255
+ this.apiEvent.eventBus = events.EventBus.fromEventBusName(
256
+ this,
257
+ `${this.id}-destined-event-bus`,
258
+ `${this.props.event.eventBusName}-${this.props.stage}`
259
+ )
260
+ return
261
+ }
250
262
  this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-destined-event-bus`, this, {
251
263
  eventBusName: `${this.props.event.eventBusName}`,
252
264
  })
253
265
  }
254
266
 
267
+ /**
268
+ * @summary Method to create a log group for successful api destined payload deliveries
269
+ * @protected
270
+ */
255
271
  protected createApiDestinationLogGroupSuccess() {
256
272
  if (this.props.api.useExisting) return
257
273
  this.apiEvent.logGroupSuccess = this.logManager.createLogGroup(`${this.id}-destination-success-log`, this, {
@@ -294,6 +310,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
294
310
  )
295
311
  }
296
312
 
313
+ /**
314
+ * @summary Method to create a log group for failed api destined payload deliveries
315
+ * @protected
316
+ */
297
317
  protected createApiDestinationLogGroupFailure() {
298
318
  if (this.props.api.useExisting) return
299
319
  this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
@@ -332,12 +352,20 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
332
352
  )
333
353
  }
334
354
 
355
+ /**
356
+ * @summary Method to create a role for sns topic
357
+ * @protected
358
+ */
335
359
  protected createApiDestinedTopicRole() {
336
360
  this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
337
361
  assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
338
362
  })
339
363
  }
340
364
 
365
+ /**
366
+ * @summary Method to create API destined SNS topic
367
+ * @protected
368
+ */
341
369
  protected createApiDestinedTopic() {
342
370
  if (!this.props.api.withResource) return
343
371
  this.apiDestinedRestApi.topic = this.snsManager.createLambdaNotificationService(
@@ -352,6 +380,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
352
380
  this.apiDestinedRestApi.topic.grantPublish(this.apiDestinedRestApi.topicRole)
353
381
  }
354
382
 
383
+ /**
384
+ * @summary Method to create api integration request parameters
385
+ * @protected
386
+ */
355
387
  protected createApiDestinedIntegrationRequestParameters() {
356
388
  if (!this.props.api.withResource) return
357
389
  this.apiDestinedRestApi.integrationRequestParameters = {
@@ -359,6 +391,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
359
391
  }
360
392
  }
361
393
 
394
+ /**
395
+ * @summary Method to create api integration request templates
396
+ * @protected
397
+ */
362
398
  protected createApiDestinedIntegrationRequestTemplates() {
363
399
  if (!this.props.api.withResource) return
364
400
  this.apiDestinedRestApi.integrationRequestTemplates = {
@@ -371,6 +407,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
371
407
  }
372
408
  }
373
409
 
410
+ /**
411
+ * @summary Method to create api integration response
412
+ * @protected
413
+ */
374
414
  protected createApiDestinedIntegrationResponse() {
375
415
  if (!this.props.api.withResource) return
376
416
  this.apiDestinedRestApi.integrationResponse = {
@@ -384,6 +424,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
384
424
  }
385
425
  }
386
426
 
427
+ /**
428
+ * @summary Method to create api integration error response
429
+ * @protected
430
+ */
387
431
  protected createApiDestinedIntegrationErrorResponse() {
388
432
  if (!this.props.api.withResource) return
389
433
  this.apiDestinedRestApi.integrationErrorResponse = {
@@ -406,6 +450,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
406
450
  }
407
451
  }
408
452
 
453
+ /**
454
+ * @summary Method to create api integration
455
+ * @protected
456
+ */
409
457
  protected createApiDestinedIntegration() {
410
458
  if (!this.props.api.withResource) return
411
459
  this.apiDestinedRestApi.integration = new apig.Integration({
@@ -428,6 +476,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
428
476
  })
429
477
  }
430
478
 
479
+ /**
480
+ * @summary Method to create api integration method response
481
+ * @protected
482
+ */
431
483
  protected createApiDestinedMethodResponse() {
432
484
  if (!this.props.api.withResource) return
433
485
  this.apiDestinedRestApi.methodResponse = {
@@ -446,6 +498,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
446
498
  }
447
499
  }
448
500
 
501
+ /**
502
+ * @summary Method to create api integration method error response
503
+ * @protected
504
+ */
449
505
  protected createApiDestinedMethodErrorResponse() {
450
506
  if (!this.props.api.withResource) return
451
507
  this.apiDestinedRestApi.methodErrorResponse = {
@@ -506,6 +562,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
506
562
  this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiDestinedRestApi.api.root.resourceId)
507
563
  }
508
564
 
565
+ /**
566
+ * @summary Method to create api integration response model
567
+ * @protected
568
+ */
509
569
  protected createApiDestinedResponseModel() {
510
570
  if (!this.props.api.withResource) return
511
571
  this.apiDestinedRestApi.responseModel = new apig.Model(this, `${this.id}-response-model`, {
@@ -524,6 +584,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
524
584
  })
525
585
  }
526
586
 
587
+ /**
588
+ * @summary Method to create api integration error response model
589
+ * @protected
590
+ */
527
591
  protected createApiDestinedErrorResponseModel() {
528
592
  if (!this.props.api.withResource) return
529
593
  this.apiDestinedRestApi.errorResponseModel = new apig.Model(this, `${this.id}-error-response-model`, {
@@ -545,6 +609,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
545
609
  })
546
610
  }
547
611
 
612
+ /**
613
+ * @summary Method to create api integration resource
614
+ * @protected
615
+ */
548
616
  protected createApiDestinedResource() {
549
617
  if (!this.props.api.withResource) return
550
618
 
@@ -562,12 +630,17 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
562
630
  this.apiDestinedRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource)
563
631
  }
564
632
 
633
+ /**
634
+ * @summary Method to create api integration resource method
635
+ * @protected
636
+ */
565
637
  protected createApiDestinedResourceMethod() {
566
638
  if (!this.props.api.withResource) return
567
639
  this.apiDestinedRestApi.method = this.apiDestinedRestApi.resource.addMethod(
568
640
  'POST',
569
641
  this.apiDestinedRestApi.integration,
570
642
  {
643
+ authorizer: this.apiDestinedRestApi.authoriser,
571
644
  methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
572
645
  }
573
646
  )
@@ -231,7 +231,15 @@ export class GraphQLApiLambda extends CommonConstruct {
231
231
  })
232
232
  )
233
233
  })
234
+ return
234
235
  }
236
+
237
+ // add default mapping if apiRootPaths not set
238
+ new apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
239
+ domainName: this.graphQLApiDomain,
240
+ restApi: this.graphQLApi,
241
+ stage: this.graphQLApi.deploymentStage,
242
+ })
235
243
  }
236
244
 
237
245
  /**
@@ -37,7 +37,6 @@ export class GraphQLApiLambdaWithCache extends GraphQLApiLambda {
37
37
  graphQLVpc: ec2.IVpc
38
38
  graphQLElastiCache: elasticache.CfnCacheCluster
39
39
  graphQLSecurityGroup: ec2.ISecurityGroup
40
- securityGroupStackName: string
41
40
  securityGroupExportName: string
42
41
  vpcExportName: string
43
42
 
@@ -60,8 +59,8 @@ export class GraphQLApiLambdaWithCache extends GraphQLApiLambda {
60
59
  * @protected
61
60
  */
62
61
  protected setVpc() {
63
- if (this.props.vpcExportName) {
64
- this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcExportName)
62
+ if (this.props.useExistingVpc) {
63
+ this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcName)
65
64
  } else {
66
65
  this.graphQLVpc = this.vpcManager.createCommonVpc(this, this.props.graphQLVpc, this.props.graphQLVpc.vpcName)
67
66
  }
@@ -71,7 +71,7 @@ export class ApiManager {
71
71
  restApiName: `${props.restApiName}-${scope.props.stage}`,
72
72
  handler: lambdaFunction,
73
73
  defaultCorsPreflightOptions: props.defaultCorsPreflightOptions,
74
- proxy: props.proxy || true,
74
+ proxy: props.proxy ?? true,
75
75
  })
76
76
 
77
77
  utils.createCfnOutput(`${id}-restApiId`, scope, api.restApiId)
@@ -99,4 +99,68 @@ export class ApiManager {
99
99
 
100
100
  return apiDomain
101
101
  }
102
+
103
+ /**
104
+ * @summary Method to create an API gateway resource
105
+ * @param {string} id
106
+ * @param {common.CommonConstruct} scope
107
+ * @param {apig.IResource} parent
108
+ * @param {string} path
109
+ * @param {apig.Integration} integration
110
+ * @param {boolean} addProxy
111
+ * @param {string[]?} allowedOrigins
112
+ * @param {string[]?} allowedMethods
113
+ * @param {string[]?} allowedHeaders
114
+ */
115
+ public createApiResource(
116
+ id: string,
117
+ scope: common.CommonConstruct,
118
+ parent: apig.IResource,
119
+ path: string,
120
+ integration: apig.Integration,
121
+ addProxy: boolean,
122
+ allowedOrigins?: string[],
123
+ allowedMethods?: string[],
124
+ allowedHeaders?: string[]
125
+ ) {
126
+ const methods = allowedMethods ?? apig.Cors.ALL_METHODS
127
+ const resource = parent.addResource(path, {
128
+ defaultCorsPreflightOptions: {
129
+ allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
130
+ allowMethods: [...methods, 'OPTIONS'],
131
+ allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
132
+ allowCredentials: true,
133
+ },
134
+ })
135
+ methods.forEach(method => resource.addMethod(method, integration))
136
+ utils.createCfnOutput(`${id}-${path}ResourceId`, scope, resource.resourceId)
137
+
138
+ if (addProxy) {
139
+ const resourceProxy = resource.addResource(`{${path}+}`, {
140
+ defaultCorsPreflightOptions: {
141
+ allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
142
+ allowMethods: [...methods, 'OPTIONS'],
143
+ allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
144
+ allowCredentials: true,
145
+ },
146
+ })
147
+ methods.forEach(method => resourceProxy.addMethod(method, integration))
148
+ utils.createCfnOutput(`${id}-${path}ProxyResourceId`, scope, resourceProxy.resourceId)
149
+ }
150
+
151
+ return resource
152
+ }
153
+
154
+ /**
155
+ * @summary Method to create an api deployment
156
+ * @param {string} id
157
+ * @param {common.CommonConstruct} scope
158
+ * @param {apig.IRestApi} restApi
159
+ */
160
+ public createApiDeployment(id: string, scope: common.CommonConstruct, restApi: apig.IRestApi) {
161
+ new apig.Deployment(scope, `${id}`, {
162
+ api: restApi,
163
+ retainDeployments: false,
164
+ })
165
+ }
102
166
  }
@@ -161,7 +161,8 @@ export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
161
161
  graphQLVpc: ec2.VpcProps
162
162
  graphQLElastiCache: ElastiCacheProps
163
163
  securityGroupExportName: string
164
- vpcExportName: string
164
+ useExistingVpc: boolean
165
+ vpcName?: string
165
166
  }
166
167
 
167
168
  /**
@@ -182,6 +183,7 @@ export interface ApiDestinationEventType {
182
183
  */
183
184
  export interface ApiDestinedRestApiType {
184
185
  api: apig.IRestApi
186
+ authoriser?: apig.IAuthorizer
185
187
  certificate: acm.ICertificate
186
188
  domain: apig.DomainName
187
189
  errorResponseModel: apig.Model