@gradientedge/cdk-utils 5.14.0 → 6.1.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.
Files changed (38) hide show
  1. package/dist/src/lib/construct/api-to-eventbridge-target/index.d.ts +0 -3
  2. package/dist/src/lib/construct/api-to-eventbridge-target/index.js +0 -3
  3. package/dist/src/lib/construct/api-to-eventbridge-target/main.d.ts +23 -68
  4. package/dist/src/lib/construct/api-to-eventbridge-target/main.js +124 -243
  5. package/dist/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.d.ts +1 -1
  6. package/dist/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.js +1 -1
  7. package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/index.d.ts +2 -0
  8. package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/index.js +18 -0
  9. package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.d.ts +193 -0
  10. package/dist/src/lib/construct/api-to-eventbridge-target-with-sns/main.js +631 -0
  11. package/dist/src/lib/construct/graphql-api-lambda/main.js +1 -1
  12. package/dist/src/lib/construct/index.d.ts +1 -0
  13. package/dist/src/lib/construct/index.js +1 -0
  14. package/dist/src/lib/construct/site-with-ecs-backend/main.js +1 -1
  15. package/dist/src/lib/{construct/api-to-eventbridge-target/api-destination-event.d.ts → helper/api-to-eventbridge-target-event.d.ts} +5 -3
  16. package/dist/src/lib/{construct/api-to-eventbridge-target/api-destination-event.js → helper/api-to-eventbridge-target-event.js} +6 -4
  17. package/dist/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.d.ts → helper/api-to-eventbridge-target-rest-api.d.ts} +4 -4
  18. package/dist/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.js → helper/api-to-eventbridge-target-rest-api.js} +5 -5
  19. package/dist/src/lib/helper/index.d.ts +2 -0
  20. package/dist/src/lib/helper/index.js +18 -0
  21. package/dist/src/lib/manager/aws/ecs-manager.js +5 -0
  22. package/dist/src/lib/manager/aws/lambda-manager.js +1 -0
  23. package/dist/src/lib/types/aws/index.d.ts +10 -5
  24. package/package.json +1 -1
  25. package/src/lib/construct/api-to-eventbridge-target/index.ts +0 -3
  26. package/src/lib/construct/api-to-eventbridge-target/main.ts +131 -280
  27. package/src/lib/construct/{api-to-eventbridge-target → api-to-eventbridge-target-with-sns}/api-destined-lambda.ts +1 -1
  28. package/src/lib/construct/api-to-eventbridge-target-with-sns/index.ts +2 -0
  29. package/src/lib/construct/api-to-eventbridge-target-with-sns/main.ts +703 -0
  30. package/src/lib/construct/graphql-api-lambda/main.ts +1 -1
  31. package/src/lib/construct/index.ts +1 -0
  32. package/src/lib/construct/site-with-ecs-backend/main.ts +1 -1
  33. package/src/lib/{construct/api-to-eventbridge-target/api-destination-event.ts → helper/api-to-eventbridge-target-event.ts} +5 -3
  34. package/src/lib/{construct/api-to-eventbridge-target/api-destined-rest-api.ts → helper/api-to-eventbridge-target-rest-api.ts} +4 -4
  35. package/src/lib/helper/index.ts +2 -0
  36. package/src/lib/manager/aws/ecs-manager.ts +5 -0
  37. package/src/lib/manager/aws/lambda-manager.ts +1 -0
  38. package/src/lib/types/aws/index.ts +10 -5
@@ -3,15 +3,11 @@ import * as apig from 'aws-cdk-lib/aws-apigateway'
3
3
  import * as events from 'aws-cdk-lib/aws-events'
4
4
  import * as eventstargets from 'aws-cdk-lib/aws-events-targets'
5
5
  import * as iam from 'aws-cdk-lib/aws-iam'
6
- import * as lambda from 'aws-cdk-lib/aws-lambda'
7
- import * as destinations from 'aws-cdk-lib/aws-lambda-destinations'
8
6
  import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
9
7
  import { Construct } from 'constructs'
10
8
  import { CommonConstruct } from '../../common'
11
- import * as types from '../../types'
12
- import { ApiDestinationEvent } from './api-destination-event'
13
- import { ApiDestinedLambda } from './api-destined-lambda'
14
- import { ApiDestinedRestApi } from './api-destined-rest-api'
9
+ import * as helper from '../../helper'
10
+ import * as types from '../../types/aws'
15
11
 
