@gradientedge/cdk-utils 4.6.6 → 4.8.0

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",
@@ -1,4 +1,3 @@
1
- import * as apig from 'aws-cdk-lib/aws-apigateway';
2
1
  import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
3
2
  import { Construct } from 'constructs';
4
3
  import { CommonConstruct } from '../../common';
@@ -32,7 +31,6 @@ export declare class ApiToEventBridgeTarget extends CommonConstruct {
32
31
  apiDestinedLambda: types.ApiDestinedLambdaType;
33
32
  apiEvent: types.ApiDestinationEventType;
34
33
  apiDestinedRestApi: types.ApiDestinedRestApiType;
35
- apiDestinedBasePathMappings: apig.BasePathMapping[];
36
34
  apiResource: string;
37
35
  constructor(parent: Construct, id: string, props: types.ApiToEventBridgeTargetProps);
38
36
  protected initResources(): void;
@@ -82,36 +80,100 @@ export declare class ApiToEventBridgeTarget extends CommonConstruct {
82
80
  * @protected
83
81
  */
84
82
  protected createApiDestinedLambdaFunction(): void;
83
+ /**
84
+ * @summary Method to create or use an existing eventbus for api destined payload deliveries
85
+ * @protected
86
+ */
85
87
  protected createApiDestinedEventBus(): void;
88
+ /**
89
+ * @summary Method to create a log group for successful api destined payload deliveries
90
+ * @protected
91
+ */
86
92
  protected createApiDestinationLogGroupSuccess(): void;
87
93
  /**
88
94
  * Method to create EventBridge rule with lambda target for success
89
95
  * @protected
90
96
  */
91
97
  protected createApiDestinationRuleSuccess(): void;
98
+ /**
99
+ * @summary Method to create a log group for failed api destined payload deliveries
100
+ * @protected
101
+ */
92
102
  protected createApiDestinationLogGroupFailure(): void;
93
103
  /**
94
104
  * Method to create EventBridge rule with lambda target for failure
95
105
  * @protected
96
106
  */
97
107
  protected createApiDestinationRuleFailure(): void;
108
+ /**
109
+ * @summary Method to create a role for sns topic
110
+ * @protected
111
+ */
98
112
  protected createApiDestinedTopicRole(): void;
113
+ /**
114
+ * @summary Method to create API destined SNS topic
115
+ * @protected
116
+ */
99
117
  protected createApiDestinedTopic(): void;
100
118
  /**
101
- * @summary Method to create rest restApi for Api
119
+ * @summary Method to create api integration request parameters
102
120
  * @protected
103
121
  */
104
- protected createApiDestinedRestApi(): void;
105
- protected createApiDestinedResponseModel(): void;
106
- protected createApiDestinedErrorResponseModel(): void;
107
- protected createApiDestinedResource(): void;
108
122
  protected createApiDestinedIntegrationRequestParameters(): void;
123
+ /**
124
+ * @summary Method to create api integration request templates
125
+ * @protected
126
+ */
109
127
  protected createApiDestinedIntegrationRequestTemplates(): void;
128
+ /**
129
+ * @summary Method to create api integration response
130
+ * @protected
131
+ */
110
132
  protected createApiDestinedIntegrationResponse(): void;
133
+ /**
134
+ * @summary Method to create api integration error response
135
+ * @protected
136
+ */
111
137
  protected createApiDestinedIntegrationErrorResponse(): void;
138
+ /**
139
+ * @summary Method to create api integration
140
+ * @protected
141
+ */
112
142
  protected createApiDestinedIntegration(): void;
143
+ /**
144
+ * @summary Method to create api integration method response
145
+ * @protected
146
+ */
113
147
  protected createApiDestinedMethodResponse(): void;
148
+ /**
149
+ * @summary Method to create api integration method error response
150
+ * @protected
151
+ */
114
152
  protected createApiDestinedMethodErrorResponse(): void;
153
+ /**
154
+ * @summary Method to create rest restApi for Api
155
+ * @protected
156
+ */
157
+ protected createApiDestinedRestApi(): void;
158
+ /**
159
+ * @summary Method to create api integration response model
160
+ * @protected
161
+ */
162
+ protected createApiDestinedResponseModel(): void;
163
+ /**
164
+ * @summary Method to create api integration error response model
165
+ * @protected
166
+ */
167
+ protected createApiDestinedErrorResponseModel(): void;
168
+ /**
169
+ * @summary Method to create api integration resource
170
+ * @protected
171
+ */
172
+ protected createApiDestinedResource(): void;
173
+ /**
174
+ * @summary Method to create api integration resource method
175
+ * @protected
176
+ */
115
177
  protected createApiDestinedResourceMethod(): void;
116
178
  /**
117
179
  * @summary Method to create custom restApi domain for Api API
@@ -22,10 +22,10 @@ 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"));
28
- const sns = __importStar(require("aws-cdk-lib/aws-sns"));
29
29
  const common_1 = require("../../common");
30
30
  const api_destination_event_1 = require("./api-destination-event");
31
31
  const api_destined_lambda_1 = require("./api-destined-lambda");
@@ -63,7 +63,6 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
63
63
  apiEvent;
64
64
  /* rest restApi related resources */
65
65
  apiDestinedRestApi;
66
- apiDestinedBasePathMappings = [];
67
66
  apiResource;
68
67
  constructor(parent, id, props) {
69
68
  super(parent, id, props);
@@ -97,15 +96,15 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
97
96
  /* restApi related resources */
98
97
  this.createApiDestinedTopicRole();
99
98
  this.createApiDestinedTopic();
100
- this.createApiDestinedRestApi();
101
- this.createApiDestinedResponseModel();
102
- this.createApiDestinedErrorResponseModel();
103
- this.createApiDestinedResource();
104
99
  this.createApiDestinedIntegrationRequestParameters();
105
100
  this.createApiDestinedIntegrationRequestTemplates();
106
101
  this.createApiDestinedIntegrationResponse();
107
102
  this.createApiDestinedIntegrationErrorResponse();
108
103
  this.createApiDestinedIntegration();
104
+ this.createApiDestinedRestApi();
105
+ this.createApiDestinedResource();
106
+ this.createApiDestinedResponseModel();
107
+ this.createApiDestinedErrorResponseModel();
109
108
  this.createApiDestinedMethodResponse();
110
109
  this.createApiDestinedMethodErrorResponse();
111
110
  this.createApiDestinedResourceMethod();
@@ -216,13 +215,23 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
216
215
  },
217
216
  }, this.apiDestinedLambda.role, this.apiDestinedLambda.layers, this.props.lambda.source, this.props.lambda.handler ?? 'lambda.handler', this.apiDestinedLambda.environment);
