@gradientedge/cdk-utils 4.6.4 → 4.6.5
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.
|
@@ -20,10 +20,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
22
|
exports.ApiToEventBridgeTarget = void 0;
|
|
23
|
+
const cdk = __importStar(require("aws-cdk-lib"));
|
|
23
24
|
const apig = __importStar(require("aws-cdk-lib/aws-apigateway"));
|
|
24
25
|
const eventstargets = __importStar(require("aws-cdk-lib/aws-events-targets"));
|
|
25
26
|
const iam = __importStar(require("aws-cdk-lib/aws-iam"));
|
|
26
27
|
const destinations = __importStar(require("aws-cdk-lib/aws-lambda-destinations"));
|
|
28
|
+
const sns = __importStar(require("aws-cdk-lib/aws-sns"));
|
|
27
29
|
const common_1 = require("../../common");
|
|
28
30
|
const api_destination_event_1 = require("./api-destination-event");
|
|
29
31
|
const api_destined_lambda_1 = require("./api-destined-lambda");
|
|
@@ -131,6 +133,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
131
133
|
* @protected
|
|
132
134
|
*/
|
|
133
135
|
resolveCertificate() {
|
|
136
|
+
if (this.props.api.useExisting)
|
|
137
|
+
return;
|
|
134
138
|
if (this.props.api.certificate.useExistingCertificate &&
|
|
135
139
|
this.props.api.certificate.certificateSsmName &&
|
|
136
140
|
this.props.api.certificate.certificateRegion) {
|
|
@@ -143,6 +147,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
143
147
|
* @protected
|
|
144
148
|
*/
|
|
145
149
|
createApiDestinedLambdaPolicy() {
|
|
150
|
+
if (this.props.api.useExisting)
|
|
151
|
+
return;
|
|
146
152
|
this.apiDestinedLambda.policy = new iam.PolicyDocument({
|
|
147
153
|
statements: [this.iamManager.statementForReadSecrets(this), this.iamManager.statementForPutEvents()],
|
|
148
154
|
});
|
|
@@ -152,6 +158,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
152
158
|
* @protected
|
|
153
159
|
*/
|
|
154
160
|
createApiDestinedLambdaRole() {
|
|
161
|
+
if (this.props.api.useExisting)
|
|
162
|
+
return;
|
|
155
163
|
this.apiDestinedLambda.role = this.iamManager.createRoleForLambda(`${this.id}-lambda-destined-role`, this, this.apiDestinedLambda.policy);
|
|
156
164
|
}
|
|
157
165
|
/**
|
|
@@ -159,6 +167,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
159
167
|
* @protected
|
|
160
168
|
*/
|
|
161
169
|
createApiDestinedLambdaEnvironment() {
|
|
170
|
+
if (this.props.api.useExisting)
|
|
171
|
+
return;
|
|
162
172
|
this.apiDestinedLambda.environment = {
|
|
163
173
|
NODE_ENV: this.props.nodeEnv,
|
|
164
174
|
LOG_LEVEL: this.props.logLevel,
|
|
@@ -171,6 +181,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
171
181
|
* @protected
|
|
172
182
|
*/
|
|
173
183
|
createApiDestinedLambdaLayers() {
|
|
184
|
+
if (this.props.api.useExisting)
|
|
185
|
+
return;
|
|
174
186
|
const layers = [];
|
|
175
187
|
if (this.props.lambda.layerSource) {
|
|
176
188
|
layers.push(this.lambdaManager.createLambdaLayer(`${this.id}-lambda-destined-layer`, this, this.props.lambda.layerSource));
|
|
@@ -182,6 +194,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
182
194
|
* @protected
|
|
183
195
|
*/
|
|
184
196
|
createApiDestinedLambdaDestinations() {
|
|
197
|
+
if (this.props.api.useExisting)
|
|
198
|
+
return;
|
|
185
199
|
this.apiDestinedLambda.destinationSuccess = new destinations.EventBridgeDestination(this.apiEvent.eventBus);
|
|
186
200
|
this.apiDestinedLambda.destinationFailure = new destinations.EventBridgeDestination(this.apiEvent.eventBus);
|
|
187
201
|
}
|
|
@@ -190,6 +204,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
190
204
|
* @protected
|
|
191
205
|
*/
|
|
192
206
|
createApiDestinedLambdaFunction() {
|
|
207
|
+
if (this.props.api.useExisting)
|
|
208
|
+
return;
|
|
193
209
|
if (!this.props.lambda.source)
|
|
194
210
|
throw 'Api Destined Lambda props undefined';
|
|
195
211
|
this.apiDestinedLambda.function = this.lambdaManager.createLambdaFunction(`${this.id}-lambda-destined`, this, {
|
|
@@ -201,11 +217,15 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
201
217
|
}, this.apiDestinedLambda.role, this.apiDestinedLambda.layers, this.props.lambda.source, this.props.lambda.handler ?? 'lambda.handler', this.apiDestinedLambda.environment);
|
|
202
218
|
}
|
|
203
219
|
createApiDestinedEventBus() {
|
|
220
|
+
if (this.props.api.useExisting)
|
|
221
|
+
return;
|
|
204
222
|
this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-destined-event-bus`, this, {
|
|
205
223
|
eventBusName: `${this.props.event.eventBusName}`,
|
|
206
224
|
});
|
|
207
225
|
}
|
|
208
226
|
createApiDestinationLogGroupSuccess() {
|
|
227
|
+
if (this.props.api.useExisting)
|
|
228
|
+
return;
|
|
209
229
|
this.apiEvent.logGroupSuccess = this.logManager.createLogGroup(`${this.id}-destination-success-log`, this, {
|
|
210
230
|
...{
|
|
211
231
|
logGroupName: `/${this.id}/events/api-destination-success`,
|
|
@@ -218,6 +238,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
218
238
|
* @protected
|
|
219
239
|
*/
|
|
220
240
|
createApiDestinationRuleSuccess() {
|
|
241
|
+
if (this.props.api.useExisting)
|
|
242
|
+
return;
|
|
221
243
|
this.props.event.ruleSuccess = {
|
|
222
244
|
...{
|
|
223
245
|
ruleName: `${this.id}-api-destination-success`,
|
|
@@ -238,6 +260,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
238
260
|
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)]);
|
|
239
261
|
}
|
|
240
262
|
createApiDestinationLogGroupFailure() {
|
|
263
|
+
if (this.props.api.useExisting)
|
|
264
|
+
return;
|
|
241
265
|
this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
|
|
242
266
|
...{
|
|
243
267
|
logGroupName: `/${this.id}/events/api-destination-failure`,
|
|
@@ -250,6 +274,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
250
274
|
* @protected
|
|
251
275
|
*/
|
|
252
276
|
createApiDestinationRuleFailure() {
|
|
277
|
+
if (this.props.api.useExisting)
|
|
278
|
+
return;
|
|
253
279
|
this.props.event.ruleFailure = {
|
|
254
280
|
...{
|
|
255
281
|
ruleName: `${this.id}-api-destination-failure`,
|
|
@@ -266,11 +292,16 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
266
292
|
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)]);
|
|
267
293
|
}
|
|
268
294
|
createApiDestinedTopicRole() {
|
|
295
|
+
if (this.props.api.useExisting)
|
|
296
|
+
return;
|
|
269
297
|
this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
|
|
270
298
|
assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
|
|
271
299
|
});
|
|
272
300
|
}
|
|
273
301
|
createApiDestinedTopic() {
|
|
302
|
+
if (this.props.api.useExisting) {
|
|
303
|
+
this.apiDestinedRestApi.topic = sns.Topic.fromTopicArn(this, `${this.id}-destined-topic`, `arn:aws:sns:${this.props.region}:${cdk.Stack.of(this).account}:${this.id}-destined-topic-${this.props.stage}`);
|
|
304
|
+
}
|
|
274
305
|
this.apiDestinedRestApi.topic = this.snsManager.createLambdaNotificationService(`${this.id}-destined-topic`, this, {
|
|
275
306
|
topicName: `${this.id}-destined-topic`,
|
|
276
307
|
}, this.apiDestinedLambda.function);
|
|
@@ -281,6 +312,9 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
281
312
|
* @protected
|
|
282
313
|
*/
|
|
283
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
|
+
}
|
|
284
318
|
this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
|
|
285
319
|
...{
|
|
286
320
|
deployOptions: {
|
|
@@ -302,8 +336,11 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
302
336
|
},
|
|
303
337
|
...this.props.api,
|
|
304
338
|
});
|
|
339
|
+
this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId);
|
|
305
340
|
}
|
|
306
341
|
createApiDestinedResponseModel() {
|
|
342
|
+
if (this.props.api.useExisting)
|
|
343
|
+
return;
|
|
307
344
|
this.apiDestinedRestApi.responseModel = this.apiDestinedRestApi.api.addModel(`${this.id}-response-model`, {
|
|
308
345
|
...{
|
|
309
346
|
contentType: 'application/json',
|
|
@@ -319,6 +356,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
319
356
|
});
|
|
320
357
|
}
|
|
321
358
|
createApiDestinedErrorResponseModel() {
|
|
359
|
+
if (this.props.api.useExisting)
|
|
360
|
+
return;
|
|
322
361
|
this.apiDestinedRestApi.errorResponseModel = this.apiDestinedRestApi.api.addModel(`${this.id}-error-response-model`, {
|
|
323
362
|
...{
|
|
324
363
|
contentType: 'application/json',
|
|
@@ -465,6 +504,8 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
465
504
|
* @protected
|
|
466
505
|
*/
|
|
467
506
|
createApiDomain() {
|
|
507
|
+
if (this.props.api.useExisting)
|
|
508
|
+
return;
|
|
468
509
|
this.apiDestinedRestApi.domain = this.apiManager.createApiDomain(`${this.id}-api-domain`, this, this.isProductionStage()
|
|
469
510
|
? `${this.props.apiSubDomain}.${this.fullyQualifiedDomainName}`
|
|
470
511
|
: `${this.props.apiSubDomain}-${this.props.stage}.${this.fullyQualifiedDomainName}`, this.apiDestinedRestApi.certificate);
|
|
@@ -170,7 +170,7 @@ export interface ApiDestinationEventType {
|
|
|
170
170
|
* @subcategory Types
|
|
171
171
|
*/
|
|
172
172
|
export interface ApiDestinedRestApiType {
|
|
173
|
-
api: apig.
|
|
173
|
+
api: apig.IRestApi;
|
|
174
174
|
certificate: acm.ICertificate;
|
|
175
175
|
domain: apig.DomainName;
|
|
176
176
|
errorResponseModel: apig.Model;
|
|
@@ -189,7 +189,7 @@ export interface ApiDestinedRestApiType {
|
|
|
189
189
|
methodResponse: apig.MethodResponse;
|
|
190
190
|
resource: apig.Resource;
|
|
191
191
|
responseModel: apig.Model;
|
|
192
|
-
topic: sns.
|
|
192
|
+
topic: sns.ITopic;
|
|
193
193
|
topicRole: iam.Role;
|
|
194
194
|
}
|
|
195
195
|
/**
|
|
@@ -212,7 +212,6 @@ export interface ApiDestinedLambdaType {
|
|
|
212
212
|
* @subcategory Properties
|
|
213
213
|
*/
|
|
214
214
|
export interface ApiToEventBridgeTargetRestApiProps {
|
|
215
|
-
withResource?: boolean;
|
|
216
215
|
certificate: AcmProps;
|
|
217
216
|
integrationResponse?: apig.IntegrationResponse;
|
|
218
217
|
integrationErrorResponse?: apig.IntegrationResponse;
|
|
@@ -223,6 +222,8 @@ export interface ApiToEventBridgeTargetRestApiProps {
|
|
|
223
222
|
errorResponseModel?: apig.ModelOptions;
|
|
224
223
|
responseModel?: apig.ModelOptions;
|
|
225
224
|
restApi?: apig.RestApiProps;
|
|
225
|
+
useExisting: boolean;
|
|
226
|
+
withResource?: boolean;
|
|
226
227
|
}
|
|
227
228
|
/**
|
|
228
229
|
* @category cdk-utils.api-to-eventbridge-target
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import * as cdk from 'aws-cdk-lib'
|
|
1
2
|
import * as apig from 'aws-cdk-lib/aws-apigateway'
|
|
2
3
|
import * as eventstargets from 'aws-cdk-lib/aws-events-targets'
|
|
3
4
|
import * as iam from 'aws-cdk-lib/aws-iam'
|
|
4
5
|
import * as lambda from 'aws-cdk-lib/aws-lambda'
|
|
5
6
|
import * as destinations from 'aws-cdk-lib/aws-lambda-destinations'
|
|
6
7
|
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager'
|
|
8
|
+
import * as sns from 'aws-cdk-lib/aws-sns'
|
|
7
9
|
import { Construct } from 'constructs'
|
|
8
10
|
import { CommonConstruct } from '../../common'
|
|
9
11
|
import * as types from '../../types'
|
|
@@ -134,6 +136,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
134
136
|
* @protected
|
|
135
137
|
*/
|
|
136
138
|
protected resolveCertificate() {
|
|
139
|
+
if (this.props.api.useExisting) return
|
|
137
140
|
if (
|
|
138
141
|
this.props.api.certificate.useExistingCertificate &&
|
|
139
142
|
this.props.api.certificate.certificateSsmName &&
|
|
@@ -159,6 +162,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
159
162
|
* @protected
|
|
160
163
|
*/
|
|
161
164
|
protected createApiDestinedLambdaPolicy() {
|
|
165
|
+
if (this.props.api.useExisting) return
|
|
162
166
|
this.apiDestinedLambda.policy = new iam.PolicyDocument({
|
|
163
167
|
statements: [this.iamManager.statementForReadSecrets(this), this.iamManager.statementForPutEvents()],
|
|
164
168
|
})
|
|
@@ -169,6 +173,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
169
173
|
* @protected
|
|
170
174
|
*/
|
|
171
175
|
protected createApiDestinedLambdaRole() {
|
|
176
|
+
if (this.props.api.useExisting) return
|
|
172
177
|
this.apiDestinedLambda.role = this.iamManager.createRoleForLambda(
|
|
173
178
|
`${this.id}-lambda-destined-role`,
|
|
174
179
|
this,
|
|
@@ -181,6 +186,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
181
186
|
* @protected
|
|
182
187
|
*/
|
|
183
188
|
protected createApiDestinedLambdaEnvironment() {
|
|
189
|
+
if (this.props.api.useExisting) return
|
|
184
190
|
this.apiDestinedLambda.environment = {
|
|
185
191
|
NODE_ENV: this.props.nodeEnv,
|
|
186
192
|
LOG_LEVEL: this.props.logLevel,
|
|
@@ -194,6 +200,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
194
200
|
* @protected
|
|
195
201
|
*/
|
|
196
202
|
protected createApiDestinedLambdaLayers() {
|
|
203
|
+
if (this.props.api.useExisting) return
|
|
197
204
|
const layers: lambda.LayerVersion[] = []
|
|
198
205
|
if (this.props.lambda.layerSource) {
|
|
199
206
|
layers.push(
|
|
@@ -209,6 +216,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
209
216
|
* @protected
|
|
210
217
|
*/
|
|
211
218
|
protected createApiDestinedLambdaDestinations() {
|
|
219
|
+
if (this.props.api.useExisting) return
|
|
212
220
|
this.apiDestinedLambda.destinationSuccess = new destinations.EventBridgeDestination(this.apiEvent.eventBus)
|
|
213
221
|
this.apiDestinedLambda.destinationFailure = new destinations.EventBridgeDestination(this.apiEvent.eventBus)
|
|
214
222
|
}
|
|
@@ -218,6 +226,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
218
226
|
* @protected
|
|
219
227
|
*/
|
|
220
228
|
protected createApiDestinedLambdaFunction() {
|
|
229
|
+
if (this.props.api.useExisting) return
|
|
221
230
|
if (!this.props.lambda.source) throw 'Api Destined Lambda props undefined'
|
|
222
231
|
|
|
223
232
|
this.apiDestinedLambda.function = this.lambdaManager.createLambdaFunction(
|
|
@@ -239,12 +248,14 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
239
248
|
}
|
|
240
249
|
|
|
241
250
|
protected createApiDestinedEventBus() {
|
|
251
|
+
if (this.props.api.useExisting) return
|
|
242
252
|
this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-destined-event-bus`, this, {
|
|
243
253
|
eventBusName: `${this.props.event.eventBusName}`,
|
|
244
254
|
})
|
|
245
255
|
}
|
|
246
256
|
|
|
247
257
|
protected createApiDestinationLogGroupSuccess() {
|
|
258
|
+
if (this.props.api.useExisting) return
|
|
248
259
|
this.apiEvent.logGroupSuccess = this.logManager.createLogGroup(`${this.id}-destination-success-log`, this, {
|
|
249
260
|
...{
|
|
250
261
|
logGroupName: `/${this.id}/events/api-destination-success`,
|
|
@@ -258,6 +269,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
258
269
|
* @protected
|
|
259
270
|
*/
|
|
260
271
|
protected createApiDestinationRuleSuccess() {
|
|
272
|
+
if (this.props.api.useExisting) return
|
|
261
273
|
this.props.event.ruleSuccess = {
|
|
262
274
|
...{
|
|
263
275
|
ruleName: `${this.id}-api-destination-success`,
|
|
@@ -285,6 +297,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
285
297
|
}
|
|
286
298
|
|
|
287
299
|
protected createApiDestinationLogGroupFailure() {
|
|
300
|
+
if (this.props.api.useExisting) return
|
|
288
301
|
this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
|
|
289
302
|
...{
|
|
290
303
|
logGroupName: `/${this.id}/events/api-destination-failure`,
|
|
@@ -298,6 +311,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
298
311
|
* @protected
|
|
299
312
|
*/
|
|
300
313
|
protected createApiDestinationRuleFailure() {
|
|
314
|
+
if (this.props.api.useExisting) return
|
|
301
315
|
this.props.event.ruleFailure = {
|
|
302
316
|
...{
|
|
303
317
|
ruleName: `${this.id}-api-destination-failure`,
|
|
@@ -321,12 +335,20 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
321
335
|
}
|
|
322
336
|
|
|
323
337
|
protected createApiDestinedTopicRole() {
|
|
338
|
+
if (this.props.api.useExisting) return
|
|
324
339
|
this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
|
|
325
340
|
assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
|
|
326
341
|
})
|
|
327
342
|
}
|
|
328
343
|
|
|
329
344
|
protected createApiDestinedTopic() {
|
|
345
|
+
if (this.props.api.useExisting) {
|
|
346
|
+
this.apiDestinedRestApi.topic = sns.Topic.fromTopicArn(
|
|
347
|
+
this,
|
|
348
|
+
`${this.id}-destined-topic`,
|
|
349
|
+
`arn:aws:sns:${this.props.region}:${cdk.Stack.of(this).account}:${this.id}-destined-topic-${this.props.stage}`
|
|
350
|
+
)
|
|
351
|
+
}
|
|
330
352
|
this.apiDestinedRestApi.topic = this.snsManager.createLambdaNotificationService(
|
|
331
353
|
`${this.id}-destined-topic`,
|
|
332
354
|
this,
|
|
@@ -344,6 +366,13 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
344
366
|
* @protected
|
|
345
367
|
*/
|
|
346
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
|
+
}
|
|
347
376
|
this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
|
|
348
377
|
...{
|
|
349
378
|
deployOptions: {
|
|
@@ -365,26 +394,32 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
365
394
|
},
|
|
366
395
|
...this.props.api,
|
|
367
396
|
})
|
|
397
|
+
this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId)
|
|
368
398
|
}
|
|
369
399
|
|
|
370
400
|
protected createApiDestinedResponseModel() {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
401
|
+
if (this.props.api.useExisting) return
|
|
402
|
+
this.apiDestinedRestApi.responseModel = (this.apiDestinedRestApi.api as apig.RestApi).addModel(
|
|
403
|
+
`${this.id}-response-model`,
|
|
404
|
+
{
|
|
405
|
+
...{
|
|
406
|
+
contentType: 'application/json',
|
|
407
|
+
modelName: 'ResponseModel',
|
|
408
|
+
schema: {
|
|
409
|
+
schema: apig.JsonSchemaVersion.DRAFT4,
|
|
410
|
+
title: 'pollResponse',
|
|
411
|
+
type: apig.JsonSchemaType.OBJECT,
|
|
412
|
+
properties: { message: { type: apig.JsonSchemaType.STRING } },
|
|
413
|
+
},
|
|
380
414
|
},
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
415
|
+
...this.props.api.responseModel,
|
|
416
|
+
}
|
|
417
|
+
)
|
|
384
418
|
}
|
|
385
419
|
|
|
386
420
|
protected createApiDestinedErrorResponseModel() {
|
|
387
|
-
|
|
421
|
+
if (this.props.api.useExisting) return
|
|
422
|
+
this.apiDestinedRestApi.errorResponseModel = (this.apiDestinedRestApi.api as apig.RestApi).addModel(
|
|
388
423
|
`${this.id}-error-response-model`,
|
|
389
424
|
{
|
|
390
425
|
...{
|
|
@@ -407,7 +442,6 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
407
442
|
|
|
408
443
|
protected createApiDestinedResource() {
|
|
409
444
|
if (!this.props.api.withResource) return
|
|
410
|
-
|
|
411
445
|
this.apiDestinedRestApi.resource = this.apiDestinedRestApi.api.root.addResource(
|
|
412
446
|
this.props.api.resource ?? this.apiResource
|
|
413
447
|
)
|
|
@@ -541,6 +575,7 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
541
575
|
* @protected
|
|
542
576
|
*/
|
|
543
577
|
protected createApiDomain() {
|
|
578
|
+
if (this.props.api.useExisting) return
|
|
544
579
|
this.apiDestinedRestApi.domain = this.apiManager.createApiDomain(
|
|
545
580
|
`${this.id}-api-domain`,
|
|
546
581
|
this,
|
|
@@ -181,7 +181,7 @@ export interface ApiDestinationEventType {
|
|
|
181
181
|
* @subcategory Types
|
|
182
182
|
*/
|
|
183
183
|
export interface ApiDestinedRestApiType {
|
|
184
|
-
api: apig.
|
|
184
|
+
api: apig.IRestApi
|
|
185
185
|
certificate: acm.ICertificate
|
|
186
186
|
domain: apig.DomainName
|
|
187
187
|
errorResponseModel: apig.Model
|
|
@@ -196,7 +196,7 @@ export interface ApiDestinedRestApiType {
|
|
|
196
196
|
methodResponse: apig.MethodResponse
|
|
197
197
|
resource: apig.Resource
|
|
198
198
|
responseModel: apig.Model
|
|
199
|
-
topic: sns.
|
|
199
|
+
topic: sns.ITopic
|
|
200
200
|
topicRole: iam.Role
|
|
201
201
|
}
|
|
202
202
|
|
|
@@ -221,7 +221,6 @@ export interface ApiDestinedLambdaType {
|
|
|
221
221
|
* @subcategory Properties
|
|
222
222
|
*/
|
|
223
223
|
export interface ApiToEventBridgeTargetRestApiProps {
|
|
224
|
-
withResource?: boolean
|
|
225
224
|
certificate: AcmProps
|
|
226
225
|
integrationResponse?: apig.IntegrationResponse
|
|
227
226
|
integrationErrorResponse?: apig.IntegrationResponse
|
|
@@ -232,6 +231,8 @@ export interface ApiToEventBridgeTargetRestApiProps {
|
|
|
232
231
|
errorResponseModel?: apig.ModelOptions
|
|
233
232
|
responseModel?: apig.ModelOptions
|
|
234
233
|
restApi?: apig.RestApiProps
|
|
234
|
+
useExisting: boolean
|
|
235
|
+
withResource?: boolean
|
|
235
236
|
}
|
|
236
237
|
|
|
237
238
|
/**
|