16
12
  /**
17
13
  * @stability stable
@@ -42,14 +38,11 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
42
38
  /* application related resources */
43
39
  applicationSecrets: secretsmanager.ISecret[]
44
40
 
45
- /* destined lambda related resources */
46
- apiDestinedLambda: types.ApiDestinedLambdaType
47
-
48
41
  /* event related resources */
49
- apiEvent: types.ApiDestinationEventType
42
+ apiEvent: types.ApiToEventBridgeTargetEventType
50
43
 
51
44
  /* rest restApi related resources */
52
- apiDestinedRestApi: types.ApiDestinedRestApiType
45
+ apiToEventBridgeTargetRestApi: types.ApiToEventBridgeTargetRestApiType
53
46
  apiResource: string
54
47
 
55
48
  constructor(parent: Construct, id: string, props: types.ApiToEventBridgeTargetProps) {
@@ -58,9 +51,8 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
58
51
  this.props = props
59
52
  this.id = id
60
53
 
61
- this.apiDestinedLambda = new ApiDestinedLambda()
62
- this.apiEvent = new ApiDestinationEvent()
63
- this.apiDestinedRestApi = new ApiDestinedRestApi()
54
+ this.apiEvent = new helper.ApiToEventbridgeTargetEvent()
55
+ this.apiToEventBridgeTargetRestApi = new helper.ApiToEventbridgeTargetRestApi()
64
56
  this.apiResource = 'notify'
65
57
  }
66
58
 
@@ -73,37 +65,27 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
73
65
  this.resolveCertificate()
74
66
 
75
67
  /* optional custom event bus */
76
- this.createApiDestinedEventBus()
77
-
78
- /* destined lambda related resources */
79
- this.createApiDestinedLambdaPolicy()
80
- this.createApiDestinedLambdaRole()
81
- this.createApiDestinedLambdaEnvironment()
82
- this.createApiDestinedLambdaLayers()
83
- this.createApiDestinedLambdaDestinations()
84
- this.createApiDestinedLambdaFunction()
68
+ this.createApiToEventBridgeTargetEventBus()
85
69
 
86
70
  /* event related resources */
87
- this.createApiDestinationLogGroupSuccess()
88
- this.createApiDestinationRuleSuccess()
89
- this.createApiDestinationLogGroupFailure()
90
- this.createApiDestinationRuleFailure()
71
+ this.createApiToEventBridgeTargetLogGroup()
72
+ this.createApiToEventBridgeTargetRule()
73
+ this.createApiToEventBridgeTargetPolicy()
74
+ this.createApiToEventBridgeTargetRole()
91
75
 
92
76
  /* restApi related resources */
93
- this.createApiDestinedTopicRole()
94
- this.createApiDestinedTopic()
95
- this.createApiDestinedIntegrationRequestParameters()
96
- this.createApiDestinedIntegrationRequestTemplates()
97
- this.createApiDestinedIntegrationResponse()
98
- this.createApiDestinedIntegrationErrorResponse()
99
- this.createApiDestinedIntegration()
100
- this.createApiDestinedRestApi()
101
- this.createApiDestinedResource()
102
- this.createApiDestinedResponseModel()
103
- this.createApiDestinedErrorResponseModel()
104
- this.createApiDestinedMethodResponse()
105
- this.createApiDestinedMethodErrorResponse()
106
- this.createApiDestinedResourceMethod()
77
+ this.createApiToEventBridgeTargetIntegrationRequestParameters()
78
+ this.createApiToEventBridgeTargetIntegrationRequestTemplates()
79
+ this.createApiToEventBridgeTargetIntegrationResponse()
80
+ this.createApiToEventBridgeTargetIntegrationErrorResponse()
81
+ this.createApiToEventBridgeTargetIntegration()
82
+ this.createApiToEventBridgeTargetRestApi()
83
+ this.createApiToEventBridgeTargetResource()
84
+ this.createApiToEventBridgeTargetResponseModel()
85
+ this.createApiToEventBridgeTargetErrorResponseModel()
86
+ this.createApiToEventBridgeTargetMethodResponse()
87
+ this.createApiToEventBridgeTargetMethodErrorResponse()
88
+ this.createApiToEventBridgeTargetResourceMethod()
107
89
  this.createApiDomain()
108
90
  this.createApiBasePathMapping()
109
91
  this.createApiRouteAssets()
@@ -123,7 +105,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
123
105
  * @protected
