@gradientedge/cdk-utils 4.6.7 → 4.7.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.
@@ -95,6 +95,13 @@ export declare class ApiToEventBridgeTarget extends CommonConstruct {
95
95
  protected createApiDestinationRuleFailure(): void;
96
96
  protected createApiDestinedTopicRole(): void;
97
97
  protected createApiDestinedTopic(): void;
98
+ protected createApiDestinedIntegrationRequestParameters(): void;
99
+ protected createApiDestinedIntegrationRequestTemplates(): void;
100
+ protected createApiDestinedIntegrationResponse(): void;
101
+ protected createApiDestinedIntegrationErrorResponse(): void;
102
+ protected createApiDestinedIntegration(): void;
103
+ protected createApiDestinedMethodResponse(): void;
104
+ protected createApiDestinedMethodErrorResponse(): void;
98
105
  /**
99
106
  * @summary Method to create rest restApi for Api
100
107
  * @protected
@@ -103,13 +110,6 @@ export declare class ApiToEventBridgeTarget extends CommonConstruct {
103
110
  protected createApiDestinedResponseModel(): void;
104
111
  protected createApiDestinedErrorResponseModel(): void;
105
112
  protected createApiDestinedResource(): void;
106
- protected createApiDestinedIntegrationRequestParameters(): void;
107
- protected createApiDestinedIntegrationRequestTemplates(): void;
108
- protected createApiDestinedIntegrationResponse(): void;
109
- protected createApiDestinedIntegrationErrorResponse(): void;
110
- protected createApiDestinedIntegration(): void;
111
- protected createApiDestinedMethodResponse(): void;
112
- protected createApiDestinedMethodErrorResponse(): void;
113
113
  protected createApiDestinedResourceMethod(): void;
114
114
  /**
115
115
  * @summary Method to create custom restApi domain for Api API
@@ -25,7 +25,6 @@ const apig = __importStar(require("aws-cdk-lib/aws-apigateway"));
25
25
  const eventstargets = __importStar(require("aws-cdk-lib/aws-events-targets"));
26
26
  const iam = __importStar(require("aws-cdk-lib/aws-iam"));
27
27
  const destinations = __importStar(require("aws-cdk-lib/aws-lambda-destinations"));
28
- const sns = __importStar(require("aws-cdk-lib/aws-sns"));
29
28
  const common_1 = require("../../common");
30
29
  const api_destination_event_1 = require("./api-destination-event");
31
30
  const api_destined_lambda_1 = require("./api-destined-lambda");
@@ -96,15 +95,15 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
96
95
  /* restApi related resources */
97
96
  this.createApiDestinedTopicRole();
98
97
  this.createApiDestinedTopic();
99
- this.createApiDestinedRestApi();
100
- this.createApiDestinedResponseModel();
101
- this.createApiDestinedErrorResponseModel();
102
- this.createApiDestinedResource();
103
98
  this.createApiDestinedIntegrationRequestParameters();
104
99
  this.createApiDestinedIntegrationRequestTemplates();
105
100
  this.createApiDestinedIntegrationResponse();
106
101
  this.createApiDestinedIntegrationErrorResponse();
107
102
  this.createApiDestinedIntegration();
103
+ this.createApiDestinedRestApi();
104
+ this.createApiDestinedResource();
105
+ this.createApiDestinedResponseModel();
106
+ this.createApiDestinedErrorResponseModel();
108
107
  this.createApiDestinedMethodResponse();
109
108
  this.createApiDestinedMethodErrorResponse();
110
109
  this.createApiDestinedResourceMethod();
@@ -291,96 +290,18 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
291
290
  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)]);
292
291
  }
293
292
  createApiDestinedTopicRole() {
294
- if (this.props.api.useExisting)
295
- return;
296
293
  this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
297
294
  assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
298
295
  });
299
296
  }
