@gradientedge/cdk-utils 5.13.0 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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/sqs-manager.js +0 -1
  23. package/dist/src/lib/types/aws/index.d.ts +10 -5
  24. package/package.json +11 -11
  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/sqs-manager.ts +0 -2
  38. package/src/lib/types/aws/index.ts +10 -5
@@ -29,11 +29,8 @@ const apig = __importStar(require("aws-cdk-lib/aws-apigateway"));
29
29
  const events = __importStar(require("aws-cdk-lib/aws-events"));
30
30
  const eventstargets = __importStar(require("aws-cdk-lib/aws-events-targets"));
31
31
  const iam = __importStar(require("aws-cdk-lib/aws-iam"));
32
- const destinations = __importStar(require("aws-cdk-lib/aws-lambda-destinations"));
33
32
  const common_1 = require("../../common");
34
- const api_destination_event_1 = require("./api-destination-event");
35
- const api_destined_lambda_1 = require("./api-destined-lambda");
36
- const api_destined_rest_api_1 = require("./api-destined-rest-api");
33
+ const helper = __importStar(require("../../helper"));
37
34
  /**
38
35
  * @stability stable
39
36
  * @category cdk-utils.api-to-eventbridge-target
@@ -61,20 +58,17 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
61
58
  id;
62
59
  /* application related resources */
63
60
  applicationSecrets;
64
- /* destined lambda related resources */
65
- apiDestinedLambda;
66
61
  /* event related resources */
67
62
  apiEvent;
68
63
  /* rest restApi related resources */
69
- apiDestinedRestApi;
64
+ apiToEventBridgeTargetRestApi;
70
65
  apiResource;
71
66
  constructor(parent, id, props) {
72
67
  super(parent, id, props);
73
68
  this.props = props;
74
69
  this.id = id;
75
- this.apiDestinedLambda = new api_destined_lambda_1.ApiDestinedLambda();
76
- this.apiEvent = new api_destination_event_1.ApiDestinationEvent();
77
- this.apiDestinedRestApi = new api_destined_rest_api_1.ApiDestinedRestApi();
70
+ this.apiEvent = new helper.ApiToEventbridgeTargetEvent();
71
+ this.apiToEventBridgeTargetRestApi = new helper.ApiToEventbridgeTargetRestApi();
78
72
  this.apiResource = 'notify';
79
73
  }