218
217
  }
218
+ /**
219
+ * @summary Method to create or use an existing eventbus for api destined payload deliveries
220
+ * @protected
221
+ */
219
222
  createApiDestinedEventBus() {
220
- 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}`);
221
225
  return;
226
+ }
222
227
  this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-destined-event-bus`, this, {
223
228
  eventBusName: `${this.props.event.eventBusName}`,
224
229
  });
225
230
  }
231
+ /**
232
+ * @summary Method to create a log group for successful api destined payload deliveries
233
+ * @protected
234
+ */
226
235
  createApiDestinationLogGroupSuccess() {
227
236
  if (this.props.api.useExisting)
228
237
  return;
@@ -259,6 +268,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
259
268
  };
260
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)]);
261
270
  }
271
+ /**
272
+ * @summary Method to create a log group for failed api destined payload deliveries
273
+ * @protected
274
+ */
262
275
  createApiDestinationLogGroupFailure() {
263
276
  if (this.props.api.useExisting)
264
277
  return;
@@ -291,95 +304,31 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
291
304
  };
292
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)]);
293
306
  }
307
+ /**
308
+ * @summary Method to create a role for sns topic
309
+ * @protected
310
+ */
294
311
  createApiDestinedTopicRole() {
295
- if (this.props.api.useExisting)
296
- return;
297
312
  this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
298
313
  assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
299
314
  });
300
315
  }
316
+ /**
317
+ * @summary Method to create API destined SNS topic
318
+ * @protected
319
+ */
301
320
  createApiDestinedTopic() {
302
- if (this.props.api.useExisting) {
303
- this.apiDestinedRestApi.topic = sns.Topic.fromTopicArn(this, `${this.id}-destined-topic`, `arn:aws:sns:${this.props.region}:${cdk.Stack.of(this).account}:${this.id}-destined-topic-${this.props.stage}`);
304
- }
321
+ if (!this.props.api.withResource)
322
+ return;
305
323
  this.apiDestinedRestApi.topic = this.snsManager.createLambdaNotificationService(`${this.id}-destined-topic`, this, {
306
324
  topicName: `${this.id}-destined-topic`,
307
325
  }, this.apiDestinedLambda.function);
308
326
  this.apiDestinedRestApi.topic.grantPublish(this.apiDestinedRestApi.topicRole);
309
327
  }
310
328
  /**
311
- * @summary Method to create rest restApi for Api
329
+ * @summary Method to create api integration request parameters
312
330
  * @protected
313
331
  */
