@gradientedge/cdk-utils 4.6.7 → 4.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/api-destined-function/layers/nodejs/node_modules/.yarn-integrity +1 -1
- package/dist/src/lib/construct/api-to-eventbridge-target/main.d.ts +69 -5
- package/dist/src/lib/construct/api-to-eventbridge-target/main.js +163 -82
- package/dist/src/lib/construct/graphql-api-lambda-with-cache/main.d.ts +0 -1
- package/dist/src/lib/construct/graphql-api-lambda-with-cache/main.js +2 -3
- package/dist/src/lib/manager/aws/api-manager.d.ts +20 -0
- package/dist/src/lib/manager/aws/api-manager.js +51 -1
- 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 +6 -2
- package/package.json +2 -2
- package/src/lib/construct/api-to-eventbridge-target/main.ts +174 -99
- package/src/lib/construct/graphql-api-lambda-with-cache/main.ts +2 -3
- package/src/lib/manager/aws/api-manager.ts +65 -1
- package/src/lib/manager/aws/sns-manager.ts +2 -2
- package/src/lib/types/aws/index.ts +6 -2
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"glob@^7.1.3": "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023",
|
|
24
24
|
"inflight@^1.0.4": "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9",
|
|
25
25
|
"inherits@2": "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c",
|
|
26
|
-
"minimatch@^3.0.4": "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.
|
|
26
|
+
"minimatch@^3.0.4": "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b",
|
|
27
27
|
"mkdirp@^1.0.4": "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e",
|
|
28
28
|
"once@^1.3.0": "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1",
|
|
29
29
|
"path-is-absolute@^1.0.0": "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f",
|
|
@@ -80,36 +80,100 @@ export declare class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
80
80
|
* @protected
|
|
81
81
|
*/
|
|
82
82
|
protected createApiDestinedLambdaFunction(): void;
|
|
83
|
+
/**
|
|
84
|
+
* @summary Method to create or use an existing eventbus for api destined payload deliveries
|
|
85
|
+
* @protected
|
|
86
|
+
*/
|
|
83
87
|
protected createApiDestinedEventBus(): void;
|
|
88
|
+
/**
|
|
89
|
+
* @summary Method to create a log group for successful api destined payload deliveries
|
|
90
|
+
* @protected
|
|
91
|
+
*/
|
|
84
92
|
protected createApiDestinationLogGroupSuccess(): void;
|
|
85
93
|
/**
|
|
86
94
|
* Method to create EventBridge rule with lambda target for success
|
|
87
95
|
* @protected
|
|
88
96
|
*/
|
|
89
97
|
protected createApiDestinationRuleSuccess(): void;
|
|
98
|
+
/**
|
|
99
|
+
* @summary Method to create a log group for failed api destined payload deliveries
|
|
100
|
+
* @protected
|
|
101
|
+
*/
|
|
90
102
|
protected createApiDestinationLogGroupFailure(): void;
|
|
91
103
|
/**
|
|
92
104
|
* Method to create EventBridge rule with lambda target for failure
|
|
93
105
|
* @protected
|
|
94
106
|
*/
|
|
95
107
|
protected createApiDestinationRuleFailure(): void;
|
|
108
|
+
/**
|
|
109
|
+
* @summary Method to create a role for sns topic
|
|
110
|
+
* @protected
|
|
111
|
+
*/
|
|
96
112
|
protected createApiDestinedTopicRole(): void;
|
|
113
|
+
/**
|
|
114
|
+
* @summary Method to create API destined SNS topic
|
|
115
|
+
* @protected
|
|
116
|
+
*/
|
|
97
117
|
protected createApiDestinedTopic(): void;
|
|
98
118
|
/**
|
|
99
|
-
* @summary Method to create
|
|
119
|
+
* @summary Method to create api integration request parameters
|
|
100
120
|
* @protected
|
|
101
121
|
*/
|
|
102
|
-
protected createApiDestinedRestApi(): void;
|
|
103
|
-
protected createApiDestinedResponseModel(): void;
|
|
104
|
-
protected createApiDestinedErrorResponseModel(): void;
|
|
105
|
-
protected createApiDestinedResource(): void;
|
|
106
122
|
protected createApiDestinedIntegrationRequestParameters(): void;
|
|
123
|
+
/**
|
|
124
|
+
* @summary Method to create api integration request templates
|
|
125
|
+
* @protected
|
|
126
|
+
*/
|
|
107
127
|
protected createApiDestinedIntegrationRequestTemplates(): void;
|
|
128
|
+
/**
|
|
129
|
+
* @summary Method to create api integration response
|
|
130
|
+
* @protected
|
|
131
|
+
*/
|
|
108
132
|
protected createApiDestinedIntegrationResponse(): void;
|
|
133
|
+
/**
|
|
134
|
+
* @summary Method to create api integration error response
|
|
135
|
+
* @protected
|
|
136
|
+
*/
|
|
109
137
|
protected createApiDestinedIntegrationErrorResponse(): void;
|
|
138
|
+
/**
|
|
139
|
+
* @summary Method to create api integration
|
|
140
|
+
* @protected
|
|
141
|
+
*/
|
|
110
142
|
protected createApiDestinedIntegration(): void;
|
|
143
|
+
/**
|
|
144
|
+
* @summary Method to create api integration method response
|
|
145
|
+
* @protected
|
|
146
|
+
*/
|
|
111
147
|
protected createApiDestinedMethodResponse(): void;
|
|
148
|
+
/**
|
|
149
|
+
* @summary Method to create api integration method error response
|
|
150
|
+
* @protected
|
|
151
|
+
*/
|
|
112
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
|
+
*/
|
|
113
177
|
protected createApiDestinedResourceMethod(): void;
|
|
114
178
|
/**
|
|
115
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");
|
|
@@ -96,15 +96,15 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
96
96
|
/* restApi related resources */
|
|
97
97
|
this.createApiDestinedTopicRole();
|
|
98
98
|
this.createApiDestinedTopic();
|
|
99
|
-
this.createApiDestinedRestApi();
|
|
100
|
-
this.createApiDestinedResponseModel();
|
|
101
|
-
this.createApiDestinedErrorResponseModel();
|
|
102
|
-
this.createApiDestinedResource();
|
|
103
99
|
this.createApiDestinedIntegrationRequestParameters();
|
|
104
100
|
this.createApiDestinedIntegrationRequestTemplates();
|
|
105
101
|
this.createApiDestinedIntegrationResponse();
|
|
106
102
|
this.createApiDestinedIntegrationErrorResponse();
|
|
107
103
|
this.createApiDestinedIntegration();
|
|
104
|
+
this.createApiDestinedRestApi();
|
|
105
|
+
this.createApiDestinedResource();
|
|
106
|
+
this.createApiDestinedResponseModel();
|
|
107
|
+
this.createApiDestinedErrorResponseModel();
|
|
108
108
|
this.createApiDestinedMethodResponse();
|
|
109
109
|
this.createApiDestinedMethodErrorResponse();
|
|
110
110
|
this.createApiDestinedResourceMethod();
|
|
@@ -215,13 +215,23 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
215
215
|
},
|
|
216
216
|
}, this.apiDestinedLambda.role, this.apiDestinedLambda.layers, this.props.lambda.source, this.props.lambda.handler ?? 'lambda.handler', this.apiDestinedLambda.environment);
|
|
217
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* @summary Method to create or use an existing eventbus for api destined payload deliveries
|
|
220
|
+
* @protected
|
|
221
|
+
*/
|
|
218
222
|
createApiDestinedEventBus() {
|
|
219
|
-
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}`);
|
|
220
225
|
return;
|
|
226
|
+
}
|
|
221
227
|
this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-destined-event-bus`, this, {
|
|
222
228
|
eventBusName: `${this.props.event.eventBusName}`,
|
|
223
229
|
});
|
|
224
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* @summary Method to create a log group for successful api destined payload deliveries
|
|
233
|
+
* @protected
|
|
234
|
+
*/
|
|
225
235
|
createApiDestinationLogGroupSuccess() {
|
|
226
236
|
if (this.props.api.useExisting)
|
|
227
237
|
return;
|
|
@@ -258,6 +268,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
258
268
|
};
|
|
259
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)]);
|
|
260
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* @summary Method to create a log group for failed api destined payload deliveries
|
|
273
|
+
* @protected
|
|
274
|
+
*/
|
|
261
275
|
createApiDestinationLogGroupFailure() {
|
|
262
276
|
if (this.props.api.useExisting)
|
|
263
277
|
return;
|
|
@@ -290,97 +304,31 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
290
304
|
};
|
|
291
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)]);
|
|
292
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* @summary Method to create a role for sns topic
|
|
309
|
+
* @protected
|
|
310
|
+
*/
|
|
293
311
|
createApiDestinedTopicRole() {
|
|
294
|
-
if (this.props.api.useExisting)
|
|
295
|
-
return;
|
|
296
312
|
this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
|
|
297
313
|
assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
|
|
298
314
|
});
|
|
299
315
|
}
|
|
316
|
+
/**
|
|
317
|
+
* @summary Method to create API destined SNS topic
|
|
318
|
+
* @protected
|
|
319
|
+
*/
|
|
300
320
|
createApiDestinedTopic() {
|
|
301
|
-
if (this.props.api.
|
|
302
|
-
this.apiDestinedRestApi.topic = sns.Topic.fromTopicArn(this, `${this.id}-destined-topic`, `arn:aws:sns:${this.props.region}:${cdk.Stack.of(this).account}:${this.id}-destined-topic-${this.props.stage}`);
|
|
321
|
+
if (!this.props.api.withResource)
|
|
303
322
|
return;
|
|
304
|
-
}
|
|
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
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
|
|
320
|
-
...{
|
|
321
|
-
deployOptions: {
|
|
322
|
-
dataTraceEnabled: true,
|
|
323
|
-
description: `${this.id} - ${this.props.stage} stage`,
|
|
324
|
-
loggingLevel: apig.MethodLoggingLevel.INFO,
|
|
325
|
-
metricsEnabled: true,
|
|
326
|
-
stageName: this.props.stage,
|
|
327
|
-
},
|
|
328
|
-
endpointConfiguration: {
|
|
329
|
-
types: [apig.EndpointType.REGIONAL],
|
|
330
|
-
},
|
|
331
|
-
defaultCorsPreflightOptions: {
|
|
332
|
-
allowOrigins: apig.Cors.ALL_ORIGINS,
|
|
333
|
-
allowMethods: ['POST'],
|
|
334
|
-
allowHeaders: apig.Cors.DEFAULT_HEADERS,
|
|
335
|
-
},
|
|
336
|
-
restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
|
|
337
|
-
},
|
|
338
|
-
...this.props.api,
|
|
339
|
-
});
|
|
340
|
-
this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId);
|
|
341
|
-
}
|
|
342
|
-
createApiDestinedResponseModel() {
|
|
343
|
-
if (this.props.api.useExisting)
|
|
344
|
-
return;
|
|
345
|
-
this.apiDestinedRestApi.responseModel = this.apiDestinedRestApi.api.addModel(`${this.id}-response-model`, {
|
|
346
|
-
...{
|
|
347
|
-
contentType: 'application/json',
|
|
348
|
-
modelName: 'ResponseModel',
|
|
349
|
-
schema: {
|
|
350
|
-
schema: apig.JsonSchemaVersion.DRAFT4,
|
|
351
|
-
title: 'pollResponse',
|
|
352
|
-
type: apig.JsonSchemaType.OBJECT,
|
|
353
|
-
properties: { message: { type: apig.JsonSchemaType.STRING } },
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
...this.props.api.responseModel,
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
createApiDestinedErrorResponseModel() {
|
|
360
|
-
if (this.props.api.useExisting)
|
|
361
|
-
return;
|
|
362
|
-
this.apiDestinedRestApi.errorResponseModel = this.apiDestinedRestApi.api.addModel(`${this.id}-error-response-model`, {
|
|
363
|
-
...{
|
|
364
|
-
contentType: 'application/json',
|
|
365
|
-
modelName: 'ErrorResponseModel',
|
|
366
|
-
schema: {
|
|
367
|
-
schema: apig.JsonSchemaVersion.DRAFT4,
|
|
368
|
-
title: 'errorResponse',
|
|
369
|
-
type: apig.JsonSchemaType.OBJECT,
|
|
370
|
-
properties: {
|
|
371
|
-
state: { type: apig.JsonSchemaType.STRING },
|
|
372
|
-
message: { type: apig.JsonSchemaType.STRING },
|
|
373
|
-
},
|
|
374
|
-
},
|
|
375
|
-
},
|
|
376
|
-
...this.props.api.errorResponseModel,
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
createApiDestinedResource() {
|
|
380
|
-
if (!this.props.api.withResource)
|
|
381
|
-
return;
|
|
382
|
-
this.apiDestinedRestApi.resource = this.apiDestinedRestApi.api.root.addResource(this.props.api.resource ?? this.apiResource);
|
|
383
|
-
}
|
|
384
332
|
createApiDestinedIntegrationRequestParameters() {
|
|
385
333
|
if (!this.props.api.withResource)
|
|
386
334
|
return;
|
|
@@ -388,6 +336,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
388
336
|
'integration.request.header.Content-Type': "'application/x-www-form-urlencoded'",
|
|
389
337
|
};
|
|
390
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* @summary Method to create api integration request templates
|
|
341
|
+
* @protected
|
|
342
|
+
*/
|
|
391
343
|
createApiDestinedIntegrationRequestTemplates() {
|
|
392
344
|
if (!this.props.api.withResource)
|
|
393
345
|
return;
|
|
@@ -400,6 +352,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
400
352
|
].join('&'),
|
|
401
353
|
};
|
|
402
354
|
}
|
|
355
|
+
/**
|
|
356
|
+
* @summary Method to create api integration response
|
|
357
|
+
* @protected
|
|
358
|
+
*/
|
|
403
359
|
createApiDestinedIntegrationResponse() {
|
|
404
360
|
if (!this.props.api.withResource)
|
|
405
361
|
return;
|
|
@@ -413,6 +369,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
413
369
|
...this.props.api.integrationResponse,
|
|
414
370
|
};
|
|
415
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* @summary Method to create api integration error response
|
|
374
|
+
* @protected
|
|
375
|
+
*/
|
|
416
376
|
createApiDestinedIntegrationErrorResponse() {
|
|
417
377
|
if (!this.props.api.withResource)
|
|
418
378
|
return;
|
|
@@ -435,6 +395,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
435
395
|
...this.props.api.integrationErrorResponse,
|
|
436
396
|
};
|
|
437
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* @summary Method to create api integration
|
|
400
|
+
* @protected
|
|
401
|
+
*/
|
|
438
402
|
createApiDestinedIntegration() {
|
|
439
403
|
if (!this.props.api.withResource)
|
|
440
404
|
return;
|
|
@@ -457,6 +421,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
457
421
|
},
|
|
458
422
|
});
|
|
459
423
|
}
|
|
424
|
+
/**
|
|
425
|
+
* @summary Method to create api integration method response
|
|
426
|
+
* @protected
|
|
427
|
+
*/
|
|
460
428
|
createApiDestinedMethodResponse() {
|
|
461
429
|
if (!this.props.api.withResource)
|
|
462
430
|
return;
|
|
@@ -475,6 +443,10 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
475
443
|
...this.props.api.methodResponse,
|
|
476
444
|
};
|
|
477
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* @summary Method to create api integration method error response
|
|
448
|
+
* @protected
|
|
449
|
+
*/
|
|
478
450
|
createApiDestinedMethodErrorResponse() {
|
|
479
451
|
if (!this.props.api.withResource)
|
|
480
452
|
return;
|
|
@@ -493,10 +465,119 @@ class ApiToEventBridgeTarget extends common_1.CommonConstruct {
|
|
|
493
465
|
...this.props.api.methodErrorResponse,
|
|
494
466
|
};
|
|
495
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
|
+
*/
|
|
496
576
|
createApiDestinedResourceMethod() {
|
|
497
577
|
if (!this.props.api.withResource)
|
|
498
578
|
return;
|
|
499
579
|
this.apiDestinedRestApi.method = this.apiDestinedRestApi.resource.addMethod('POST', this.apiDestinedRestApi.integration, {
|
|
580
|
+
authorizer: this.apiDestinedRestApi.authoriser,
|
|
500
581
|
methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
|
|
501
582
|
});
|
|
502
583
|
}
|
|
@@ -30,7 +30,6 @@ export declare class GraphQLApiLambdaWithCache extends GraphQLApiLambda {
|
|
|
30
30
|
graphQLVpc: ec2.IVpc;
|
|
31
31
|
graphQLElastiCache: elasticache.CfnCacheCluster;
|
|
32
32
|
graphQLSecurityGroup: ec2.ISecurityGroup;
|
|
33
|
-
securityGroupStackName: string;
|
|
34
33
|
securityGroupExportName: string;
|
|
35
34
|
vpcExportName: string;
|
|
36
35
|
constructor(parent: Construct, id: string, props: GraphQlApiLambdaWithCacheProps);
|
|
@@ -54,7 +54,6 @@ class GraphQLApiLambdaWithCache extends __1.GraphQLApiLambda {
|
|
|
54
54
|
graphQLVpc;
|
|
55
55
|
graphQLElastiCache;
|
|
56
56
|
graphQLSecurityGroup;
|
|
57
|
-
securityGroupStackName;
|
|
58
57
|
securityGroupExportName;
|
|
59
58
|
vpcExportName;
|
|
60
59
|
constructor(parent, id, props) {
|
|
@@ -73,8 +72,8 @@ class GraphQLApiLambdaWithCache extends __1.GraphQLApiLambda {
|
|
|
73
72
|
* @protected
|
|
74
73
|
*/
|
|
75
74
|
setVpc() {
|
|
76
|
-
if (this.props.
|
|
77
|
-
this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.
|
|
75
|
+
if (this.props.useExistingVpc) {
|
|
76
|
+
this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcName);
|
|
78
77
|
}
|
|
79
78
|
else {
|
|
80
79
|
this.graphQLVpc = this.vpcManager.createCommonVpc(this, this.props.graphQLVpc, this.props.graphQLVpc.vpcName);
|
|
@@ -40,4 +40,24 @@ export declare class ApiManager {
|
|
|
40
40
|
* @param certificate the certificate used for custom restApi domain
|
|
41
41
|
*/
|
|
42
42
|
createApiDomain(id: string, scope: common.CommonConstruct, domainName: string, certificate: acm.ICertificate): apig.DomainName;
|
|
43
|
+
/**
|
|
44
|
+
* @summary Method to create an API gateway resource
|
|
45
|
+
* @param {string} id
|
|
46
|
+
* @param {common.CommonConstruct} scope
|
|
47
|
+
* @param {apig.IResource} parent
|
|
48
|
+
* @param {string} path
|
|
49
|
+
* @param {apig.Integration} integration
|
|
50
|
+
* @param {boolean} addProxy
|
|
51
|
+
* @param {string[]?} allowedOrigins
|
|
52
|
+
* @param {string[]?} allowedMethods
|
|
53
|
+
* @param {string[]?} allowedHeaders
|
|
54
|
+
*/
|
|
55
|
+
createApiResource(id: string, scope: common.CommonConstruct, parent: apig.IResource, path: string, integration: apig.Integration, addProxy: boolean, allowedOrigins?: string[], allowedMethods?: string[], allowedHeaders?: string[]): apig.Resource;
|
|
56
|
+
/**
|
|
57
|
+
* @summary Method to create an api deployment
|
|
58
|
+
* @param {string} id
|
|
59
|
+
* @param {common.CommonConstruct} scope
|
|
60
|
+
* @param {apig.IRestApi} restApi
|
|
61
|
+
*/
|
|
62
|
+
createApiDeployment(id: string, scope: common.CommonConstruct, restApi: apig.IRestApi): void;
|
|
43
63
|
}
|
|
@@ -84,7 +84,7 @@ class ApiManager {
|
|
|
84
84
|
restApiName: `${props.restApiName}-${scope.props.stage}`,
|
|
85
85
|
handler: lambdaFunction,
|
|
86
86
|
defaultCorsPreflightOptions: props.defaultCorsPreflightOptions,
|
|
87
|
-
proxy: props.proxy
|
|
87
|
+
proxy: props.proxy ?? true,
|
|
88
88
|
});
|
|
89
89
|
utils.createCfnOutput(`${id}-restApiId`, scope, api.restApiId);
|
|
90
90
|
utils.createCfnOutput(`${id}-restApiName`, scope, api.restApiName);
|
|
@@ -107,5 +107,55 @@ class ApiManager {
|
|
|
107
107
|
utils.createCfnOutput(`${id}-customDomainName`, scope, apiDomain.domainName);
|
|
108
108
|
return apiDomain;
|
|
109
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* @summary Method to create an API gateway resource
|
|
112
|
+
* @param {string} id
|
|
113
|
+
* @param {common.CommonConstruct} scope
|
|
114
|
+
* @param {apig.IResource} parent
|
|
115
|
+
* @param {string} path
|
|
116
|
+
* @param {apig.Integration} integration
|
|
117
|
+
* @param {boolean} addProxy
|
|
118
|
+
* @param {string[]?} allowedOrigins
|
|
119
|
+
* @param {string[]?} allowedMethods
|
|
120
|
+
* @param {string[]?} allowedHeaders
|
|
121
|
+
*/
|
|
122
|
+
createApiResource(id, scope, parent, path, integration, addProxy, allowedOrigins, allowedMethods, allowedHeaders) {
|
|
123
|
+
const methods = allowedMethods ?? apig.Cors.ALL_METHODS;
|
|
124
|
+
const resource = parent.addResource(path, {
|
|
125
|
+
defaultCorsPreflightOptions: {
|
|
126
|
+
allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
|
|
127
|
+
allowMethods: [...methods, 'OPTIONS'],
|
|
128
|
+
allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
|
|
129
|
+
allowCredentials: true,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
methods.forEach(method => resource.addMethod(method, integration));
|
|
133
|
+
utils.createCfnOutput(`${id}-${path}ResourceId`, scope, resource.resourceId);
|
|
134
|
+
if (addProxy) {
|
|
135
|
+
const resourceProxy = resource.addResource(`{${path}+}`, {
|
|
136
|
+
defaultCorsPreflightOptions: {
|
|
137
|
+
allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
|
|
138
|
+
allowMethods: [...methods, 'OPTIONS'],
|
|
139
|
+
allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
|
|
140
|
+
allowCredentials: true,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
methods.forEach(method => resourceProxy.addMethod(method, integration));
|
|
144
|
+
utils.createCfnOutput(`${id}-${path}ProxyResourceId`, scope, resourceProxy.resourceId);
|
|
145
|
+
}
|
|
146
|
+
return resource;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @summary Method to create an api deployment
|
|
150
|
+
* @param {string} id
|
|
151
|
+
* @param {common.CommonConstruct} scope
|
|
152
|
+
* @param {apig.IRestApi} restApi
|
|
153
|
+
*/
|
|
154
|
+
createApiDeployment(id, scope, restApi) {
|
|
155
|
+
new apig.Deployment(scope, `${id}`, {
|
|
156
|
+
api: restApi,
|
|
157
|
+
retainDeployments: false,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
110
160
|
}
|
|
111
161
|
exports.ApiManager = ApiManager;
|
|
@@ -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)
|
|
@@ -152,7 +152,8 @@ export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
|
|
|
152
152
|
graphQLVpc: ec2.VpcProps;
|
|
153
153
|
graphQLElastiCache: ElastiCacheProps;
|
|
154
154
|
securityGroupExportName: string;
|
|
155
|
-
|
|
155
|
+
useExistingVpc: boolean;
|
|
156
|
+
vpcName?: string;
|
|
156
157
|
}
|
|
157
158
|
/**
|
|
158
159
|
* @category cdk-utils.api-to-eventbridge-target
|
|
@@ -171,6 +172,7 @@ export interface ApiDestinationEventType {
|
|
|
171
172
|
*/
|
|
172
173
|
export interface ApiDestinedRestApiType {
|
|
173
174
|
api: apig.IRestApi;
|
|
175
|
+
authoriser?: apig.IAuthorizer;
|
|
174
176
|
certificate: acm.ICertificate;
|
|
175
177
|
domain: apig.DomainName;
|
|
176
178
|
errorResponseModel: apig.Model;
|
|
@@ -200,7 +202,7 @@ export interface ApiDestinedLambdaType {
|
|
|
200
202
|
destinationFailure: destinations.EventBridgeDestination;
|
|
201
203
|
destinationSuccess: destinations.EventBridgeDestination;
|
|
202
204
|
environment: types.ApiDestinedLambdaEnvironment;
|
|
203
|
-
function: lambda.
|
|
205
|
+
function: lambda.IFunction;
|
|
204
206
|
layers: lambda.LayerVersion[];
|
|
205
207
|
layerSource?: lambda.AssetCode;
|
|
206
208
|
policy: iam.PolicyDocument;
|
|
@@ -222,6 +224,8 @@ export interface ApiToEventBridgeTargetRestApiProps {
|
|
|
222
224
|
errorResponseModel?: apig.ModelOptions;
|
|
223
225
|
responseModel?: apig.ModelOptions;
|
|
224
226
|
restApi?: apig.RestApiProps;
|
|
227
|
+
importedRestApiRef?: string;
|
|
228
|
+
importedRestApiRootResourceRef?: string;
|
|
225
229
|
useExisting: boolean;
|
|
226
230
|
withResource?: boolean;
|
|
227
231
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.9.0",
|
|
4
4
|
"description": "Utilities for AWS CDK provisioning",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"app-root-path": "^3.0.0",
|
|
51
51
|
"aws-cdk-lib": "^2.12.0",
|
|
52
52
|
"aws-sdk": "^2.1074.0",
|
|
53
|
-
"constructs": "^10.0.
|
|
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'
|
|
@@ -92,15 +92,15 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
92
92
|
/* restApi related resources */
|
|
93
93
|
this.createApiDestinedTopicRole()
|
|
94
94
|
this.createApiDestinedTopic()
|
|
95
|
-
this.createApiDestinedRestApi()
|
|
96
|
-
this.createApiDestinedResponseModel()
|
|
97
|
-
this.createApiDestinedErrorResponseModel()
|
|
98
|
-
this.createApiDestinedResource()
|
|
99
95
|
this.createApiDestinedIntegrationRequestParameters()
|
|
100
96
|
this.createApiDestinedIntegrationRequestTemplates()
|
|
101
97
|
this.createApiDestinedIntegrationResponse()
|
|
102
98
|
this.createApiDestinedIntegrationErrorResponse()
|
|
103
99
|
this.createApiDestinedIntegration()
|
|
100
|
+
this.createApiDestinedRestApi()
|
|
101
|
+
this.createApiDestinedResource()
|
|
102
|
+
this.createApiDestinedResponseModel()
|
|
103
|
+
this.createApiDestinedErrorResponseModel()
|
|
104
104
|
this.createApiDestinedMethodResponse()
|
|
105
105
|
this.createApiDestinedMethodErrorResponse()
|
|
106
106
|
this.createApiDestinedResourceMethod()
|
|
@@ -246,13 +246,28 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
246
246
|
)
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
/**
|
|
250
|
+
* @summary Method to create or use an existing eventbus for api destined payload deliveries
|
|
251
|
+
* @protected
|
|
252
|
+
*/
|
|
249
253
|
protected createApiDestinedEventBus() {
|
|
250
|
-
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
|
+
}
|
|
251
262
|
this.apiEvent.eventBus = this.eventManager.createEventBus(`${this.id}-destined-event-bus`, this, {
|
|
252
263
|
eventBusName: `${this.props.event.eventBusName}`,
|
|
253
264
|
})
|
|
254
265
|
}
|
|
255
266
|
|
|
267
|
+
/**
|
|
268
|
+
* @summary Method to create a log group for successful api destined payload deliveries
|
|
269
|
+
* @protected
|
|
270
|
+
*/
|
|
256
271
|
protected createApiDestinationLogGroupSuccess() {
|
|
257
272
|
if (this.props.api.useExisting) return
|
|
258
273
|
this.apiEvent.logGroupSuccess = this.logManager.createLogGroup(`${this.id}-destination-success-log`, this, {
|
|
@@ -295,6 +310,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
295
310
|
)
|
|
296
311
|
}
|
|
297
312
|
|
|
313
|
+
/**
|
|
314
|
+
* @summary Method to create a log group for failed api destined payload deliveries
|
|
315
|
+
* @protected
|
|
316
|
+
*/
|
|
298
317
|
protected createApiDestinationLogGroupFailure() {
|
|
299
318
|
if (this.props.api.useExisting) return
|
|
300
319
|
this.apiEvent.logGroupFailure = this.logManager.createLogGroup(`${this.id}-destination-failure-log`, this, {
|
|
@@ -333,22 +352,22 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
333
352
|
)
|
|
334
353
|
}
|
|
335
354
|
|
|
355
|
+
/**
|
|
356
|
+
* @summary Method to create a role for sns topic
|
|
357
|
+
* @protected
|
|
358
|
+
*/
|
|
336
359
|
protected createApiDestinedTopicRole() {
|
|
337
|
-
if (this.props.api.useExisting) return
|
|
338
360
|
this.apiDestinedRestApi.topicRole = new iam.Role(this, `${this.id}-sns-rest-api-role`, {
|
|
339
361
|
assumedBy: new iam.ServicePrincipal('apigateway.amazonaws.com'),
|
|
340
362
|
})
|
|
341
363
|
}
|
|
342
364
|
|
|
365
|
+
/**
|
|
366
|
+
* @summary Method to create API destined SNS topic
|
|
367
|
+
* @protected
|
|
368
|
+
*/
|
|
343
369
|
protected createApiDestinedTopic() {
|
|
344
|
-
if (this.props.api.
|
|
345
|
-
this.apiDestinedRestApi.topic = sns.Topic.fromTopicArn(
|
|
346
|
-
this,
|
|
347
|
-
`${this.id}-destined-topic`,
|
|
348
|
-
`arn:aws:sns:${this.props.region}:${cdk.Stack.of(this).account}:${this.id}-destined-topic-${this.props.stage}`
|
|
349
|
-
)
|
|
350
|
-
return
|
|
351
|
-
}
|
|
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,92 +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
|
-
return
|
|
376
|
-
}
|
|
377
|
-
this.apiDestinedRestApi.api = new apig.RestApi(this, `${this.id}-sns-rest-api`, {
|
|
378
|
-
...{
|
|
379
|
-
deployOptions: {
|
|
380
|
-
dataTraceEnabled: true,
|
|
381
|
-
description: `${this.id} - ${this.props.stage} stage`,
|
|
382
|
-
loggingLevel: apig.MethodLoggingLevel.INFO,
|
|
383
|
-
metricsEnabled: true,
|
|
384
|
-
stageName: this.props.stage,
|
|
385
|
-
},
|
|
386
|
-
endpointConfiguration: {
|
|
387
|
-
types: [apig.EndpointType.REGIONAL],
|
|
388
|
-
},
|
|
389
|
-
defaultCorsPreflightOptions: {
|
|
390
|
-
allowOrigins: apig.Cors.ALL_ORIGINS,
|
|
391
|
-
allowMethods: ['POST'],
|
|
392
|
-
allowHeaders: apig.Cors.DEFAULT_HEADERS,
|
|
393
|
-
},
|
|
394
|
-
restApiName: `${this.id}-destined-rest-api-${this.props.stage}`,
|
|
395
|
-
},
|
|
396
|
-
...this.props.api,
|
|
397
|
-
})
|
|
398
|
-
this.addCfnOutput(`${this.id}-restApiId`, this.apiDestinedRestApi.api.restApiId)
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
protected createApiDestinedResponseModel() {
|
|
402
|
-
if (this.props.api.useExisting) return
|
|
403
|
-
this.apiDestinedRestApi.responseModel = (this.apiDestinedRestApi.api as apig.RestApi).addModel(
|
|
404
|
-
`${this.id}-response-model`,
|
|
405
|
-
{
|
|
406
|
-
...{
|
|
407
|
-
contentType: 'application/json',
|
|
408
|
-
modelName: 'ResponseModel',
|
|
409
|
-
schema: {
|
|
410
|
-
schema: apig.JsonSchemaVersion.DRAFT4,
|
|
411
|
-
title: 'pollResponse',
|
|
412
|
-
type: apig.JsonSchemaType.OBJECT,
|
|
413
|
-
properties: { message: { type: apig.JsonSchemaType.STRING } },
|
|
414
|
-
},
|
|
415
|
-
},
|
|
416
|
-
...this.props.api.responseModel,
|
|
417
|
-
}
|
|
418
|
-
)
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
protected createApiDestinedErrorResponseModel() {
|
|
422
|
-
if (this.props.api.useExisting) return
|
|
423
|
-
this.apiDestinedRestApi.errorResponseModel = (this.apiDestinedRestApi.api as apig.RestApi).addModel(
|
|
424
|
-
`${this.id}-error-response-model`,
|
|
425
|
-
{
|
|
426
|
-
...{
|
|
427
|
-
contentType: 'application/json',
|
|
428
|
-
modelName: 'ErrorResponseModel',
|
|
429
|
-
schema: {
|
|
430
|
-
schema: apig.JsonSchemaVersion.DRAFT4,
|
|
431
|
-
title: 'errorResponse',
|
|
432
|
-
type: apig.JsonSchemaType.OBJECT,
|
|
433
|
-
properties: {
|
|
434
|
-
state: { type: apig.JsonSchemaType.STRING },
|
|
435
|
-
message: { type: apig.JsonSchemaType.STRING },
|
|
436
|
-
},
|
|
437
|
-
},
|
|
438
|
-
},
|
|
439
|
-
...this.props.api.errorResponseModel,
|
|
440
|
-
}
|
|
441
|
-
)
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
protected createApiDestinedResource() {
|
|
445
|
-
if (!this.props.api.withResource) return
|
|
446
|
-
this.apiDestinedRestApi.resource = this.apiDestinedRestApi.api.root.addResource(
|
|
447
|
-
this.props.api.resource ?? this.apiResource
|
|
448
|
-
)
|
|
449
|
-
}
|
|
450
|
-
|
|
451
387
|
protected createApiDestinedIntegrationRequestParameters() {
|
|
452
388
|
if (!this.props.api.withResource) return
|
|
453
389
|
this.apiDestinedRestApi.integrationRequestParameters = {
|
|
@@ -455,6 +391,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
455
391
|
}
|
|
456
392
|
}
|
|
457
393
|
|
|
394
|
+
/**
|
|
395
|
+
* @summary Method to create api integration request templates
|
|
396
|
+
* @protected
|
|
397
|
+
*/
|
|
458
398
|
protected createApiDestinedIntegrationRequestTemplates() {
|
|
459
399
|
if (!this.props.api.withResource) return
|
|
460
400
|
this.apiDestinedRestApi.integrationRequestTemplates = {
|
|
@@ -467,6 +407,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
467
407
|
}
|
|
468
408
|
}
|
|
469
409
|
|
|
410
|
+
/**
|
|
411
|
+
* @summary Method to create api integration response
|
|
412
|
+
* @protected
|
|
413
|
+
*/
|
|
470
414
|
protected createApiDestinedIntegrationResponse() {
|
|
471
415
|
if (!this.props.api.withResource) return
|
|
472
416
|
this.apiDestinedRestApi.integrationResponse = {
|
|
@@ -480,6 +424,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
480
424
|
}
|
|
481
425
|
}
|
|
482
426
|
|
|
427
|
+
/**
|
|
428
|
+
* @summary Method to create api integration error response
|
|
429
|
+
* @protected
|
|
430
|
+
*/
|
|
483
431
|
protected createApiDestinedIntegrationErrorResponse() {
|
|
484
432
|
if (!this.props.api.withResource) return
|
|
485
433
|
this.apiDestinedRestApi.integrationErrorResponse = {
|
|
@@ -502,6 +450,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
502
450
|
}
|
|
503
451
|
}
|
|
504
452
|
|
|
453
|
+
/**
|
|
454
|
+
* @summary Method to create api integration
|
|
455
|
+
* @protected
|
|
456
|
+
*/
|
|
505
457
|
protected createApiDestinedIntegration() {
|
|
506
458
|
if (!this.props.api.withResource) return
|
|
507
459
|
this.apiDestinedRestApi.integration = new apig.Integration({
|
|
@@ -524,6 +476,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
524
476
|
})
|
|
525
477
|
}
|
|
526
478
|
|
|
479
|
+
/**
|
|
480
|
+
* @summary Method to create api integration method response
|
|
481
|
+
* @protected
|
|
482
|
+
*/
|
|
527
483
|
protected createApiDestinedMethodResponse() {
|
|
528
484
|
if (!this.props.api.withResource) return
|
|
529
485
|
this.apiDestinedRestApi.methodResponse = {
|
|
@@ -542,6 +498,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
542
498
|
}
|
|
543
499
|
}
|
|
544
500
|
|
|
501
|
+
/**
|
|
502
|
+
* @summary Method to create api integration method error response
|
|
503
|
+
* @protected
|
|
504
|
+
*/
|
|
545
505
|
protected createApiDestinedMethodErrorResponse() {
|
|
546
506
|
if (!this.props.api.withResource) return
|
|
547
507
|
this.apiDestinedRestApi.methodErrorResponse = {
|
|
@@ -560,12 +520,127 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
560
520
|
}
|
|
561
521
|
}
|
|
562
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
|
+
*/
|
|
563
637
|
protected createApiDestinedResourceMethod() {
|
|
564
638
|
if (!this.props.api.withResource) return
|
|
565
639
|
this.apiDestinedRestApi.method = this.apiDestinedRestApi.resource.addMethod(
|
|
566
640
|
'POST',
|
|
567
641
|
this.apiDestinedRestApi.integration,
|
|
568
642
|
{
|
|
643
|
+
authorizer: this.apiDestinedRestApi.authoriser,
|
|
569
644
|
methodResponses: [this.apiDestinedRestApi.methodResponse, this.apiDestinedRestApi.methodErrorResponse],
|
|
570
645
|
}
|
|
571
646
|
)
|
|
@@ -37,7 +37,6 @@ export class GraphQLApiLambdaWithCache extends GraphQLApiLambda {
|
|
|
37
37
|
graphQLVpc: ec2.IVpc
|
|
38
38
|
graphQLElastiCache: elasticache.CfnCacheCluster
|
|
39
39
|
graphQLSecurityGroup: ec2.ISecurityGroup
|
|
40
|
-
securityGroupStackName: string
|
|
41
40
|
securityGroupExportName: string
|
|
42
41
|
vpcExportName: string
|
|
43
42
|
|
|
@@ -60,8 +59,8 @@ export class GraphQLApiLambdaWithCache extends GraphQLApiLambda {
|
|
|
60
59
|
* @protected
|
|
61
60
|
*/
|
|
62
61
|
protected setVpc() {
|
|
63
|
-
if (this.props.
|
|
64
|
-
this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.
|
|
62
|
+
if (this.props.useExistingVpc) {
|
|
63
|
+
this.graphQLVpc = this.vpcManager.retrieveCommonVpc(`${this.id}`, this, this.props.vpcName)
|
|
65
64
|
} else {
|
|
66
65
|
this.graphQLVpc = this.vpcManager.createCommonVpc(this, this.props.graphQLVpc, this.props.graphQLVpc.vpcName)
|
|
67
66
|
}
|
|
@@ -71,7 +71,7 @@ export class ApiManager {
|
|
|
71
71
|
restApiName: `${props.restApiName}-${scope.props.stage}`,
|
|
72
72
|
handler: lambdaFunction,
|
|
73
73
|
defaultCorsPreflightOptions: props.defaultCorsPreflightOptions,
|
|
74
|
-
proxy: props.proxy
|
|
74
|
+
proxy: props.proxy ?? true,
|
|
75
75
|
})
|
|
76
76
|
|
|
77
77
|
utils.createCfnOutput(`${id}-restApiId`, scope, api.restApiId)
|
|
@@ -99,4 +99,68 @@ export class ApiManager {
|
|
|
99
99
|
|
|
100
100
|
return apiDomain
|
|
101
101
|
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @summary Method to create an API gateway resource
|
|
105
|
+
* @param {string} id
|
|
106
|
+
* @param {common.CommonConstruct} scope
|
|
107
|
+
* @param {apig.IResource} parent
|
|
108
|
+
* @param {string} path
|
|
109
|
+
* @param {apig.Integration} integration
|
|
110
|
+
* @param {boolean} addProxy
|
|
111
|
+
* @param {string[]?} allowedOrigins
|
|
112
|
+
* @param {string[]?} allowedMethods
|
|
113
|
+
* @param {string[]?} allowedHeaders
|
|
114
|
+
*/
|
|
115
|
+
public createApiResource(
|
|
116
|
+
id: string,
|
|
117
|
+
scope: common.CommonConstruct,
|
|
118
|
+
parent: apig.IResource,
|
|
119
|
+
path: string,
|
|
120
|
+
integration: apig.Integration,
|
|
121
|
+
addProxy: boolean,
|
|
122
|
+
allowedOrigins?: string[],
|
|
123
|
+
allowedMethods?: string[],
|
|
124
|
+
allowedHeaders?: string[]
|
|
125
|
+
) {
|
|
126
|
+
const methods = allowedMethods ?? apig.Cors.ALL_METHODS
|
|
127
|
+
const resource = parent.addResource(path, {
|
|
128
|
+
defaultCorsPreflightOptions: {
|
|
129
|
+
allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
|
|
130
|
+
allowMethods: [...methods, 'OPTIONS'],
|
|
131
|
+
allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
|
|
132
|
+
allowCredentials: true,
|
|
133
|
+
},
|
|
134
|
+
})
|
|
135
|
+
methods.forEach(method => resource.addMethod(method, integration))
|
|
136
|
+
utils.createCfnOutput(`${id}-${path}ResourceId`, scope, resource.resourceId)
|
|
137
|
+
|
|
138
|
+
if (addProxy) {
|
|
139
|
+
const resourceProxy = resource.addResource(`{${path}+}`, {
|
|
140
|
+
defaultCorsPreflightOptions: {
|
|
141
|
+
allowOrigins: allowedOrigins ?? apig.Cors.ALL_ORIGINS,
|
|
142
|
+
allowMethods: [...methods, 'OPTIONS'],
|
|
143
|
+
allowHeaders: allowedHeaders ?? apig.Cors.DEFAULT_HEADERS,
|
|
144
|
+
allowCredentials: true,
|
|
145
|
+
},
|
|
146
|
+
})
|
|
147
|
+
methods.forEach(method => resourceProxy.addMethod(method, integration))
|
|
148
|
+
utils.createCfnOutput(`${id}-${path}ProxyResourceId`, scope, resourceProxy.resourceId)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return resource
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @summary Method to create an api deployment
|
|
156
|
+
* @param {string} id
|
|
157
|
+
* @param {common.CommonConstruct} scope
|
|
158
|
+
* @param {apig.IRestApi} restApi
|
|
159
|
+
*/
|
|
160
|
+
public createApiDeployment(id: string, scope: common.CommonConstruct, restApi: apig.IRestApi) {
|
|
161
|
+
new apig.Deployment(scope, `${id}`, {
|
|
162
|
+
api: restApi,
|
|
163
|
+
retainDeployments: false,
|
|
164
|
+
})
|
|
165
|
+
}
|
|
102
166
|
}
|
|
@@ -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
|
|
|
@@ -161,7 +161,8 @@ export interface GraphQlApiLambdaWithCacheProps extends GraphQlApiLambdaProps {
|
|
|
161
161
|
graphQLVpc: ec2.VpcProps
|
|
162
162
|
graphQLElastiCache: ElastiCacheProps
|
|
163
163
|
securityGroupExportName: string
|
|
164
|
-
|
|
164
|
+
useExistingVpc: boolean
|
|
165
|
+
vpcName?: string
|
|
165
166
|
}
|
|
166
167
|
|
|
167
168
|
/**
|
|
@@ -182,6 +183,7 @@ export interface ApiDestinationEventType {
|
|
|
182
183
|
*/
|
|
183
184
|
export interface ApiDestinedRestApiType {
|
|
184
185
|
api: apig.IRestApi
|
|
186
|
+
authoriser?: apig.IAuthorizer
|
|
185
187
|
certificate: acm.ICertificate
|
|
186
188
|
domain: apig.DomainName
|
|
187
189
|
errorResponseModel: apig.Model
|
|
@@ -208,7 +210,7 @@ export interface ApiDestinedLambdaType {
|
|
|
208
210
|
destinationFailure: destinations.EventBridgeDestination
|
|
209
211
|
destinationSuccess: destinations.EventBridgeDestination
|
|
210
212
|
environment: types.ApiDestinedLambdaEnvironment
|
|
211
|
-
function: lambda.
|
|
213
|
+
function: lambda.IFunction
|
|
212
214
|
layers: lambda.LayerVersion[]
|
|
213
215
|
layerSource?: lambda.AssetCode
|
|
214
216
|
policy: iam.PolicyDocument
|
|
@@ -231,6 +233,8 @@ export interface ApiToEventBridgeTargetRestApiProps {
|
|
|
231
233
|
errorResponseModel?: apig.ModelOptions
|
|
232
234
|
responseModel?: apig.ModelOptions
|
|
233
235
|
restApi?: apig.RestApiProps
|
|
236
|
+
importedRestApiRef?: string
|
|
237
|
+
importedRestApiRootResourceRef?: string
|
|
234
238
|
useExisting: boolean
|
|
235
239
|
withResource?: boolean
|
|
236
240
|
}
|