124
106
  */
125
107
  protected resolveHostedZone() {
126
- this.apiDestinedRestApi.hostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(
108
+ this.apiToEventBridgeTargetRestApi.hostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(
127
109
  `${this.id}-hosted-zone`,
128
110
  this,
129
111
  this.props.useExistingHostedZone
@@ -149,7 +131,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
149
131
  )
150
132
  }
151
133
 
152
- this.apiDestinedRestApi.certificate = this.acmManager.resolveCertificate(
134
+ this.apiToEventBridgeTargetRestApi.certificate = this.acmManager.resolveCertificate(
153
135
  `${this.id}-certificate`,
154
136
  this,
155
137
  this.props.api.certificate
@@ -157,124 +139,34 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
157
139
  }
158
140
 
159
141
  /**
160
- * @summary Method to create iam policy for Api Destined Lambda function
161
- * @protected
162
- */
163
- protected createApiDestinedLambdaPolicy() {
164
- if (this.props.api.useExisting) return
165
- this.apiDestinedLambda.policy = new iam.PolicyDocument({
166
- statements: [this.iamManager.statementForReadSecrets(this), this.iamManager.statementForPutEvents()],
167
- })
168
- }
169
-
170
- /**
171
- * @summary Method to create iam role for Api Destined Lambda function
172
- * @protected
173
- */
174
- protected createApiDestinedLambdaRole() {
175
- if (this.props.api.useExisting) return
176
- this.apiDestinedLambda.role = this.iamManager.createRoleForLambda(
177
- `${this.id}-lambda-destined-role`,
178
- this,
179
- this.apiDestinedLambda.policy
180
- )
181
- }
182
-
183
- /**
184
- * @summary Method to create environment variables for Api Destined Lambda function
142
+ * @summary Method to create or use an existing eventbus for api payload deliveries
185
143
  * @protected
186
144
  */
187
- protected createApiDestinedLambdaEnvironment() {
188
- if (this.props.api.useExisting) return
189
- this.apiDestinedLambda.environment = {
190
- NODE_ENV: this.props.nodeEnv,
191
- LOG_LEVEL: this.props.logLevel,
192
- TZ: this.props.timezone,
193
- SOURCE_ID: this.id,
194
- }
195
- }
196
-
197
- /**
198
- * @summary Method to create layers for Api Destined Lambda function
199
- * @protected
200
- */
201
- protected createApiDestinedLambdaLayers() {
202
- if (this.props.api.useExisting) return
203
- const layers: lambda.LayerVersion[] = []
204
- if (this.props.lambda.layerSource) {
205
- layers.push(
206
- this.lambdaManager.createLambdaLayer(`${this.id}-lambda-destined-layer`, this, this.props.lambda.layerSource)
207
- )
208
- }
209
-
210
- this.apiDestinedLambda.layers = layers
211
- }
212
-
213
- /**
214
- * @summary Method to create destination for Api Destined function
215
- * @protected
216
- */
217
- protected createApiDestinedLambdaDestinations() {
218
- if (this.props.api.useExisting) return
219
- this.apiDestinedLambda.destinationSuccess = new destinations.EventBridgeDestination(this.apiEvent.eventBus)
220
- this.apiDestinedLambda.destinationFailure = new destinations.EventBridgeDestination(this.apiEvent.eventBus)
221
- }
222
-
223
- /**
224
- * @summary Method to create lambda function for Api Destined
225
- * @protected
226
- */
227
- protected createApiDestinedLambdaFunction() {
228
- if (this.props.api.useExisting) return
229
- if (!this.props.lambda.source) throw 'Api Destined Lambda props undefined'
230
-
231
- this.apiDestinedLambda.function = this.lambdaManager.createLambdaFunction(
232
- `${this.id}-lambda-destined`,
233
- this,
234
- {
235
- ...this.props.lambda.function,
236
- ...{
237
- onSuccess: this.apiDestinedLambda.destinationSuccess,
238
- onFailure: this.apiDestinedLambda.destinationFailure,
239
- },
240
- },
241
- this.apiDestinedLambda.role,
242
- this.apiDestinedLambda.layers,
243
- this.props.lambda.source,
244
- this.props.lambda.handler ?? 'lambda.handler',
245
- this.apiDestinedLambda.environment
246
- )
247
- }
248
-
249
- /**
250
- * @summary Method to create or use an existing eventbus for api destined payload deliveries
251
- * @protected
252
- */
253
- protected createApiDestinedEventBus() {
145
+ protected createApiToEventBridgeTargetEventBus() {
254
146
  if (this.props.api.useExisting) {
255
147
  this.apiEvent.eventBus = events.EventBus.fromEventBusName(
256
148
  this,
257
- `${this.id}-destined-event-bus`,
149
+ `${this.id}-event-bus`,
258
150
  `${this.props.event.eventBusName}-${this.props.stage}`
259
151
  )
260
152
  return
261
153
  }
262
- this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-destined-event-bus`, this, {
154
+ this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-event-bus`, this, {
263
155
  eventBusName: `${this.props.event.eventBusName}`,
264
156
  })
265
157
  }
266
158
 
267
159
  /**
268
- * @summary Method to create a log group for successful api destined payload deliveries
160
+ * @summary Method to create a log group for successful api payload deliveries
269
161
  * @protected
270
162
  */
271
- protected createApiDestinationLogGroupSuccess() {
163
+ protected createApiToEventBridgeTargetLogGroup() {
272
164
  if (this.props.api.useExisting) return
273
- this.apiEvent.logGroupSuccess = this.logManager.createLogGroup(`${this.id}-destination-success-log`, this, {
165
+ this.apiEvent.logGroup = this.logManager.createLogGroup(`${this.id}-log`, this, {
274
166
  ...{
275
- logGroupName: `/${this.id}/events/api-destination-success`,
167
+ logGroupName: `/${this.id}/events/api-to-eventbridge-target`,
276
168
  },
277
- ...this.props.event.logGroupSuccess,
169
+ ...this.props.event.logGroup,
278
170
  })
279
171
  }
280
172
 
@@ -282,111 +174,53 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
282
174
  * Method to create EventBridge rule with lambda target for success
283
175
  * @protected
284
176
  */
285
- protected createApiDestinationRuleSuccess() {
177
+ protected createApiToEventBridgeTargetRule() {
286
178
  if (this.props.api.useExisting) return
287
- this.props.event.ruleSuccess = {
179
+ this.props.event.rule = {
288
180
  ...{
289
- ruleName: `${this.id}-api-destination-success`,
181
+ ruleName: `${this.id}-api-to-eventbridge-target`,
290
182
  eventPattern: {
291
- detail: {
292
- requestContext: {
293
- condition: ['Success'],
294
- },
295
- responsePayload: {
296
- source: ['custom:api-destined-lambda'],
297
- sourceId: [this.id],
298
- },
299
- },
183
+ source: ['api-to-eventbridge-target'],
184
+ detailType: ['external-client-event'],
300
185
  },
301
186
  },
302
- ...this.props.event.ruleSuccess,
187
+ ...this.props.event.rule,
303
188
  }
304
- this.apiEvent.ruleSuccess = this.eventManager.createRule(
305
- `${this.id}-api-destination-rule-success`,
189
+ this.apiEvent.rule = this.eventManager.createRule(
190
+ `${this.id}-api-to-eventbridge-target-rule`,
306
191
  this,
307
- this.props.event.ruleSuccess,
192
+ this.props.event.rule,
308
193
  this.apiEvent.eventBus,
309
- [new eventstargets.CloudWatchLogGroup(this.apiEvent.logGroupSuccess)]
194
+ [new eventstargets.CloudWatchLogGroup(this.apiEvent.logGroup)]
310
195
  )
311
196
  }
312
197
 
313
- /**
314
- * @summary Method to create a log group for failed api destined payload deliveries
315
- * @protected
316
- */
317
- protected createApiDestinationLogGroupFailure() {
318
- if (this.props.api.useExisting) return
319
- this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
320
- ...{
321
- logGroupName: `/${this.id}/events/api-destination-failure`,
322
- },
323
- ...this.props.event.logGroupFailure,
198
+ protected createApiToEventBridgeTargetPolicy() {
199
+ this.apiToEventBridgeTargetRestApi.policy = new iam.PolicyDocument({
200
+ statements: [this.iamManager.statementForPutEvents()],
324
201
  })
325
202
  }
326
203
 
327
204
  /**
328
- * Method to create EventBridge rule with lambda target for failure
205
+ * @summary Method to create a role for api integration
329
206
  * @protected
330
207
  */
331
- protected createApiDestinationRuleFailure() {
332
- if (this.props.api.useExisting) return
333
- this.props.event.ruleFailure = {
334
- ...{
335
- ruleName: `${this.id}-api-destination-failure`,
336
- eventPattern: {
337
- detail: {
338
- responsePayload: {
339
- errorType: ['Error'],
340
- },
341
- },
342
- },
343
- },
344
- ...this.props.event.ruleFailure,
345
- }
346
- this.apiEvent.ruleFailure = this.eventManager.createRule(
347
- `${this.id}-api-destination-rule-failure`,
348
- this,
349
- this.props.event.ruleFailure,
350
- this.apiEvent.eventBus,
351
- [new eventstargets.CloudWatchLogGroup(this.apiEvent.logGroupFailure)]
352
- )
353
- }
208
+ protected createApiToEventBridgeTargetRole() {
209
+ if (!this.apiToEventBridgeTargetRestApi.policy) throw 'Policy undefined'
354
210
 
355
- /**
356
- * @summary Method to create a role for sns topic
357
- * @protected
358
- */
359
- protected createApiDestinedTopicRole() {
360
- this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
211
+ this.apiToEventBridgeTargetRestApi.role = new iam.Role(this, `${this.id}-rest-api-role`, {
361
212
  assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
213
+ inlinePolicies: { policy: this.apiToEventBridgeTargetRestApi.policy },
362
214
  })
363
215
  }
364
216
 
365
- /**
366
- * @summary Method to create API destined SNS topic
367
- * @protected
368
- */
369
- protected createApiDestinedTopic() {
370
- if (!this.props.api.withResource) return
371
- this.apiDestinedRestApi.topic = this.snsManager.createLambdaNotificationService(
372
- `${this.id}-destined-topic`,
373
- this,
374
- {
375
- topicName: `${this.id}-destined-topic`,
376
- },
377
- this.apiDestinedLambda.function
378
- )
379
-
380
- this.apiDestinedRestApi.topic.grantPublish(this.apiDestinedRestApi.topicRole)
381
- }
382
-
383
217
  /**
384
218
  * @summary Method to create api integration request parameters
385
219
  * @protected
386
220
  */
387
- protected createApiDestinedIntegrationRequestParameters() {
221
+ protected createApiToEventBridgeTargetIntegrationRequestParameters() {
388
222
  if (!this.props.api.withResource) return
389
- this.apiDestinedRestApi.integrationRequestParameters = {
223
+ this.apiToEventBridgeTargetRestApi.integrationRequestParameters = {
390
224
  'integration.request.header.Content-Type': "'application/x-www-form-urlencoded'",
391
225
  }
392
226
  }
@@ -395,15 +229,24 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
395
229
  * @summary Method to create api integration request templates
396
230
  * @protected
397
231
  */
398
- protected createApiDestinedIntegrationRequestTemplates() {
232
+ protected createApiToEventBridgeTargetIntegrationRequestTemplates() {
399
233
  if (!this.props.api.withResource) return
400
- this.apiDestinedRestApi.integrationRequestTemplates = {
234
+ this.apiToEventBridgeTargetRestApi.integrationRequestTemplates = {
401
235
  'application/json': [
402
- 'Action=Publish',
403
- `TargetArn=$util.urlEncode('${this.apiDestinedRestApi.topic.topicArn}')`,
404
- 'Message=$util.urlEncode($input.body)',
405
- 'Version=2010-03-31',
406
- ].join('&'),
236
+ '#set($context.requestOverride.header.X-Amz-Target = "AWSEvents.PutEvents")',
237
+ '#set($context.requestOverride.header.Content-Type = "application/x-amz-json-1.1")',
238
+ "#set($inputRoot = $input.path('$'))",
239
+ `{
240
+ "Entries": [
241
+ {
242
+ "EventBusName": "${this.apiEvent.eventBus.eventBusName}",
243
+ "Source": "api-to-eventbridge-target",
244
+ "DetailType": "external-client-event",
245
+ "Detail": "$util.escapeJavaScript($input.json('$'))"
246
+ }
247
+ ]
248
+ }`,
249
+ ].join('\r'),
407
250
  }
408
251
  }
409
252
 
@@ -411,9 +254,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
411
254
  * @summary Method to create api integration response
412
255
  * @protected
413
256
  */
414
- protected createApiDestinedIntegrationResponse() {
257
+ protected createApiToEventBridgeTargetIntegrationResponse() {
415
258
  if (!this.props.api.withResource) return
416
- this.apiDestinedRestApi.integrationResponse = this.props.api.integrationResponse ?? {
259
+ this.apiToEventBridgeTargetRestApi.integrationResponse = this.props.api.integrationResponse ?? {
417
260
  ...{
418
261
  statusCode: '200',
419
262
  responseTemplates: {
@@ -427,9 +270,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
427
270
  * @summary Method to create api integration error response
428
271
  * @protected
429
272
  */
430
- protected createApiDestinedIntegrationErrorResponse() {
273
+ protected createApiToEventBridgeTargetIntegrationErrorResponse() {
431
274
  if (!this.props.api.withResource) return
432
- this.apiDestinedRestApi.integrationErrorResponse = {
275
+ this.apiToEventBridgeTargetRestApi.integrationErrorResponse = {
433
276
  ...{
434
277
  selectionPattern: '^\\[Error\\].*',
435
278
  statusCode: '400',
@@ -453,21 +296,21 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
453
296
  * @summary Method to create api integration
454
297
  * @protected
455
298
  */
456
- protected createApiDestinedIntegration() {
299
+ protected createApiToEventBridgeTargetIntegration() {
457
300
  if (!this.props.api.withResource) return
458
- this.apiDestinedRestApi.integration = new apig.Integration({
301
+ this.apiToEventBridgeTargetRestApi.integration = new apig.Integration({
459
302
  type: apig.IntegrationType.AWS,
460
303
  integrationHttpMethod: 'POST',
461
- uri: `arn:aws:apigateway:${this.props.region}:sns:path//`,
304
+ uri: `arn:aws:apigateway:${this.props.region}:events:path//`,
462
305
  options: {
463
306
  ...{
464
- credentialsRole: this.apiDestinedRestApi.topicRole,
465
- requestParameters: this.apiDestinedRestApi.integrationRequestParameters,
466
- requestTemplates: this.apiDestinedRestApi.integrationRequestTemplates,
307
+ credentialsRole: this.apiToEventBridgeTargetRestApi.role,
308
+ requestParameters: this.apiToEventBridgeTargetRestApi.integrationRequestParameters,
309
+ requestTemplates: this.apiToEventBridgeTargetRestApi.integrationRequestTemplates,
467
310
  passthroughBehavior: apig.PassthroughBehavior.NEVER,
468
311
  integrationResponses: [
469
- this.apiDestinedRestApi.integrationResponse,
470
- this.apiDestinedRestApi.integrationErrorResponse,
312
+ this.apiToEventBridgeTargetRestApi.integrationResponse,
313
+ this.apiToEventBridgeTargetRestApi.integrationErrorResponse,
471
314
  ],
472
315
  },
473
316
  ...this.props.api.integrationOptions,
@@ -479,9 +322,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
479
322
  * @summary Method to create api integration method response
480
323
  * @protected
481
324
  */
482
- protected createApiDestinedMethodResponse() {
325
+ protected createApiToEventBridgeTargetMethodResponse() {
483
326
  if (!this.props.api.withResource) return
484
- this.apiDestinedRestApi.methodResponse = {
327
+ this.apiToEventBridgeTargetRestApi.methodResponse = {
485
328
  ...{
486
329
  statusCode: '200',
487
330
  responseParameters: {
@@ -490,7 +333,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
490
333
  'method.response.header.Access-Control-Allow-Credentials': true,
491
334
  },
492
335
  responseModels: {
493
- 'application/json': this.apiDestinedRestApi.responseModel,
336
+ 'application/json': this.apiToEventBridgeTargetRestApi.responseModel,
494
337
  },
495
338
  },
496
339
  ...this.props.api.methodResponse,
@@ -501,9 +344,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
501
344
  * @summary Method to create api integration method error response
502
345
  * @protected
503
346
  */
504
- protected createApiDestinedMethodErrorResponse() {
347
+ protected createApiToEventBridgeTargetMethodErrorResponse() {
505
348
  if (!this.props.api.withResource) return
506
- this.apiDestinedRestApi.methodErrorResponse = {
349
+ this.apiToEventBridgeTargetRestApi.methodErrorResponse = {
507
350
  ...{
508
351
  statusCode: '400',
509
352
  responseParameters: {
@@ -512,7 +355,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
512
355
  'method.response.header.Access-Control-Allow-Credentials': true,
513
356
  },
514
357
  responseModels: {
515
- 'application/json': this.apiDestinedRestApi.errorResponseModel,
358
+ 'application/json': this.apiToEventBridgeTargetRestApi.errorResponseModel,
516
359
  },
517
360
  },
518
361
  ...this.props.api.methodErrorResponse,
@@ -523,29 +366,34 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
523
366
  * @summary Method to create rest restApi for Api
524
367
  * @protected
525
368
  */
526
- protected createApiDestinedRestApi() {
369
+ protected createApiToEventBridgeTargetRestApi() {
527
370
  if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
528
- this.apiDestinedRestApi.api = apig.RestApi.fromRestApiId(
371
+ this.apiToEventBridgeTargetRestApi.api = apig.RestApi.fromRestApiId(
529
372
  this,
530
- `${this.id}-sns-rest-api`,
373
+ `${this.id}-rest-api`,
531
374
  cdk.Fn.importValue(this.props.api.importedRestApiRef)
532
375
  )
533
376
  return
534
377
  }
535
378
 
536
- const accessLogGroup = this.logManager.createLogGroup(`${this.id}-sns-rest-api-access-log`, this, {
537
- logGroupName: `/custom/api/${this.id}-destined-rest-api-access-${this.props.stage}`,
379
+ const accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
380
+ logGroupName: `/custom/api/${this.id}-rest-api-access`,
538
381
  removalPolicy: cdk.RemovalPolicy.DESTROY,
539
382
  })
540
383
 
541
- this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
384
+ this.apiToEventBridgeTargetRestApi.api = new apig.RestApi(this, `${this.id}-rest-api`, {
542
385
  ...{
543
- defaultIntegration: this.apiDestinedRestApi.integration,
386
+ cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
387
+ defaultIntegration: this.apiToEventBridgeTargetRestApi.integration,
544
388
  defaultMethodOptions: {
545
- methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
389
+ methodResponses: [
390
+ this.apiToEventBridgeTargetRestApi.methodResponse,
391
+ this.apiToEventBridgeTargetRestApi.methodErrorResponse,
392
+ ],
546
393
  },
547
394
  deployOptions: {
548
- dataTraceEnabled: true,
395
+ tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
396
+ dataTraceEnabled: this.props.api.restApi?.deployOptions?.dataTraceEnabled,
549
397
  description: `${this.id} - ${this.props.stage} stage`,
550
398
  loggingLevel: apig.MethodLoggingLevel.INFO,
551
399
  metricsEnabled: true,
@@ -561,22 +409,22 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
561
409
  allowMethods: ['POST'],
562
410
  allowHeaders: apig.Cors.DEFAULT_HEADERS,
563
411
  },
564
- restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
412
+ restApiName: `${this.id}-rest-api-${this.props.stage}`,
565
413
  },
566
- ...this.props.api,
414
+ ...this.props.api.restApi,
567
415
  })
568
- this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId)
569
- this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiDestinedRestApi.api.root.resourceId)
416
+ this.addCfnOutput(`${this.id}-restApiId`, this.apiToEventBridgeTargetRestApi.api.restApiId)
417
+ this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiToEventBridgeTargetRestApi.api.root.resourceId)
570
418
  }
571
419
 
572
420
  /**
573
421
  * @summary Method to create api integration response model
574
422
  * @protected
575
423
  */
576
- protected createApiDestinedResponseModel() {
424
+ protected createApiToEventBridgeTargetResponseModel() {
577
425
  if (!this.props.api.withResource) return
578
- this.apiDestinedRestApi.responseModel = new apig.Model(this, `${this.id}-response-model`, {
579
- restApi: this.apiDestinedRestApi.api,
426
+ this.apiToEventBridgeTargetRestApi.responseModel = new apig.Model(this, `${this.id}-response-model`, {
427
+ restApi: this.apiToEventBridgeTargetRestApi.api,
580
428
  ...{
581
429
  contentType: 'application/json',
582
430
  modelName: 'ResponseModel',
@@ -595,10 +443,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
595
443
  * @summary Method to create api integration error response model
596
444
  * @protected
597
445
  */
598
- protected createApiDestinedErrorResponseModel() {
446
+ protected createApiToEventBridgeTargetErrorResponseModel() {
599
447
  if (!this.props.api.withResource) return
600
- this.apiDestinedRestApi.errorResponseModel = new apig.Model(this, `${this.id}-error-response-model`, {
601
- restApi: this.apiDestinedRestApi.api,
448
+ this.apiToEventBridgeTargetRestApi.errorResponseModel = new apig.Model(this, `${this.id}-error-response-model`, {
449
+ restApi: this.apiToEventBridgeTargetRestApi.api,
602
450
  ...{
603
451
  contentType: 'application/json',
604
452
  modelName: 'ErrorResponseModel',
@@ -620,35 +468,38 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
620
468
  * @summary Method to create api integration resource
621
469
  * @protected
622
470
  */
623
- protected createApiDestinedResource() {
471
+ protected createApiToEventBridgeTargetResource() {
624
472
  if (!this.props.api.withResource) return
625
473
 
626
474
  let rootResource
627
475
  if (this.props.api.withResource && this.props.api.importedRestApiRootResourceRef) {
628
476
  rootResource = apig.Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
629
477
  resourceId: cdk.Fn.importValue(this.props.api.importedRestApiRootResourceRef),
630
- restApi: this.apiDestinedRestApi.api,
478
+ restApi: this.apiToEventBridgeTargetRestApi.api,
631
479
  path: '/',
632
480
  })
633
481
  } else {
634
- rootResource = this.apiDestinedRestApi.api.root
482
+ rootResource = this.apiToEventBridgeTargetRestApi.api.root
635
483
  }
636
484
 
637
- this.apiDestinedRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource)
485
+ this.apiToEventBridgeTargetRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource)
638
486
  }
639
487
 
640
488
  /**
641
489
  * @summary Method to create api integration resource method
642
490
  * @protected
643
491
  */
644
- protected createApiDestinedResourceMethod() {
492
+ protected createApiToEventBridgeTargetResourceMethod() {
645
493
  if (!this.props.api.withResource) return
646
- this.apiDestinedRestApi.method = this.apiDestinedRestApi.resource.addMethod(
494
+ this.apiToEventBridgeTargetRestApi.method = this.apiToEventBridgeTargetRestApi.resource.addMethod(
647
495
  'POST',
648
- this.apiDestinedRestApi.integration,
496
+ this.apiToEventBridgeTargetRestApi.integration,
649
497
  {
650
- authorizer: this.apiDestinedRestApi.authoriser,
651
- methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
498
+ authorizer: this.apiToEventBridgeTargetRestApi.authoriser,
499
+ methodResponses: [
500
+ this.apiToEventBridgeTargetRestApi.methodResponse,
501
+ this.apiToEventBridgeTargetRestApi.methodErrorResponse,
502
+ ],
652
503
  }
653
504
  )
654
505
  }
@@ -659,13 +510,13 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
659
510
  */
660
511
  protected createApiDomain() {
661
512
  if (this.props.api.useExisting) return
662
- this.apiDestinedRestApi.domain = this.apiManager.createApiDomain(
513
+ this.apiToEventBridgeTargetRestApi.domain = this.apiManager.createApiDomain(
663
514
  `${this.id}-api-domain`,
664
515
  this,
665
516
  this.isProductionStage() || this.props.skipStageForARecords
666
517
  ? `${this.props.apiSubDomain}.${this.fullyQualifiedDomainName}`
667
518
  : `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`,
668
- this.apiDestinedRestApi.certificate
519
+ this.apiToEventBridgeTargetRestApi.certificate
669
520
  )
670
521
  }
671
522
 
@@ -677,9 +528,9 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
677
528
  if (this.props.api.useExisting) return
678
529
  new apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
679
530
  basePath: '',
680
- domainName: this.apiDestinedRestApi.domain,
681
- restApi: this.apiDestinedRestApi.api,
682
- stage: this.apiDestinedRestApi.api.deploymentStage,
531
+ domainName: this.apiToEventBridgeTargetRestApi.domain,
532
+ restApi: this.apiToEventBridgeTargetRestApi.api,
533
+ stage: this.apiToEventBridgeTargetRestApi.api.deploymentStage,
683
534
  })
684
535
  }
685
536
 
@@ -693,8 +544,8 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
693
544
  `${this.id}-custom-domain-a-record`,
694
545
  this,
695
546
  this.props.apiSubDomain,
696
- this.apiDestinedRestApi.domain,
697
- this.apiDestinedRestApi.hostedZone,
547
+ this.apiToEventBridgeTargetRestApi.domain,
548
+ this.apiToEventBridgeTargetRestApi.hostedZone,
698
549
  this.props.skipStageForARecords
699
550
  )
700
551
  }