314
- createApiDestinedRestApi() {
315
- if (this.props.api.useExisting) {
316
- this.apiDestinedRestApi.api = apig.RestApi.fromRestApiId(this, `${this.id}-sns-rest-api`, cdk.Fn.importValue('importedRestApiRef'));
317
- }
318
- this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
319
- ...{
320
- deployOptions: {
321
- dataTraceEnabled: true,
322
- description: `${this.id} - ${this.props.stage} stage`,
323
- loggingLevel: apig.MethodLoggingLevel.INFO,
324
- metricsEnabled: true,
325
- stageName: this.props.stage,
326
- },
327
- endpointConfiguration: {
328
- types: [apig.EndpointType.REGIONAL],
329
- },
330
- defaultCorsPreflightOptions: {
331
- allowOrigins: apig.Cors.ALL_ORIGINS,
332
- allowMethods: ['POST'],
333
- allowHeaders: apig.Cors.DEFAULT_HEADERS,
334
- },
335
- restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
336
- },
337
- ...this.props.api,
338
- });
339
- this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId);
340
- }
341
- createApiDestinedResponseModel() {
342
- if (this.props.api.useExisting)
343
- return;
344
- this.apiDestinedRestApi.responseModel = this.apiDestinedRestApi.api.addModel(`${this.id}-response-model`, {
345
- ...{
346
- contentType: 'application/json',
347
- modelName: 'ResponseModel',
348
- schema: {
349
- schema: apig.JsonSchemaVersion.DRAFT4,
350
- title: 'pollResponse',
351
- type: apig.JsonSchemaType.OBJECT,
352
- properties: { message: { type: apig.JsonSchemaType.STRING } },
353
- },
354
- },
355
- ...this.props.api.responseModel,
356
- });
357
- }
358
- createApiDestinedErrorResponseModel() {
359
- if (this.props.api.useExisting)
360
- return;
361
- this.apiDestinedRestApi.errorResponseModel = this.apiDestinedRestApi.api.addModel(`${this.id}-error-response-model`, {
362
- ...{
363
- contentType: 'application/json',
364
- modelName: 'ErrorResponseModel',
365
- schema: {
366
- schema: apig.JsonSchemaVersion.DRAFT4,
367
- title: 'errorResponse',
368
- type: apig.JsonSchemaType.OBJECT,
369
- properties: {
370
- state: { type: apig.JsonSchemaType.STRING },
371
- message: { type: apig.JsonSchemaType.STRING },
372
- },
373
- },
374
- },
375
- ...this.props.api.errorResponseModel,
376
- });
377
- }
378
- createApiDestinedResource() {
379
- if (!this.props.api.withResource)
380
- return;
381
- this.apiDestinedRestApi.resource = this.apiDestinedRestApi.api.root.addResource(this.props.api.resource ?? this.apiResource);
382
- }
383
332
  createApiDestinedIntegrationRequestParameters() {
384
333
  if (!this.props.api.withResource)
385
334
  return;
@@ -387,6 +336,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
387
336
  'integration.request.header.Content-Type': "'application/x-www-form-urlencoded'",
388
337
  };
389
338
  }
339
+ /**
340
+ * @summary Method to create api integration request templates
341
+ * @protected
342
+ */
390
343
  createApiDestinedIntegrationRequestTemplates() {
391
344
  if (!this.props.api.withResource)
392
345
  return;
@@ -399,6 +352,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
399
352
  ].join('&'),
400
353
  };
401
354
  }
355
+ /**
356
+ * @summary Method to create api integration response
357
+ * @protected
358
+ */
402
359
  createApiDestinedIntegrationResponse() {
403
360
  if (!this.props.api.withResource)
404
361
  return;
@@ -412,6 +369,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
412
369
  ...this.props.api.integrationResponse,
413
370
  };
414
371
  }
372
+ /**
373
+ * @summary Method to create api integration error response
374
+ * @protected
375
+ */
415
376
  createApiDestinedIntegrationErrorResponse() {
416
377
  if (!this.props.api.withResource)
417
378
  return;
@@ -434,6 +395,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
434
395
  ...this.props.api.integrationErrorResponse,
435
396
  };
436
397
  }
398
+ /**
399
+ * @summary Method to create api integration
400
+ * @protected
401
+ */
437
402
  createApiDestinedIntegration() {
438
403
  if (!this.props.api.withResource)
439
404
  return;
@@ -456,6 +421,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
456
421
  },
457
422
  });
458
423
  }
424
+ /**
425
+ * @summary Method to create api integration method response
426
+ * @protected
427
+ */
459
428
  createApiDestinedMethodResponse() {
460
429
  if (!this.props.api.withResource)
461
430
  return;
@@ -474,6 +443,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
474
443
  ...this.props.api.methodResponse,
475
444
  };
476
445
  }
446
+ /**
447
+ * @summary Method to create api integration method error response
448
+ * @protected
449
+ */
477
450
  createApiDestinedMethodErrorResponse() {
478
451
  if (!this.props.api.withResource)
479
452
  return;
@@ -492,10 +465,119 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
492
465
  ...this.props.api.methodErrorResponse,
493
466
  };
494
467
  }
