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