300
297
  createApiDestinedTopic() {
301
- if (this.props.api.useExisting) {
302
- 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}`);
298
+ if (!this.props.api.withResource)
303
299
  return;
304
- }
305
300
  this.apiDestinedRestApi.topic = this.snsManager.createLambdaNotificationService(`${this.id}-destined-topic`, this, {
306
301
  topicName: `${this.id}-destined-topic`,
307
302
  }, this.apiDestinedLambda.function);
308
303
  this.apiDestinedRestApi.topic.grantPublish(this.apiDestinedRestApi.topicRole);
309
304
  }
310
- /**
311
- * @summary Method to create rest restApi for Api
312
- * @protected
313
- */
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
- return;
318
- }
319
- this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
320
- ...{
321
- deployOptions: {
322
- dataTraceEnabled: true,
323
- description: `${this.id} - ${this.props.stage} stage`,
324
- loggingLevel: apig.MethodLoggingLevel.INFO,
325
- metricsEnabled: true,
326
- stageName: this.props.stage,
327
- },
328
- endpointConfiguration: {
329
- types: [apig.EndpointType.REGIONAL],
330
- },
331
- defaultCorsPreflightOptions: {
332
- allowOrigins: apig.Cors.ALL_ORIGINS,
333
- allowMethods: ['POST'],
334
- allowHeaders: apig.Cors.DEFAULT_HEADERS,
335
- },
336
- restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
337
- },
338
- ...this.props.api,
339
- });
340
- this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId);
341
- }
342
- createApiDestinedResponseModel() {
343
- if (this.props.api.useExisting)
344
- return;
345
- this.apiDestinedRestApi.responseModel = this.apiDestinedRestApi.api.addModel(`${this.id}-response-model`, {
346
- ...{
347
- contentType: 'application/json',
348
- modelName: 'ResponseModel',
349
- schema: {
350
- schema: apig.JsonSchemaVersion.DRAFT4,
351
- title: 'pollResponse',
352
- type: apig.JsonSchemaType.OBJECT,
353
- properties: { message: { type: apig.JsonSchemaType.STRING } },
354
- },
355
- },
356
- ...this.props.api.responseModel,
357
- });
358
- }
359
- createApiDestinedErrorResponseModel() {
360
- if (this.props.api.useExisting)
361
- return;
362
- this.apiDestinedRestApi.errorResponseModel = this.apiDestinedRestApi.api.addModel(`${this.id}-error-response-model`, {
363
- ...{
364
- contentType: 'application/json',
365
- modelName: 'ErrorResponseModel',
366
- schema: {
367
- schema: apig.JsonSchemaVersion.DRAFT4,
368
- title: 'errorResponse',
369
- type: apig.JsonSchemaType.OBJECT,
370
- properties: {
371
- state: { type: apig.JsonSchemaType.STRING },
372
- message: { type: apig.JsonSchemaType.STRING },
373
- },
374
- },
375
- },
376
- ...this.props.api.errorResponseModel,
377
- });
378
- }
379
- createApiDestinedResource() {
380
- if (!this.props.api.withResource)
381
- return;
382
- this.apiDestinedRestApi.resource = this.apiDestinedRestApi.api.root.addResource(this.props.api.resource ?? this.apiResource);
383
- }
384
305
  createApiDestinedIntegrationRequestParameters() {
385
306
  if (!this.props.api.withResource)
386
307
  return;
@@ -493,6 +414,98 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
493
414
  ...this.props.api.methodErrorResponse,
494
415
  };
495
416
  }
417
+ /**
418
+ * @summary Method to create rest restApi for Api
419
+ * @protected
420
+ */
421
+ createApiDestinedRestApi() {
422
+ if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
423
+ this.apiDestinedRestApi.api = apig.RestApi.fromRestApiId(this, `${this.id}-sns-rest-api`, cdk.Fn.importValue(this.props.api.importedRestApiRef));
424
+ return;
425
+ }
426
+ this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
427
+ ...{
428
+ defaultIntegration: this.apiDestinedRestApi.integration,
429
+ defaultMethodOptions: {
430
+ methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
431
+ },
432
+ deployOptions: {
433
+ dataTraceEnabled: true,
434
+ description: `${this.id} - ${this.props.stage} stage`,
435
+ loggingLevel: apig.MethodLoggingLevel.INFO,
436
+ metricsEnabled: true,
437
+ stageName: this.props.stage,
438
+ },
439
+ endpointConfiguration: {
440
+ types: [apig.EndpointType.REGIONAL],
441
+ },
442
+ defaultCorsPreflightOptions: {
443
+ allowOrigins: apig.Cors.ALL_ORIGINS,
444
+ allowMethods: ['POST'],
445
+ allowHeaders: apig.Cors.DEFAULT_HEADERS,
446
+ },
447
+ restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
448
+ },
449
+ ...this.props.api,
450
+ });
451
+ this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId);
452
+ this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiDestinedRestApi.api.root.resourceId);
453
+ }
454
+ createApiDestinedResponseModel() {
455
+ if (!this.props.api.withResource)
456
+ return;
457
+ this.apiDestinedRestApi.responseModel = new apig.Model(this, `${this.id}-response-model`, {
458
+ restApi: this.apiDestinedRestApi.api,
459
+ ...{
460
+ contentType: 'application/json',
461
+ modelName: 'ResponseModel',
462
+ schema: {
463
+ schema: apig.JsonSchemaVersion.DRAFT4,
464
+ title: 'pollResponse',
465
+ type: apig.JsonSchemaType.OBJECT,
466
+ properties: { message: { type: apig.JsonSchemaType.STRING } },
467
+ },
468
+ },
469
+ ...this.props.api.responseModel,
470
+ });
471
+ }
472
+ createApiDestinedErrorResponseModel() {
473
+ if (!this.props.api.withResource)
474
+ return;
475
+ this.apiDestinedRestApi.errorResponseModel = new apig.Model(this, `${this.id}-error-response-model`, {
476
+ restApi: this.apiDestinedRestApi.api,
477
+ ...{
478
+ contentType: 'application/json',
479
+ modelName: 'ErrorResponseModel',
480
+ schema: {
481
+ schema: apig.JsonSchemaVersion.DRAFT4,
482
+ title: 'errorResponse',
483
+ type: apig.JsonSchemaType.OBJECT,
484
+ properties: {
485
+ state: { type: apig.JsonSchemaType.STRING },
486
+ message: { type: apig.JsonSchemaType.STRING },
487
+ },
488
+ },
489
+ },
490
+ ...this.props.api.errorResponseModel,
491
+ });
492
+ }
493
+ createApiDestinedResource() {
494
+ if (!this.props.api.withResource)
495
+ return;
496
+ let rootResource;
497
+ if (this.props.api.withResource && this.props.api.importedRestApiRootResourceRef) {
498
+ rootResource = apig.Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
499
+ resourceId: cdk.Fn.importValue(this.props.api.importedRestApiRootResourceRef),
500
+ restApi: this.apiDestinedRestApi.api,
501
+ path: '/',
502
+ });
503
+ }
504
+ else {
505
+ rootResource = this.apiDestinedRestApi.api.root;
506
+ }
507
+ this.apiDestinedRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource);
508
+ }
496
509
  createApiDestinedResourceMethod() {
497
510
  if (!this.props.api.withResource)
498
511
  return;
@@ -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)
@@ -200,7 +200,7 @@ export interface ApiDestinedLambdaType {
200
200
  destinationFailure: destinations.EventBridgeDestination;
201
201
  destinationSuccess: destinations.EventBridgeDestination;
202
202
  environment: types.ApiDestinedLambdaEnvironment;
203
- function: lambda.Function;
203
+ function: lambda.IFunction;
204
204
  layers: lambda.LayerVersion[];
205
205
  layerSource?: lambda.AssetCode;
206
206
  policy: iam.PolicyDocument;
@@ -222,6 +222,8 @@ export interface ApiToEventBridgeTargetRestApiProps {
222
222
  errorResponseModel?: apig.ModelOptions;
223
223
  responseModel?: apig.ModelOptions;
224
224
  restApi?: apig.RestApiProps;
225
+ importedRestApiRef?: string;
226
+ importedRestApiRootResourceRef?: string;
225
227
  useExisting: boolean;
226
228
  withResource?: boolean;
227
229
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradientedge/cdk-utils",
3
- "version": "4.6.7",
3
+ "version": "4.7.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",
@@ -5,7 +5,6 @@ import * as iam from 'aws-cdk-lib/aws-iam'
5
5
  import * as lambda from 'aws-cdk-lib/aws-lambda'
6
6
  import * as destinations from 'aws-cdk-lib/aws-lambda-destinations'
7
7
  import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
8
- import * as sns from 'aws-cdk-lib/aws-sns'
9
8
  import { Construct } from 'constructs'
10
9
  import { CommonConstruct } from '../../common'
11
10
  import * as types from '../../types'
@@ -92,15 +91,15 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
92
91
  /* restApi related resources */
93
92
  this.createApiDestinedTopicRole()
94
93
  this.createApiDestinedTopic()
95
- this.createApiDestinedRestApi()
96
- this.createApiDestinedResponseModel()
97
- this.createApiDestinedErrorResponseModel()
98
- this.createApiDestinedResource()
99
94
  this.createApiDestinedIntegrationRequestParameters()
100
95
  this.createApiDestinedIntegrationRequestTemplates()
101
96
  this.createApiDestinedIntegrationResponse()
102
97
  this.createApiDestinedIntegrationErrorResponse()
103
98
  this.createApiDestinedIntegration()
99
+ this.createApiDestinedRestApi()
100
+ this.createApiDestinedResource()
101
+ this.createApiDestinedResponseModel()
102
+ this.createApiDestinedErrorResponseModel()
104
103
  this.createApiDestinedMethodResponse()
105
104
  this.createApiDestinedMethodErrorResponse()
106
105
  this.createApiDestinedResourceMethod()
@@ -334,21 +333,13 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
334
333
  }
335
334
 
336
335
  protected createApiDestinedTopicRole() {
337
- if (this.props.api.useExisting) return
338
336
  this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
339
337
  assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
340
338
  })
341
339
  }
342
340
 
343
341
  protected createApiDestinedTopic() {
344
- if (this.props.api.useExisting) {
345
- this.apiDestinedRestApi.topic = sns.Topic.fromTopicArn(
346
- this,
347
- `${this.id}-destined-topic`,
348
- `arn:aws:sns:${this.props.region}:${cdk.Stack.of(this).account}:${this.id}-destined-topic-${this.props.stage}`
349
- )
350
- return
351
- }
342
+ if (!this.props.api.withResource) return
352
343
  this.apiDestinedRestApi.topic = this.snsManager.createLambdaNotificationService(
353
344
  `${this.id}-destined-topic`,
354
345
  this,
@@ -361,93 +352,6 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
361
352
  this.apiDestinedRestApi.topic.grantPublish(this.apiDestinedRestApi.topicRole)
362
353
  }
363
354
 
364
- /**
365
- * @summary Method to create rest restApi for Api
366
- * @protected
367
- */
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
- return
376
- }
377
- this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
378
- ...{
379
- deployOptions: {
380
- dataTraceEnabled: true,
381
- description: `${this.id} - ${this.props.stage} stage`,
382
- loggingLevel: apig.MethodLoggingLevel.INFO,
383
- metricsEnabled: true,
384
- stageName: this.props.stage,
385
- },
386
- endpointConfiguration: {
387
- types: [apig.EndpointType.REGIONAL],
388
- },
389
- defaultCorsPreflightOptions: {
390
- allowOrigins: apig.Cors.ALL_ORIGINS,
391
- allowMethods: ['POST'],
392
- allowHeaders: apig.Cors.DEFAULT_HEADERS,
393
- },
394
- restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
395
- },
396
- ...this.props.api,
397
- })
398
- this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId)
399
- }
400
-
401
- protected createApiDestinedResponseModel() {
402
- if (this.props.api.useExisting) return
403
- this.apiDestinedRestApi.responseModel = (this.apiDestinedRestApi.api as apig.RestApi).addModel(
404
- `${this.id}-response-model`,
405
- {
406
- ...{
407
- contentType: 'application/json',
408
- modelName: 'ResponseModel',
409
- schema: {
410
- schema: apig.JsonSchemaVersion.DRAFT4,
411
- title: 'pollResponse',
412
- type: apig.JsonSchemaType.OBJECT,
413
- properties: { message: { type: apig.JsonSchemaType.STRING } },
414
- },
415
- },
416
- ...this.props.api.responseModel,
417
- }
418
- )
419
- }
420
-
421
- protected createApiDestinedErrorResponseModel() {
422
- if (this.props.api.useExisting) return
423
- this.apiDestinedRestApi.errorResponseModel = (this.apiDestinedRestApi.api as apig.RestApi).addModel(
424
- `${this.id}-error-response-model`,
425
- {
426
- ...{
427
- contentType: 'application/json',
428
- modelName: 'ErrorResponseModel',
429
- schema: {
430
- schema: apig.JsonSchemaVersion.DRAFT4,
431
- title: 'errorResponse',
432
- type: apig.JsonSchemaType.OBJECT,
433
- properties: {
434
- state: { type: apig.JsonSchemaType.STRING },
435
- message: { type: apig.JsonSchemaType.STRING },
436
- },
437
- },
438
- },
439
- ...this.props.api.errorResponseModel,
440
- }
441
- )
442
- }
443
-
444
- protected createApiDestinedResource() {
445
- if (!this.props.api.withResource) return
446
- this.apiDestinedRestApi.resource = this.apiDestinedRestApi.api.root.addResource(
447
- this.props.api.resource ?? this.apiResource
448
- )
449
- }
450
-
451
355
  protected createApiDestinedIntegrationRequestParameters() {
452
356
  if (!this.props.api.withResource) return
453
357
  this.apiDestinedRestApi.integrationRequestParameters = {
@@ -560,6 +464,104 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
560
464
  }
561
465
  }
562
466
 
467
+ /**
468
+ * @summary Method to create rest restApi for Api
469
+ * @protected
470
+ */
471
+ protected createApiDestinedRestApi() {
472
+ if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
473
+ this.apiDestinedRestApi.api = apig.RestApi.fromRestApiId(
474
+ this,
475
+ `${this.id}-sns-rest-api`,
476
+ cdk.Fn.importValue(this.props.api.importedRestApiRef)
477
+ )
478
+ return
479
+ }
480
+ this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
481
+ ...{
482
+ defaultIntegration: this.apiDestinedRestApi.integration,
483
+ defaultMethodOptions: {
484
+ methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
485
+ },
486
+ deployOptions: {
487
+ dataTraceEnabled: true,
488
+ description: `${this.id} - ${this.props.stage} stage`,
489
+ loggingLevel: apig.MethodLoggingLevel.INFO,
490
+ metricsEnabled: true,
491
+ stageName: this.props.stage,
492
+ },
493
+ endpointConfiguration: {
494
+ types: [apig.EndpointType.REGIONAL],
495
+ },
496
+ defaultCorsPreflightOptions: {
497
+ allowOrigins: apig.Cors.ALL_ORIGINS,
498
+ allowMethods: ['POST'],
499
+ allowHeaders: apig.Cors.DEFAULT_HEADERS,
500
+ },
501
+ restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
502
+ },
503
+ ...this.props.api,
504
+ })
505
+ this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId)
506
+ this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiDestinedRestApi.api.root.resourceId)
507
+ }
508
+
509
+ protected createApiDestinedResponseModel() {
510
+ if (!this.props.api.withResource) return
511
+ this.apiDestinedRestApi.responseModel = new apig.Model(this, `${this.id}-response-model`, {
512
+ restApi: this.apiDestinedRestApi.api,
513
+ ...{
514
+ contentType: 'application/json',
515
+ modelName: 'ResponseModel',
516
+ schema: {
517
+ schema: apig.JsonSchemaVersion.DRAFT4,
518
+ title: 'pollResponse',
519
+ type: apig.JsonSchemaType.OBJECT,
520
+ properties: { message: { type: apig.JsonSchemaType.STRING } },
521
+ },
522
+ },
523
+ ...this.props.api.responseModel,
524
+ })
525
+ }
526
+
527
+ protected createApiDestinedErrorResponseModel() {
528
+ if (!this.props.api.withResource) return
529
+ this.apiDestinedRestApi.errorResponseModel = new apig.Model(this, `${this.id}-error-response-model`, {
530
+ restApi: this.apiDestinedRestApi.api,
531
+ ...{
532
+ contentType: 'application/json',
533
+ modelName: 'ErrorResponseModel',
534
+ schema: {
535
+ schema: apig.JsonSchemaVersion.DRAFT4,
536
+ title: 'errorResponse',
537
+ type: apig.JsonSchemaType.OBJECT,
538
+ properties: {
539
+ state: { type: apig.JsonSchemaType.STRING },
540
+ message: { type: apig.JsonSchemaType.STRING },
541
+ },
542
+ },
543
+ },
544
+ ...this.props.api.errorResponseModel,
545
+ })
546
+ }
547
+
548
+ protected createApiDestinedResource() {
549
+ if (!this.props.api.withResource) return
550
+
551
+ let rootResource
552
+ if (this.props.api.withResource && this.props.api.importedRestApiRootResourceRef) {
553
+ rootResource = apig.Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
554
+ resourceId: cdk.Fn.importValue(this.props.api.importedRestApiRootResourceRef),
555
+ restApi: this.apiDestinedRestApi.api,
556
+ path: '/',
557
+ })
558
+ } else {
559
+ rootResource = this.apiDestinedRestApi.api.root
560
+ }
561
+
562
+ this.apiDestinedRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource)
563
+ }
564
+
563
565
  protected createApiDestinedResourceMethod() {
564
566
  if (!this.props.api.withResource) return
565
567
  this.apiDestinedRestApi.method = this.apiDestinedRestApi.resource.addMethod(
@@ -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
 
@@ -208,7 +208,7 @@ export interface ApiDestinedLambdaType {
208
208
  destinationFailure: destinations.EventBridgeDestination
209
209
  destinationSuccess: destinations.EventBridgeDestination
210
210
  environment: types.ApiDestinedLambdaEnvironment
211
- function: lambda.Function
211
+ function: lambda.IFunction
212
212
  layers: lambda.LayerVersion[]
213
213
  layerSource?: lambda.AssetCode
214
214
  policy: iam.PolicyDocument
@@ -231,6 +231,8 @@ export interface ApiToEventBridgeTargetRestApiProps {
231
231
  errorResponseModel?: apig.ModelOptions
232
232
  responseModel?: apig.ModelOptions
233
233
  restApi?: apig.RestApiProps
234
+ importedRestApiRef?: string
235
+ importedRestApiRootResourceRef?: string
234
236
  useExisting: boolean
235
237
  withResource?: boolean
236
238
  }