468
+ /**
469
+ * @summary Method to create rest restApi for Api
470
+ * @protected
471
+ */
472
+ createApiDestinedRestApi() {
473
+ if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
474
+ this.apiDestinedRestApi.api = apig.RestApi.fromRestApiId(this, `${this.id}-sns-rest-api`, cdk.Fn.importValue(this.props.api.importedRestApiRef));
475
+ return;
476
+ }
477
+ this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
478
+ ...{
479
+ defaultIntegration: this.apiDestinedRestApi.integration,
480
+ defaultMethodOptions: {
481
+ methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
482
+ },
483
+ deployOptions: {
484
+ dataTraceEnabled: true,
485
+ description: `${this.id} - ${this.props.stage} stage`,
486
+ loggingLevel: apig.MethodLoggingLevel.INFO,
487
+ metricsEnabled: true,
488
+ stageName: this.props.stage,
489
+ },
490
+ endpointConfiguration: {
491
+ types: [apig.EndpointType.REGIONAL],
492
+ },
493
+ defaultCorsPreflightOptions: {
494
+ allowOrigins: apig.Cors.ALL_ORIGINS,
495
+ allowMethods: ['POST'],
496
+ allowHeaders: apig.Cors.DEFAULT_HEADERS,
497
+ },
498
+ restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
499
+ },
500
+ ...this.props.api,
501
+ });
502
+ this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId);
503
+ this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiDestinedRestApi.api.root.resourceId);
504
+ }
505
+ /**
506
+ * @summary Method to create api integration response model
507
+ * @protected
508
+ */
509
+ createApiDestinedResponseModel() {
510
+ if (!this.props.api.withResource)
511
+ return;
512
+ this.apiDestinedRestApi.responseModel = new apig.Model(this, `${this.id}-response-model`, {
513
+ restApi: this.apiDestinedRestApi.api,
514
+ ...{
515
+ contentType: 'application/json',
516
+ modelName: 'ResponseModel',
517
+ schema: {
518
+ schema: apig.JsonSchemaVersion.DRAFT4,
519
+ title: 'pollResponse',
520
+ type: apig.JsonSchemaType.OBJECT,
521
+ properties: { message: { type: apig.JsonSchemaType.STRING } },
522
+ },
523
+ },
524
+ ...this.props.api.responseModel,
525
+ });
526
+ }
527
+ /**
528
+ * @summary Method to create api integration error response model
529
+ * @protected
530
+ */
531
+ createApiDestinedErrorResponseModel() {
532
+ if (!this.props.api.withResource)
533
+ return;
534
+ this.apiDestinedRestApi.errorResponseModel = new apig.Model(this, `${this.id}-error-response-model`, {
535
+ restApi: this.apiDestinedRestApi.api,
536
+ ...{
537
+ contentType: 'application/json',
538
+ modelName: 'ErrorResponseModel',
539
+ schema: {
540
+ schema: apig.JsonSchemaVersion.DRAFT4,
541
+ title: 'errorResponse',
542
+ type: apig.JsonSchemaType.OBJECT,
543
+ properties: {
544
+ state: { type: apig.JsonSchemaType.STRING },
545
+ message: { type: apig.JsonSchemaType.STRING },
546
+ },
547
+ },
548
+ },
549
+ ...this.props.api.errorResponseModel,
550
+ });
551
+ }
552
+ /**
553
+ * @summary Method to create api integration resource
554
+ * @protected
555
+ */
556
+ createApiDestinedResource() {
557
+ if (!this.props.api.withResource)
558
+ return;
559
+ let rootResource;
560
+ if (this.props.api.withResource && this.props.api.importedRestApiRootResourceRef) {
561
+ rootResource = apig.Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
562
+ resourceId: cdk.Fn.importValue(this.props.api.importedRestApiRootResourceRef),
563
+ restApi: this.apiDestinedRestApi.api,
564
+ path: '/',
565
+ });
566
+ }
567
+ else {
568
+ rootResource = this.apiDestinedRestApi.api.root;
569
+ }
570
+ this.apiDestinedRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource);
571
+ }
572
+ /**
573
+ * @summary Method to create api integration resource method
574
+ * @protected
575
+ */
495
576
  createApiDestinedResourceMethod() {
496
577
  if (!this.props.api.withResource)
497
578
  return;
498
579
  this.apiDestinedRestApi.method = this.apiDestinedRestApi.resource.addMethod('POST', this.apiDestinedRestApi.integration, {
580
+ authorizer: this.apiDestinedRestApi.authoriser,
499
581
  methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
500
582
  });
501
583
  }
@@ -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,17 @@ 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;
43
56
  }
@@ -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,43 @@ 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
+ }
110
148
  }
111
149
  exports.ApiManager = ApiManager;