80
74
  initResources() {
@@ -84,34 +78,25 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
84
78
  this.resolveHostedZone();
85
79
  this.resolveCertificate();
86
80
  /* optional custom event bus */
87
- this.createApiDestinedEventBus();
88
- /* destined lambda related resources */
89
- this.createApiDestinedLambdaPolicy();
90
- this.createApiDestinedLambdaRole();
91
- this.createApiDestinedLambdaEnvironment();
92
- this.createApiDestinedLambdaLayers();
93
- this.createApiDestinedLambdaDestinations();
94
- this.createApiDestinedLambdaFunction();
81
+ this.createApiToEventBridgeTargetEventBus();
95
82
  /* event related resources */
96
- this.createApiDestinationLogGroupSuccess();
97
- this.createApiDestinationRuleSuccess();
98
- this.createApiDestinationLogGroupFailure();
99
- this.createApiDestinationRuleFailure();
83
+ this.createApiToEventBridgeTargetLogGroup();
84
+ this.createApiToEventBridgeTargetRule();
85
+ this.createApiToEventBridgeTargetPolicy();
86
+ this.createApiToEventBridgeTargetRole();
100
87
  /* restApi related resources */
101
- this.createApiDestinedTopicRole();
102
- this.createApiDestinedTopic();
103
- this.createApiDestinedIntegrationRequestParameters();
104
- this.createApiDestinedIntegrationRequestTemplates();
105
- this.createApiDestinedIntegrationResponse();
106
- this.createApiDestinedIntegrationErrorResponse();
107
- this.createApiDestinedIntegration();
108
- this.createApiDestinedRestApi();
109
- this.createApiDestinedResource();
110
- this.createApiDestinedResponseModel();
111
- this.createApiDestinedErrorResponseModel();
112
- this.createApiDestinedMethodResponse();
113
- this.createApiDestinedMethodErrorResponse();
114
- this.createApiDestinedResourceMethod();
88
+ this.createApiToEventBridgeTargetIntegrationRequestParameters();
89
+ this.createApiToEventBridgeTargetIntegrationRequestTemplates();
90
+ this.createApiToEventBridgeTargetIntegrationResponse();
91
+ this.createApiToEventBridgeTargetIntegrationErrorResponse();
92
+ this.createApiToEventBridgeTargetIntegration();
93
+ this.createApiToEventBridgeTargetRestApi();
94
+ this.createApiToEventBridgeTargetResource();
95
+ this.createApiToEventBridgeTargetResponseModel();
96
+ this.createApiToEventBridgeTargetErrorResponseModel();
97
+ this.createApiToEventBridgeTargetMethodResponse();
98
+ this.createApiToEventBridgeTargetMethodErrorResponse();
99
+ this.createApiToEventBridgeTargetResourceMethod();
115
100
  this.createApiDomain();
116
101
  this.createApiBasePathMapping();
117
102
  this.createApiRouteAssets();
@@ -129,7 +114,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
129
114
  * @protected
130
115
  */
131
116
  resolveHostedZone() {
132
- this.apiDestinedRestApi.hostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(`${this.id}-hosted-zone`, this, this.props.useExistingHostedZone);
117
+ this.apiToEventBridgeTargetRestApi.hostedZone = this.route53Manager.withHostedZoneFromFullyQualifiedDomainName(`${this.id}-hosted-zone`, this, this.props.useExistingHostedZone);
133
118
  }
134
119
  /**
135
120
  * @summary Method to resolve a certificate based on attributes
@@ -143,200 +128,79 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
143
128
  this.props.api.certificate.certificateRegion) {
144
129
  this.props.api.certificate.certificateArn = this.ssmManager.readStringParameterFromRegion(`${this.id}-certificate-param`, this, this.props.api.certificate.certificateSsmName, this.props.api.certificate.certificateRegion);
145
130
  }
146
- this.apiDestinedRestApi.certificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.api.certificate);
131
+ this.apiToEventBridgeTargetRestApi.certificate = this.acmManager.resolveCertificate(`${this.id}-certificate`, this, this.props.api.certificate);
147
132
  }
148
133
  /**
149
- * @summary Method to create iam policy for Api Destined Lambda function
134
+ * @summary Method to create or use an existing eventbus for api payload deliveries
150
135
  * @protected
151
136
  */
152
- createApiDestinedLambdaPolicy() {
153
- if (this.props.api.useExisting)
154
- return;
155
- this.apiDestinedLambda.policy = new iam.PolicyDocument({
156
- statements: [this.iamManager.statementForReadSecrets(this), this.iamManager.statementForPutEvents()],
157
- });
158
- }
159
- /**
160
- * @summary Method to create iam role for Api Destined Lambda function
161
- * @protected
162
- */
163
- createApiDestinedLambdaRole() {
164
- if (this.props.api.useExisting)
165
- return;
166
- this.apiDestinedLambda.role = this.iamManager.createRoleForLambda(`${this.id}-lambda-destined-role`, this, this.apiDestinedLambda.policy);
167
- }
168
- /**
169
- * @summary Method to create environment variables for Api Destined Lambda function
170
- * @protected
171
- */
172
- createApiDestinedLambdaEnvironment() {
173
- if (this.props.api.useExisting)
174
- return;
175
- this.apiDestinedLambda.environment = {
176
- NODE_ENV: this.props.nodeEnv,
177
- LOG_LEVEL: this.props.logLevel,
178
- TZ: this.props.timezone,
179
- SOURCE_ID: this.id,
180
- };
181
- }
182
- /**
183
- * @summary Method to create layers for Api Destined Lambda function
184
- * @protected
185
- */
186
- createApiDestinedLambdaLayers() {
187
- if (this.props.api.useExisting)
188
- return;
189
- const layers = [];
190
- if (this.props.lambda.layerSource) {
191
- layers.push(this.lambdaManager.createLambdaLayer(`${this.id}-lambda-destined-layer`, this, this.props.lambda.layerSource));
192
- }
193
- this.apiDestinedLambda.layers = layers;
194
- }
195
- /**
196
- * @summary Method to create destination for Api Destined function
197
- * @protected
198
- */
199
- createApiDestinedLambdaDestinations() {
200
- if (this.props.api.useExisting)
201
- return;
202
- this.apiDestinedLambda.destinationSuccess = new destinations.EventBridgeDestination(this.apiEvent.eventBus);
203
- this.apiDestinedLambda.destinationFailure = new destinations.EventBridgeDestination(this.apiEvent.eventBus);
204
- }
205
- /**
206
- * @summary Method to create lambda function for Api Destined
207
- * @protected
208
- */
209
- createApiDestinedLambdaFunction() {
210
- if (this.props.api.useExisting)
211
- return;
212
- if (!this.props.lambda.source)
213
- throw 'Api Destined Lambda props undefined';
214
- this.apiDestinedLambda.function = this.lambdaManager.createLambdaFunction(`${this.id}-lambda-destined`, this, {
215
- ...this.props.lambda.function,
216
- ...{
217
- onSuccess: this.apiDestinedLambda.destinationSuccess,
218
- onFailure: this.apiDestinedLambda.destinationFailure,
219
- },
220
- }, this.apiDestinedLambda.role, this.apiDestinedLambda.layers, this.props.lambda.source, this.props.lambda.handler ?? 'lambda.handler', this.apiDestinedLambda.environment);
221
- }
222
- /**
223
- * @summary Method to create or use an existing eventbus for api destined payload deliveries
224
- * @protected
225
- */
226
- createApiDestinedEventBus() {
137
+ createApiToEventBridgeTargetEventBus() {
227
138
  if (this.props.api.useExisting) {
228
- this.apiEvent.eventBus = events.EventBus.fromEventBusName(this, `${this.id}-destined-event-bus`, `${this.props.event.eventBusName}-${this.props.stage}`);
139
+ this.apiEvent.eventBus = events.EventBus.fromEventBusName(this, `${this.id}-event-bus`, `${this.props.event.eventBusName}-${this.props.stage}`);
229
140
  return;
230
141
  }
231
- this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-destined-event-bus`, this, {
142
+ this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-event-bus`, this, {
232
143
  eventBusName: `${this.props.event.eventBusName}`,
233
144
  });
234
145
  }
235
146
  /**
236
- * @summary Method to create a log group for successful api destined payload deliveries
147
+ * @summary Method to create a log group for successful api payload deliveries
237
148
  * @protected
238
149
  */
239
- createApiDestinationLogGroupSuccess() {
150
+ createApiToEventBridgeTargetLogGroup() {
240
151
  if (this.props.api.useExisting)
241
152
  return;
242
- this.apiEvent.logGroupSuccess = this.logManager.createLogGroup(`${this.id}-destination-success-log`, this, {
153
+ this.apiEvent.logGroup = this.logManager.createLogGroup(`${this.id}-log`, this, {
243
154
  ...{
244
- logGroupName: `/${this.id}/events/api-destination-success`,
155
+ logGroupName: `/${this.id}/events/api-to-eventbridge-target`,
245
156
  },
246
- ...this.props.event.logGroupSuccess,
157
+ ...this.props.event.logGroup,
247
158
  });
248
159
  }
249
160
  /**
250
161
  * Method to create EventBridge rule with lambda target for success
251
162
  * @protected
252
163
  */
253
- createApiDestinationRuleSuccess() {
164
+ createApiToEventBridgeTargetRule() {
254
165
  if (this.props.api.useExisting)
255
166
  return;
256
- this.props.event.ruleSuccess = {
167
+ this.props.event.rule = {
257
168
  ...{
258
- ruleName: `${this.id}-api-destination-success`,
169
+ ruleName: `${this.id}-api-to-eventbridge-target`,
259
170
  eventPattern: {
260
- detail: {
261
- requestContext: {
262
- condition: ['Success'],
263
- },
264
- responsePayload: {
265
- source: ['custom:api-destined-lambda'],
266
- sourceId: [this.id],
267
- },
268
- },
171
+ source: ['api-to-eventbridge-target'],
172
+ detailType: ['external-client-event'],
269
173
  },
270
174
  },
271
- ...this.props.event.ruleSuccess,
175
+ ...this.props.event.rule,
272
176
  };
273
- 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)]);
177
+ this.apiEvent.rule = this.eventManager.createRule(`${this.id}-api-to-eventbridge-target-rule`, this, this.props.event.rule, this.apiEvent.eventBus, [new eventstargets.CloudWatchLogGroup(this.apiEvent.logGroup)]);
274
178
  }
275
- /**
276
- * @summary Method to create a log group for failed api destined payload deliveries
277
- * @protected
278
- */
279
- createApiDestinationLogGroupFailure() {
280
- if (this.props.api.useExisting)
281
- return;
282
- this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
283
- ...{
284
- logGroupName: `/${this.id}/events/api-destination-failure`,
285
- },
286
- ...this.props.event.logGroupFailure,
179
+ createApiToEventBridgeTargetPolicy() {
180
+ this.apiToEventBridgeTargetRestApi.policy = new iam.PolicyDocument({
181
+ statements: [this.iamManager.statementForPutEvents()],
287
182
  });
288
183
  }
289
184
  /**
290
- * Method to create EventBridge rule with lambda target for failure
291
- * @protected
292
- */
293
- createApiDestinationRuleFailure() {
294
- if (this.props.api.useExisting)
295
- return;
296
- this.props.event.ruleFailure = {
297
- ...{
298
- ruleName: `${this.id}-api-destination-failure`,
299
- eventPattern: {
300
- detail: {
301
- responsePayload: {
302
- errorType: ['Error'],
303
- },
304
- },
305
- },
306
- },
307
- ...this.props.event.ruleFailure,
308
- };
309
- 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)]);
310
- }
311
- /**
312
- * @summary Method to create a role for sns topic
185
+ * @summary Method to create a role for api integration
313
186
  * @protected
314
187
  */
315
- createApiDestinedTopicRole() {
316
- this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
188
+ createApiToEventBridgeTargetRole() {
189
+ if (!this.apiToEventBridgeTargetRestApi.policy)
190
+ throw 'Policy undefined';
191
+ this.apiToEventBridgeTargetRestApi.role = new iam.Role(this, `${this.id}-rest-api-role`, {
317
192
  assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
193
+ inlinePolicies: { policy: this.apiToEventBridgeTargetRestApi.policy },
318
194
  });
319
195
  }
320
- /**
321
- * @summary Method to create API destined SNS topic
322
- * @protected
323
- */
324
- createApiDestinedTopic() {
325
- if (!this.props.api.withResource)
326
- return;
327
- this.apiDestinedRestApi.topic = this.snsManager.createLambdaNotificationService(`${this.id}-destined-topic`, this, {
328
- topicName: `${this.id}-destined-topic`,
329
- }, this.apiDestinedLambda.function);
330
- this.apiDestinedRestApi.topic.grantPublish(this.apiDestinedRestApi.topicRole);
331
- }
332
196
  /**
333
197
  * @summary Method to create api integration request parameters
334
198
  * @protected
335
199
  */
336
- createApiDestinedIntegrationRequestParameters() {
200
+ createApiToEventBridgeTargetIntegrationRequestParameters() {
337
201
  if (!this.props.api.withResource)
338
202
  return;
339
- this.apiDestinedRestApi.integrationRequestParameters = {
203
+ this.apiToEventBridgeTargetRestApi.integrationRequestParameters = {
340
204
  'integration.request.header.Content-Type': "'application/x-www-form-urlencoded'",
341
205
  };
342
206
  }
@@ -344,26 +208,35 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
344
208
  * @summary Method to create api integration request templates
345
209
  * @protected
346
210
  */
347
- createApiDestinedIntegrationRequestTemplates() {
211
+ createApiToEventBridgeTargetIntegrationRequestTemplates() {
348
212
  if (!this.props.api.withResource)
349
213
  return;
350
- this.apiDestinedRestApi.integrationRequestTemplates = {
214
+ this.apiToEventBridgeTargetRestApi.integrationRequestTemplates = {
351
215
  'application/json': [
352
- 'Action=Publish',
353
- `TargetArn=$util.urlEncode('${this.apiDestinedRestApi.topic.topicArn}')`,
354
- 'Message=$util.urlEncode($input.body)',
355
- 'Version=2010-03-31',
356
- ].join('&'),
216
+ '#set($context.requestOverride.header.X-Amz-Target = "AWSEvents.PutEvents")',
217
+ '#set($context.requestOverride.header.Content-Type = "application/x-amz-json-1.1")',
218
+ "#set($inputRoot = $input.path('$'))",
219
+ `{
220
+ "Entries": [
221
+ {
222
+ "EventBusName": "${this.apiEvent.eventBus.eventBusName}",
223
+ "Source": "api-to-eventbridge-target",
224
+ "DetailType": "external-client-event",
225
+ "Detail": "$util.escapeJavaScript($input.json('$'))"
226
+ }
227
+ ]
228
+ }`,
229
+ ].join('\r'),
357
230
  };
358
231
  }
359
232
  /**
360
233
  * @summary Method to create api integration response
361
234
  * @protected
362
235
  */
363
- createApiDestinedIntegrationResponse() {
236
+ createApiToEventBridgeTargetIntegrationResponse() {
364
237
  if (!this.props.api.withResource)
365
238
  return;
366
- this.apiDestinedRestApi.integrationResponse = this.props.api.integrationResponse ?? {
239
+ this.apiToEventBridgeTargetRestApi.integrationResponse = this.props.api.integrationResponse ?? {
367
240
  ...{
368
241
  statusCode: '200',
369
242
  responseTemplates: {
@@ -376,10 +249,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
376
249
  * @summary Method to create api integration error response
377
250
  * @protected
378
251
  */
379
- createApiDestinedIntegrationErrorResponse() {
252
+ createApiToEventBridgeTargetIntegrationErrorResponse() {
380
253
  if (!this.props.api.withResource)
381
254
  return;
382
- this.apiDestinedRestApi.integrationErrorResponse = {
255
+ this.apiToEventBridgeTargetRestApi.integrationErrorResponse = {
383
256
  ...{
384
257
  selectionPattern: '^\\[Error\\].*',
385
258
  statusCode: '400',
@@ -402,22 +275,22 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
402
275
  * @summary Method to create api integration
403
276
  * @protected
404
277
  */
405
- createApiDestinedIntegration() {
278
+ createApiToEventBridgeTargetIntegration() {
406
279
  if (!this.props.api.withResource)
407
280
  return;
408
- this.apiDestinedRestApi.integration = new apig.Integration({
281
+ this.apiToEventBridgeTargetRestApi.integration = new apig.Integration({
409
282
  type: apig.IntegrationType.AWS,
410
283
  integrationHttpMethod: 'POST',
411
- uri: `arn:aws:apigateway:${this.props.region}:sns:path//`,
284
+ uri: `arn:aws:apigateway:${this.props.region}:events:path//`,
412
285
  options: {
413
286
  ...{
414
- credentialsRole: this.apiDestinedRestApi.topicRole,
415
- requestParameters: this.apiDestinedRestApi.integrationRequestParameters,
416
- requestTemplates: this.apiDestinedRestApi.integrationRequestTemplates,
287
+ credentialsRole: this.apiToEventBridgeTargetRestApi.role,
288
+ requestParameters: this.apiToEventBridgeTargetRestApi.integrationRequestParameters,
289
+ requestTemplates: this.apiToEventBridgeTargetRestApi.integrationRequestTemplates,
417
290
  passthroughBehavior: apig.PassthroughBehavior.NEVER,
418
291
  integrationResponses: [
419
- this.apiDestinedRestApi.integrationResponse,
420
- this.apiDestinedRestApi.integrationErrorResponse,
292
+ this.apiToEventBridgeTargetRestApi.integrationResponse,
293
+ this.apiToEventBridgeTargetRestApi.integrationErrorResponse,
421
294
  ],
422
295
  },
423
296
  ...this.props.api.integrationOptions,
@@ -428,10 +301,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
428
301
  * @summary Method to create api integration method response
429
302
  * @protected
430
303
  */
431
- createApiDestinedMethodResponse() {
304
+ createApiToEventBridgeTargetMethodResponse() {
432
305
  if (!this.props.api.withResource)
433
306
  return;
434
- this.apiDestinedRestApi.methodResponse = {
307
+ this.apiToEventBridgeTargetRestApi.methodResponse = {
435
308
  ...{
436
309
  statusCode: '200',
437
310
  responseParameters: {
@@ -440,7 +313,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
440
313
  'method.response.header.Access-Control-Allow-Credentials': true,
441
314
  },
442
315
  responseModels: {
443
- 'application/json': this.apiDestinedRestApi.responseModel,
316
+ 'application/json': this.apiToEventBridgeTargetRestApi.responseModel,
444
317
  },
445
318
  },
446
319
  ...this.props.api.methodResponse,
@@ -450,10 +323,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
450
323
  * @summary Method to create api integration method error response
451
324
  * @protected
452
325
  */
453
- createApiDestinedMethodErrorResponse() {
326
+ createApiToEventBridgeTargetMethodErrorResponse() {
454
327
  if (!this.props.api.withResource)
455
328
  return;
456
- this.apiDestinedRestApi.methodErrorResponse = {
329
+ this.apiToEventBridgeTargetRestApi.methodErrorResponse = {
457
330
  ...{
458
331
  statusCode: '400',
459
332
  responseParameters: {
@@ -462,7 +335,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
462
335
  'method.response.header.Access-Control-Allow-Credentials': true,
463
336
  },
464
337
  responseModels: {
465
- 'application/json': this.apiDestinedRestApi.errorResponseModel,
338
+ 'application/json': this.apiToEventBridgeTargetRestApi.errorResponseModel,
466
339
  },
467
340
  },
468
341
  ...this.props.api.methodErrorResponse,
@@ -472,23 +345,28 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
472
345
  * @summary Method to create rest restApi for Api
473
346
  * @protected
474
347
  */
475
- createApiDestinedRestApi() {
348
+ createApiToEventBridgeTargetRestApi() {
476
349
  if (this.props.api.useExisting && this.props.api.importedRestApiRef) {
477
- this.apiDestinedRestApi.api = apig.RestApi.fromRestApiId(this, `${this.id}-sns-rest-api`, cdk.Fn.importValue(this.props.api.importedRestApiRef));
350
+ this.apiToEventBridgeTargetRestApi.api = apig.RestApi.fromRestApiId(this, `${this.id}-rest-api`, cdk.Fn.importValue(this.props.api.importedRestApiRef));
478
351
  return;
479
352
  }
480
- const accessLogGroup = this.logManager.createLogGroup(`${this.id}-sns-rest-api-access-log`, this, {
481
- logGroupName: `/custom/api/${this.id}-destined-rest-api-access-${this.props.stage}`,
353
+ const accessLogGroup = this.logManager.createLogGroup(`${this.id}-rest-api-access-log`, this, {
354
+ logGroupName: `/custom/api/${this.id}-rest-api-access`,
482
355
  removalPolicy: cdk.RemovalPolicy.DESTROY,
483
356
  });
484
- this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
357
+ this.apiToEventBridgeTargetRestApi.api = new apig.RestApi(this, `${this.id}-rest-api`, {
485
358
  ...{
486
- defaultIntegration: this.apiDestinedRestApi.integration,
359
+ cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
360
+ defaultIntegration: this.apiToEventBridgeTargetRestApi.integration,
487
361
  defaultMethodOptions: {
488
- methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
362
+ methodResponses: [
363
+ this.apiToEventBridgeTargetRestApi.methodResponse,
364
+ this.apiToEventBridgeTargetRestApi.methodErrorResponse,
365
+ ],
489
366
  },
490
367
  deployOptions: {
491
- dataTraceEnabled: true,
368
+ tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
369
+ dataTraceEnabled: this.props.api.restApi?.deployOptions?.dataTraceEnabled,
492
370
  description: `${this.id} - ${this.props.stage} stage`,
493
371
  loggingLevel: apig.MethodLoggingLevel.INFO,
494
372
  metricsEnabled: true,
@@ -504,22 +382,22 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
504
382
  allowMethods: ['POST'],
505
383
  allowHeaders: apig.Cors.DEFAULT_HEADERS,
506
384
  },
507
- restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
385
+ restApiName: `${this.id}-rest-api-${this.props.stage}`,
508
386
  },
509
- ...this.props.api,
387
+ ...this.props.api.restApi,
510
388
  });
511
- this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId);
512
- this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiDestinedRestApi.api.root.resourceId);
389
+ this.addCfnOutput(`${this.id}-restApiId`, this.apiToEventBridgeTargetRestApi.api.restApiId);
390
+ this.addCfnOutput(`${this.id}-restApiRootResourceId`, this.apiToEventBridgeTargetRestApi.api.root.resourceId);
513
391
  }
514
392
  /**
515
393
  * @summary Method to create api integration response model
516
394
  * @protected
517
395
  */
518
- createApiDestinedResponseModel() {
396
+ createApiToEventBridgeTargetResponseModel() {
519
397
  if (!this.props.api.withResource)
520
398
  return;
521
- this.apiDestinedRestApi.responseModel = new apig.Model(this, `${this.id}-response-model`, {
522
- restApi: this.apiDestinedRestApi.api,
399
+ this.apiToEventBridgeTargetRestApi.responseModel = new apig.Model(this, `${this.id}-response-model`, {
400
+ restApi: this.apiToEventBridgeTargetRestApi.api,
523
401
  ...{
524
402
  contentType: 'application/json',
525
403
  modelName: 'ResponseModel',
@@ -537,11 +415,11 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
537
415
  * @summary Method to create api integration error response model
538
416
  * @protected
539
417
  */
540
- createApiDestinedErrorResponseModel() {
418
+ createApiToEventBridgeTargetErrorResponseModel() {
541
419
  if (!this.props.api.withResource)
542
420
  return;
543
- this.apiDestinedRestApi.errorResponseModel = new apig.Model(this, `${this.id}-error-response-model`, {
544
- restApi: this.apiDestinedRestApi.api,
421
+ this.apiToEventBridgeTargetRestApi.errorResponseModel = new apig.Model(this, `${this.id}-error-response-model`, {
422
+ restApi: this.apiToEventBridgeTargetRestApi.api,
545
423
  ...{
546
424
  contentType: 'application/json',
547
425
  modelName: 'ErrorResponseModel',
@@ -562,32 +440,35 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
562
440
  * @summary Method to create api integration resource
563
441
  * @protected
564
442
  */
565
- createApiDestinedResource() {
443
+ createApiToEventBridgeTargetResource() {
566
444
  if (!this.props.api.withResource)
567
445
  return;
568
446
  let rootResource;
569
447
  if (this.props.api.withResource && this.props.api.importedRestApiRootResourceRef) {
570
448
  rootResource = apig.Resource.fromResourceAttributes(this, `${this.id}-root-resource`, {
571
449
  resourceId: cdk.Fn.importValue(this.props.api.importedRestApiRootResourceRef),
572
- restApi: this.apiDestinedRestApi.api,
450
+ restApi: this.apiToEventBridgeTargetRestApi.api,
573
451
  path: '/',
574
452
  });
575
453
  }
576
454
  else {
577
- rootResource = this.apiDestinedRestApi.api.root;
455
+ rootResource = this.apiToEventBridgeTargetRestApi.api.root;
578
456
  }
579
- this.apiDestinedRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource);
457
+ this.apiToEventBridgeTargetRestApi.resource = rootResource.addResource(this.props.api.resource ?? this.apiResource);
580
458
  }
581
459
  /**
582
460
  * @summary Method to create api integration resource method
583
461
  * @protected
584
462
  */
585
- createApiDestinedResourceMethod() {
463
+ createApiToEventBridgeTargetResourceMethod() {
586
464
  if (!this.props.api.withResource)
587
465
  return;
588
- this.apiDestinedRestApi.method = this.apiDestinedRestApi.resource.addMethod('POST', this.apiDestinedRestApi.integration, {
589
- authorizer: this.apiDestinedRestApi.authoriser,
590
- methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
466
+ this.apiToEventBridgeTargetRestApi.method = this.apiToEventBridgeTargetRestApi.resource.addMethod('POST', this.apiToEventBridgeTargetRestApi.integration, {
467
+ authorizer: this.apiToEventBridgeTargetRestApi.authoriser,
468
+ methodResponses: [
469
+ this.apiToEventBridgeTargetRestApi.methodResponse,
470
+ this.apiToEventBridgeTargetRestApi.methodErrorResponse,
471
+ ],
591
472
  });
592
473
  }
593
474
  /**
@@ -597,9 +478,9 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
597
478
  createApiDomain() {
598
479
  if (this.props.api.useExisting)
599
480
  return;
600
- this.apiDestinedRestApi.domain = this.apiManager.createApiDomain(`${this.id}-api-domain`, this, this.isProductionStage() || this.props.skipStageForARecords
481
+ this.apiToEventBridgeTargetRestApi.domain = this.apiManager.createApiDomain(`${this.id}-api-domain`, this, this.isProductionStage() || this.props.skipStageForARecords
601
482
  ? `${this.props.apiSubDomain}.${this.fullyQualifiedDomainName}`
602
- : `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`, this.apiDestinedRestApi.certificate);
483
+ : `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`, this.apiToEventBridgeTargetRestApi.certificate);
603
484
  }
604
485
  /**
605
486
  * @summary Method to create base path mappings for Api API
@@ -610,9 +491,9 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
610
491
  return;
611
492
  new apig.BasePathMapping(this, `${this.id}-base-bath-mapping`, {
612
493
  basePath: '',
613
- domainName: this.apiDestinedRestApi.domain,
614
- restApi: this.apiDestinedRestApi.api,
615
- stage: this.apiDestinedRestApi.api.deploymentStage,
494
+ domainName: this.apiToEventBridgeTargetRestApi.domain,
495
+ restApi: this.apiToEventBridgeTargetRestApi.api,
496
+ stage: this.apiToEventBridgeTargetRestApi.api.deploymentStage,
616
497
  });
617
498
  }
618
499
  /**
@@ -622,7 +503,7 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
622
503
  createApiRouteAssets() {
623
504
  if (this.props.api.useExisting)
624
505
  return;
625
- this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.apiDestinedRestApi.domain, this.apiDestinedRestApi.hostedZone, this.props.skipStageForARecords);
506
+ this.route53Manager.createApiGatewayARecord(`${this.id}-custom-domain-a-record`, this, this.props.apiSubDomain, this.apiToEventBridgeTargetRestApi.domain, this.apiToEventBridgeTargetRestApi.hostedZone, this.props.skipStageForARecords);
626
507
  }
627
508
  }
628
509
  exports.ApiToEventBridgeTarget = ApiToEventBridgeTarget;
@@ -6,7 +6,7 @@ import * as types from '../../types/aws';
6
6
  * @stability stable
7
7
  * @category cdk-utils.api-to-eventbridge-target
8
8
  * @subcategory member
9
- * @classdesc Provides a construct to contain lambda resources for ApiToEventBridgeTarget
9
+ * @classdesc Provides a construct to contain lambda resources for ApiToEventBridgeTargetWithSns
10
10
  */
11
11
  export declare class ApiDestinedLambda implements types.ApiDestinedLambdaType {
12
12
  destinationFailure: destinations.EventBridgeDestination;
@@ -5,7 +5,7 @@ exports.ApiDestinedLambda = void 0;
5
5
  * @stability stable
6
6
  * @category cdk-utils.api-to-eventbridge-target
7
7
  * @subcategory member
8
- * @classdesc Provides a construct to contain lambda resources for ApiToEventBridgeTarget
8
+ * @classdesc Provides a construct to contain lambda resources for ApiToEventBridgeTargetWithSns
9
9
  */
10
10
  class ApiDestinedLambda {
11
11
  destinationFailure;
@@ -0,0 +1,2 @@
1
+ export * from './api-destined-lambda';
2
+ export * from './main';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./api-destined-lambda"), exports);
18
+ __exportStar(require("./main"), exports);