@@ -36,7 +36,7 @@ export declare class SnsManager {
36
36
  * @param {string} id scoped id of the resource
37
37
  * @param {common.CommonConstruct} scope scope in which this resource is defined
38
38
  * @param {types.SubscriptionProps} props
39
- * @param {lambda.Function} lambdaFunction
39
+ * @param {lambda.IFunction} lambdaFunction
40
40
  */
41
- createLambdaNotificationService(id: string, scope: common.CommonConstruct, props: types.SubscriptionProps, lambdaFunction: lambda.Function): sns.Topic;
41
+ createLambdaNotificationService(id: string, scope: common.CommonConstruct, props: types.SubscriptionProps, lambdaFunction: lambda.IFunction): sns.Topic;
42
42
  }
@@ -71,7 +71,7 @@ class SnsManager {
71
71
  * @param {string} id scoped id of the resource
72
72
  * @param {common.CommonConstruct} scope scope in which this resource is defined
73
73
  * @param {types.SubscriptionProps} props
74
- * @param {lambda.Function} lambdaFunction
74
+ * @param {lambda.IFunction} lambdaFunction
75
75
  */
76
76
  createLambdaNotificationService(id, scope, props, lambdaFunction) {
77
77
  if (!props)
@@ -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;
@@ -200,7 +202,7 @@ export interface ApiDestinedLambdaType {
200
202
  destinationFailure: destinations.EventBridgeDestination;
201
203
  destinationSuccess: destinations.EventBridgeDestination;
202
204
  environment: types.ApiDestinedLambdaEnvironment;
203
- function: lambda.Function;
205
+ function: lambda.IFunction;
204
206
  layers: lambda.LayerVersion[];
205
207
  layerSource?: lambda.AssetCode;
206
208
  policy: iam.PolicyDocument;
@@ -222,6 +224,8 @@ export interface ApiToEventBridgeTargetRestApiProps {
222
224
  errorResponseModel?: apig.ModelOptions;
223
225
  responseModel?: apig.ModelOptions;
224
226
  restApi?: apig.RestApiProps;
227
+ importedRestApiRef?: string;
228
+ importedRestApiRootResourceRef?: string;
225
229
  useExisting: boolean;
226
230
  withResource?: boolean;
227
231
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "4.6.6",
3
+ "version": "4.8.0",
4
4
  "description": "Utilities for AWS CDK provisioning",
5
5
  "main": "dist/index.js",
6
6
  "engines": {
@@ -50,7 +50,7 @@
50
50
  "app-root-path": "^3.0.0",
51
51
  "aws-cdk-lib": "^2.12.0",
52
52
  "aws-sdk": "^2.1074.0",
53
- "constructs": "^10.0.62",
53
+ "constructs": "^10.0.63",
54
54
  "lodash": "^4.17.21",
55
55
  "moment": "^2.29.1",
56
56
  "nconf": "^0.11.3",
@@ -1,11 +1,11 @@
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'
6
7
  import * as destinations from 'aws-cdk-lib/aws-lambda-destinations'
7
8
  import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
8
- import * as sns from 'aws-cdk-lib/aws-sns'
9
9
  import { Construct } from 'constructs'
10
10
  import { CommonConstruct } from '../../common'
11
11
  import * as types from '../../types'
@@ -50,7 +50,6 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
50
50
 
51
51
  /* rest restApi related resources */
52
52
  apiDestinedRestApi: types.ApiDestinedRestApiType
53
- apiDestinedBasePathMappings: apig.BasePathMapping[] = []
54
53
  apiResource: string
55
54
 
56
55
  constructor(parent: Construct, id: string, props: types.ApiToEventBridgeTargetProps) {
@@ -93,15 +92,15 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
93
92
  /* restApi related resources */
94
93
  this.createApiDestinedTopicRole()
95
94
  this.createApiDestinedTopic()
96
- this.createApiDestinedRestApi()
97
- this.createApiDestinedResponseModel()
98
- this.createApiDestinedErrorResponseModel()
99
- this.createApiDestinedResource()
100
95
  this.createApiDestinedIntegrationRequestParameters()
101
96
  this.createApiDestinedIntegrationRequestTemplates()
102
97
  this.createApiDestinedIntegrationResponse()
103
98
  this.createApiDestinedIntegrationErrorResponse()
104
99
  this.createApiDestinedIntegration()
100
+ this.createApiDestinedRestApi()
101
+ this.createApiDestinedResource()
102
+ this.createApiDestinedResponseModel()
103
+ this.createApiDestinedErrorResponseModel()
105
104
  this.createApiDestinedMethodResponse()
106
105
  this.createApiDestinedMethodErrorResponse()
107
106
  this.createApiDestinedResourceMethod()
@@ -247,13 +246,28 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
247
246
  )
248
247
  }
249
248
 
249
+ /**
250
+ * @summary Method to create or use an existing eventbus for api destined payload deliveries
251
+ * @protected
252
+ */
250
253
  protected createApiDestinedEventBus() {
251
- 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
+ }
252
262
  this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-destined-event-bus`, this, {
253
263
  eventBusName: `${this.props.event.eventBusName}`,
254
264
  })
255
265
  }
256
266
 
267
+ /**
268
+ * @summary Method to create a log group for successful api destined payload deliveries
269
+ * @protected
270
+ */
257
271
  protected createApiDestinationLogGroupSuccess() {
258
272
  if (this.props.api.useExisting) return
259
273
  this.apiEvent.logGroupSuccess = this.logManager.createLogGroup(`${this.id}-destination-success-log`, this, {
@@ -296,6 +310,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
296
310
  )
297
311
  }
298
312
 
313
+ /**
314
+ * @summary Method to create a log group for failed api destined payload deliveries
315
+ * @protected
316
+ */
299
317
  protected createApiDestinationLogGroupFailure() {
300
318
  if (this.props.api.useExisting) return
301
319
  this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
@@ -334,21 +352,22 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
334
352
  )
335
353
  }
336
354
 
355
+ /**
356
+ * @summary Method to create a role for sns topic
357
+ * @protected
358
+ */
337
359
  protected createApiDestinedTopicRole() {
338
- if (this.props.api.useExisting) return
339
360
  this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
340
361
  assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
341
362
  })
342
363
  }
343
364
 
365
+ /**
366
+ * @summary Method to create API destined SNS topic
367
+ * @protected
368
+ */
344
369
  protected createApiDestinedTopic() {
345
- if (this.props.api.useExisting) {
346
- this.apiDestinedRestApi.topic = sns.Topic.fromTopicArn(
347
- this,
348
- `${this.id}-destined-topic`,
349
- `arn:aws:sns:${this.props.region}:${cdk.Stack.of(this).account}:${this.id}-destined-topic-${this.props.stage}`
350
- )
351
- }
370
+ if (!this.props.api.withResource) return
352
371
  this.apiDestinedRestApi.topic = this.snsManager.createLambdaNotificationService(
353
372
  `${this.id}-destined-topic`,
354
373
  this,
@@ -362,91 +381,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
362
381
  }
363
382
 
364
383
  /**
365
- * @summary Method to create rest restApi for Api
384
+ * @summary Method to create api integration request parameters
366
385
  * @protected
367
386
  */
368
- protected createApiDestinedRestApi() {
369
- if (this.props.api.useExisting) {
370
- this.apiDestinedRestApi.api = apig.RestApi.fromRestApiId(
371
- this,
372
- `${this.id}-sns-rest-api`,
373
- cdk.Fn.importValue('importedRestApiRef')
374
- )
375
- }
376
- this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
377
- ...{
378
- deployOptions: {
379
- dataTraceEnabled: true,
380
- description: `${this.id} - ${this.props.stage} stage`,
381
- loggingLevel: apig.MethodLoggingLevel.INFO,
382
- metricsEnabled: true,
383
- stageName: this.props.stage,
384
- },
385
- endpointConfiguration: {
386
- types: [apig.EndpointType.REGIONAL],
387
- },
388
- defaultCorsPreflightOptions: {
389
- allowOrigins: apig.Cors.ALL_ORIGINS,
390
- allowMethods: ['POST'],
391
- allowHeaders: apig.Cors.DEFAULT_HEADERS,
392
- },
393
- restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
394
- },
395
- ...this.props.api,
396
- })
397
- this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId)
398
- }
399
-
400
- protected createApiDestinedResponseModel() {
401
- if (this.props.api.useExisting) return
402
- this.apiDestinedRestApi.responseModel = (this.apiDestinedRestApi.api as apig.RestApi).addModel(
403
- `${this.id}-response-model`,
404
- {
405
- ...{
406
- contentType: 'application/json',
407
- modelName: 'ResponseModel',
408
- schema: {
409
- schema: apig.JsonSchemaVersion.DRAFT4,
410
- title: 'pollResponse',
411
- type: apig.JsonSchemaType.OBJECT,
412
- properties: { message: { type: apig.JsonSchemaType.STRING } },
413
- },
414
- },
415
- ...this.props.api.responseModel,
416
- }
417
- )
418
- }
419
-
420
- protected createApiDestinedErrorResponseModel() {
421
- if (this.props.api.useExisting) return
422
- this.apiDestinedRestApi.errorResponseModel = (this.apiDestinedRestApi.api as apig.RestApi).addModel(
423
- `${this.id}-error-response-model`,
424
- {
425
- ...{
426
- contentType: 'application/json',
427
- modelName: 'ErrorResponseModel',
428
- schema: {
429
- schema: apig.JsonSchemaVersion.DRAFT4,
430
- title: 'errorResponse',
431
- type: apig.JsonSchemaType.OBJECT,
432
- properties: {
433
- state: { type: apig.JsonSchemaType.STRING },
434
- message: { type: apig.JsonSchemaType.STRING },
435
- },
436
- },
437
- },
438
- ...this.props.api.errorResponseModel,
439
- }
440
- )
441
- }
442
-
443
- protected createApiDestinedResource() {
444
- if (!this.props.api.withResource) return
445
- this.apiDestinedRestApi.resource = this.apiDestinedRestApi.api.root.addResource(
446
- this.props.api.resource ?? this.apiResource
447
- )
448
- }
449
-
450
387
  protected createApiDestinedIntegrationRequestParameters() {
451
388
  if (!this.props.api.withResource) return
452
389
  this.apiDestinedRestApi.integrationRequestParameters = {
@@ -454,6 +391,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
454
391
  }
455
392
  }
456
393
 
394
+ /**
395
+ * @summary Method to create api integration request templates
396
+ * @protected
397
+ */
457
398
  protected createApiDestinedIntegrationRequestTemplates() {
458
399
  if (!this.props.api.withResource) return
459
400
  this.apiDestinedRestApi.integrationRequestTemplates = {
@@ -466,6 +407,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
466
407
  }
467
408
  }
468
409
 
410
+ /**
411
+ * @summary Method to create api integration response
412
+ * @protected
413
+ */
469
414
  protected createApiDestinedIntegrationResponse() {
470
415
  if (!this.props.api.withResource) return
471
416
  this.apiDestinedRestApi.integrationResponse = {
@@ -479,6 +424,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
479
424
  }
480
425
  }
481
426
 
427
+ /**
428
+ * @summary Method to create api integration error response
429
+ * @protected
430
+ */
482
431
  protected createApiDestinedIntegrationErrorResponse() {
483
432
  if (!this.props.api.withResource) return
484
433
  this.apiDestinedRestApi.integrationErrorResponse = {
@@ -501,6 +450,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
501
450
  }
502
451
  }
503
452
 
453
+ /**
454
+ * @summary Method to create api integration
455
+ * @protected
456
+ */
504
457
  protected createApiDestinedIntegration() {
505
458
  if (!this.props.api.withResource) return
506
459
  this.apiDestinedRestApi.integration = new apig.Integration({
@@ -523,6 +476,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
523
476
  })
524
477
  }
525
478
 
479
+ /**
480
+ * @summary Method to create api integration method response
481
+ * @protected
482
+ */
526
483
  protected createApiDestinedMethodResponse() {
527
484
  if (!this.props.api.withResource) return
528
485
  this.apiDestinedRestApi.methodResponse = {
@@ -541,6 +498,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
541
498
  }
542
499
  }
543
500
 
501
+ /**
502
+ * @summary Method to create api integration method error response
503
+ * @protected
504
+ */
544
505
  protected createApiDestinedMethodErrorResponse() {
545
506
  if (!this.props.api.withResource) return
546
507
  this.apiDestinedRestApi.methodErrorResponse = {
@@ -559,12 +520,127 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
559
520
  }
560
521
  }
561
522
 
523
+ /**
524
+ * @summary Method to create rest restApi for Api
525
+ * @protected
526
+ */
527
+ protected createApiDestinedRestApi() {
528
+ if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
529
+ this.apiDestinedRestApi.api = apig.RestApi.fromRestApiId(
530
+ this,
531
+ `${this.id}-sns-rest-api`,
532
+ cdk.Fn.importValue(this.props.api.importedRestApiRef)
533
+ )
534
+ return
535
+ }
536
+ this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
537
+ ...{
538
+ defaultIntegration: this.apiDestinedRestApi.integration,
539
+ defaultMethodOptions: {
540
+ methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
541
+ },
542
+ deployOptions: {
543
+ dataTraceEnabled: true,
544
+ description: `${this.id} - ${this.props.stage} stage`,
545
+ loggingLevel: apig.MethodLoggingLevel.INFO,
546
+ metricsEnabled: true,
547
+ stageName: this.props.stage,
548
+ },
549
+ endpointConfiguration: {
550
+ types: [apig.EndpointType.REGIONAL],
551
+ },
552
+ defaultCorsPreflightOptions: {
553
+ allowOrigins: apig.Cors.ALL_ORIGINS,
554
+ allowMethods: ['POST'],
555
+ allowHeaders: apig.Cors.DEFAULT_HEADERS,
556
+ },
557
+ restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
558
+ },
559
+ ...this.props.api,
560
+ })
561
+ this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId)
562
+ this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiDestinedRestApi.api.root.resourceId)
563
+ }
564
+
565
+ /**
566
+ * @summary Method to create api integration response model
567
+ * @protected
568
+ */
569
+ protected createApiDestinedResponseModel() {
570
+ if (!this.props.api.withResource) return
571
+ this.apiDestinedRestApi.responseModel = new apig.Model(this, `${this.id}-response-model`, {
572
+ restApi: this.apiDestinedRestApi.api,
573
+ ...{
574
+ contentType: 'application/json',
575
+ modelName: 'ResponseModel',
576
+ schema: {
577
+ schema: apig.JsonSchemaVersion.DRAFT4,
578
+ title: 'pollResponse',
579
+ type: apig.JsonSchemaType.OBJECT,
580
+ properties: { message: { type: apig.JsonSchemaType.STRING } },
581
+ },
582
+ },
583
+ ...this.props.api.responseModel,
584
+ })
585
+ }
586
+
587
+ /**
588
+ * @summary Method to create api integration error response model
589
+ * @protected
590
+ */
591
+ protected createApiDestinedErrorResponseModel() {
592
+ if (!this.props.api.withResource) return
593
+ this.apiDestinedRestApi.errorResponseModel = new apig.Model(this, `${this.id}-error-response-model`, {
594
+ restApi: this.apiDestinedRestApi.api,
595
+ ...{
596
+ contentType: 'application/json',
597
+ modelName: 'ErrorResponseModel',
598
+ schema: {
599
+ schema: apig.JsonSchemaVersion.DRAFT4,
600
+ title: 'errorResponse',
601
+ type: apig.JsonSchemaType.OBJECT,
602
+ properties: {
603
+ state: { type: apig.JsonSchemaType.STRING },
604
+ message: { type: apig.JsonSchemaType.STRING },
605
+ },
606
+ },
607
+ },
608
+ ...this.props.api.errorResponseModel,
609
+ })
610
+ }
611
+
612
+ /**
613
+ * @summary Method to create api integration resource
614
+ * @protected
615
+ */
616
+ protected createApiDestinedResource() {
617
+ if (!this.props.api.withResource) return
618
+
619
+ let rootResource
620
+ if (this.props.api.withResource && this.props.api.importedRestApiRootResourceRef) {
621
+ rootResource = apig.Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
622
+ resourceId: cdk.Fn.importValue(this.props.api.importedRestApiRootResourceRef),
623
+ restApi: this.apiDestinedRestApi.api,
624
+ path: '/',
625
+ })
626
+ } else {
627
+ rootResource = this.apiDestinedRestApi.api.root
628
+ }
629
+
630
+ this.apiDestinedRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource)
631
+ }
632
+
633
+ /**
634
+ * @summary Method to create api integration resource method
635
+ * @protected
636
+ */
562
637
  protected createApiDestinedResourceMethod() {
563
638
  if (!this.props.api.withResource) return
564
639
  this.apiDestinedRestApi.method = this.apiDestinedRestApi.resource.addMethod(
565
640
  'POST',
566
641
  this.apiDestinedRestApi.integration,
567
642
  {
643
+ authorizer: this.apiDestinedRestApi.authoriser,
568
644
  methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
569
645
  }
570
646
  )
@@ -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,55 @@ 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
+ }
102
153
  }
@@ -62,13 +62,13 @@ export class SnsManager {
62
62
  * @param {string} id scoped id of the resource
63
63
  * @param {common.CommonConstruct} scope scope in which this resource is defined
64
64
  * @param {types.SubscriptionProps} props
65
- * @param {lambda.Function} lambdaFunction
65
+ * @param {lambda.IFunction} lambdaFunction
66
66
  */
67
67
  public createLambdaNotificationService(
68
68
  id: string,
69
69
  scope: common.CommonConstruct,
70
70
  props: types.SubscriptionProps,
71
- lambdaFunction: lambda.Function
71
+ lambdaFunction: lambda.IFunction
72
72
  ) {
73
73
  if (!props) throw `Subscription props undefined`
74
74
 
@@ -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
@@ -208,7 +210,7 @@ export interface ApiDestinedLambdaType {
208
210
  destinationFailure: destinations.EventBridgeDestination
209
211
  destinationSuccess: destinations.EventBridgeDestination
210
212
  environment: types.ApiDestinedLambdaEnvironment
211
- function: lambda.Function
213
+ function: lambda.IFunction
212
214
  layers: lambda.LayerVersion[]
213
215
  layerSource?: lambda.AssetCode
214
216
  policy: iam.PolicyDocument
@@ -231,6 +233,8 @@ export interface ApiToEventBridgeTargetRestApiProps {
231
233
  errorResponseModel?: apig.ModelOptions
232
234
  responseModel?: apig.ModelOptions
233
235
  restApi?: apig.RestApiProps
236
+ importedRestApiRef?: string
237
+ importedRestApiRootResourceRef?: string
234
238
  useExisting: boolean
235
239
  withResource?: boolean
236
240
  }