@gradientedge/cdk-utils 8.122.0 → 8.123.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/dist/src/lib/aws/common/stack.js +5 -7
- package/dist/src/lib/aws/construct/api-to-any-target/main.js +24 -26
- package/dist/src/lib/aws/construct/api-to-eventbridge-target/main.js +85 -103
- package/dist/src/lib/aws/construct/api-to-eventbridge-target-with-sns/main.js +94 -120
- package/dist/src/lib/aws/construct/api-to-lambda-target/main.js +8 -10
- package/dist/src/lib/aws/construct/graphql-api-lambda/main.js +7 -3
- package/dist/src/lib/aws/construct/graphql-api-lambda-with-cache/main.js +5 -1
- package/dist/src/lib/aws/construct/lambda-with-iam-access/main.js +5 -1
- package/dist/src/lib/aws/construct/rest-api-lambda/main.js +7 -3
- package/dist/src/lib/aws/construct/rest-api-lambda-with-cache/main.js +5 -1
- package/dist/src/lib/aws/construct/site-with-ecs-backend/main.js +8 -6
- package/dist/src/lib/aws/construct/static-asset-deployment/main.js +5 -1
- package/dist/src/lib/aws/services/api-gateway/main.js +18 -10
- package/dist/src/lib/aws/services/cloudfront/main.js +11 -7
- package/dist/src/lib/aws/services/cloudwatch/logs.js +8 -4
- package/dist/src/lib/aws/services/cloudwatch/main.js +36 -78
- package/dist/src/lib/aws/services/dynamodb/main.js +6 -2
- package/dist/src/lib/aws/services/elastic-container-service/main.js +8 -4
- package/dist/src/lib/aws/services/elastic-file-system/main.js +5 -1
- package/dist/src/lib/aws/services/elasticache/main.js +6 -2
- package/dist/src/lib/aws/services/eventbridge/main.js +8 -4
- package/dist/src/lib/aws/services/lambda/main.js +7 -3
- package/dist/src/lib/aws/services/simple-notification-service/main.js +6 -2
- package/dist/src/lib/aws/services/simple-queue-service/main.js +6 -2
- package/dist/src/lib/aws/services/simple-storage-service/main.js +8 -4
- package/dist/src/lib/aws/services/step-function/main.js +52 -32
- package/dist/src/lib/aws/services/virtual-private-cloud/main.js +8 -4
- package/dist/src/lib/azure/common/stack.js +5 -7
- package/dist/src/lib/common/index.js +7 -3
- package/package.json +8 -8
- package/src/lib/aws/common/stack.ts +5 -7
- package/src/lib/aws/construct/api-to-any-target/main.ts +25 -27
- package/src/lib/aws/construct/api-to-eventbridge-target/main.ts +85 -103
- package/src/lib/aws/construct/api-to-eventbridge-target-with-sns/main.ts +94 -120
- package/src/lib/aws/construct/api-to-lambda-target/main.ts +8 -10
- package/src/lib/aws/construct/graphql-api-lambda/main.ts +4 -3
- package/src/lib/aws/construct/graphql-api-lambda-with-cache/main.ts +2 -1
- package/src/lib/aws/construct/lambda-with-iam-access/main.ts +2 -1
- package/src/lib/aws/construct/rest-api-lambda/main.ts +4 -3
- package/src/lib/aws/construct/rest-api-lambda-with-cache/main.ts +2 -1
- package/src/lib/aws/construct/site-with-ecs-backend/main.ts +8 -9
- package/src/lib/aws/construct/static-asset-deployment/main.ts +2 -1
- package/src/lib/aws/services/api-gateway/main.ts +9 -6
- package/src/lib/aws/services/cloudfront/main.ts +8 -7
- package/src/lib/aws/services/cloudwatch/logs.ts +6 -5
- package/src/lib/aws/services/cloudwatch/main.ts +35 -81
- package/src/lib/aws/services/dynamodb/main.ts +3 -2
- package/src/lib/aws/services/elastic-container-service/main.ts +5 -4
- package/src/lib/aws/services/elastic-file-system/main.ts +2 -1
- package/src/lib/aws/services/elasticache/main.ts +3 -2
- package/src/lib/aws/services/eventbridge/main.ts +5 -4
- package/src/lib/aws/services/lambda/main.ts +4 -3
- package/src/lib/aws/services/simple-notification-service/main.ts +3 -2
- package/src/lib/aws/services/simple-queue-service/main.ts +3 -2
- package/src/lib/aws/services/simple-storage-service/main.ts +5 -4
- package/src/lib/aws/services/step-function/main.ts +17 -16
- package/src/lib/aws/services/virtual-private-cloud/main.ts +5 -4
- package/src/lib/azure/common/stack.ts +7 -9
- package/src/lib/common/index.ts +5 -3
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.SfnManager = void 0;
|
|
4
7
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
5
8
|
const aws_stepfunctions_1 = require("aws-cdk-lib/aws-stepfunctions");
|
|
6
9
|
const aws_stepfunctions_tasks_1 = require("aws-cdk-lib/aws-stepfunctions-tasks");
|
|
10
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
7
11
|
const uuid_1 = require("uuid");
|
|
8
12
|
const utils_1 = require("../../utils");
|
|
9
13
|
const DEFAULT_RETRY_CONFIG = [
|
|
@@ -160,10 +164,12 @@ class SfnManager {
|
|
|
160
164
|
if (!retries || retries.length === 0) {
|
|
161
165
|
retries = DEFAULT_RETRY_CONFIG;
|
|
162
166
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
+
lodash_1.default.forEach(retries, retry => {
|
|
168
|
+
step.addRetry({
|
|
169
|
+
...retry,
|
|
170
|
+
...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
171
|
+
});
|
|
172
|
+
});
|
|
167
173
|
return step;
|
|
168
174
|
}
|
|
169
175
|
/**
|
|
@@ -202,10 +208,12 @@ class SfnManager {
|
|
|
202
208
|
if (!retries || retries.length === 0) {
|
|
203
209
|
retries = DEFAULT_RETRY_CONFIG;
|
|
204
210
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
211
|
+
lodash_1.default.forEach(retries, retry => {
|
|
212
|
+
step.addRetry({
|
|
213
|
+
...retry,
|
|
214
|
+
...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
215
|
+
});
|
|
216
|
+
});
|
|
209
217
|
return step;
|
|
210
218
|
}
|
|
211
219
|
/**
|
|
@@ -244,10 +252,12 @@ class SfnManager {
|
|
|
244
252
|
if (!retries || retries.length === 0) {
|
|
245
253
|
retries = DEFAULT_RETRY_CONFIG;
|
|
246
254
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
255
|
+
lodash_1.default.forEach(retries, retry => {
|
|
256
|
+
step.addRetry({
|
|
257
|
+
...retry,
|
|
258
|
+
...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
259
|
+
});
|
|
260
|
+
});
|
|
251
261
|
return step;
|
|
252
262
|
}
|
|
253
263
|
/**
|
|
@@ -284,10 +294,12 @@ class SfnManager {
|
|
|
284
294
|
if (!retries || retries.length === 0) {
|
|
285
295
|
retries = DEFAULT_RETRY_CONFIG;
|
|
286
296
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
297
|
+
lodash_1.default.forEach(retries, retry => {
|
|
298
|
+
step.addRetry({
|
|
299
|
+
...retry,
|
|
300
|
+
...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
301
|
+
});
|
|
302
|
+
});
|
|
291
303
|
return step;
|
|
292
304
|
}
|
|
293
305
|
/**
|
|
@@ -311,10 +323,12 @@ class SfnManager {
|
|
|
311
323
|
if (!retries || retries.length === 0) {
|
|
312
324
|
retries = DEFAULT_RETRY_CONFIG;
|
|
313
325
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
326
|
+
lodash_1.default.forEach(retries, retry => {
|
|
327
|
+
step.addRetry({
|
|
328
|
+
...retry,
|
|
329
|
+
...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
330
|
+
});
|
|
331
|
+
});
|
|
318
332
|
return step;
|
|
319
333
|
}
|
|
320
334
|
/**
|
|
@@ -341,10 +355,12 @@ class SfnManager {
|
|
|
341
355
|
if (!retries || retries.length === 0) {
|
|
342
356
|
retries = DEFAULT_RETRY_CONFIG;
|
|
343
357
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
358
|
+
lodash_1.default.forEach(retries, retry => {
|
|
359
|
+
step.addRetry({
|
|
360
|
+
...retry,
|
|
361
|
+
...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
362
|
+
});
|
|
363
|
+
});
|
|
348
364
|
return step;
|
|
349
365
|
}
|
|
350
366
|
/**
|
|
@@ -369,10 +385,12 @@ class SfnManager {
|
|
|
369
385
|
if (!retries || retries.length === 0) {
|
|
370
386
|
retries = DEFAULT_RETRY_CONFIG;
|
|
371
387
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
388
|
+
lodash_1.default.forEach(retries, retry => {
|
|
389
|
+
step.addRetry({
|
|
390
|
+
...retry,
|
|
391
|
+
...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
392
|
+
});
|
|
393
|
+
});
|
|
376
394
|
return step;
|
|
377
395
|
}
|
|
378
396
|
/**
|
|
@@ -394,10 +412,12 @@ class SfnManager {
|
|
|
394
412
|
if (!retries || retries.length === 0) {
|
|
395
413
|
retries = DEFAULT_RETRY_CONFIG;
|
|
396
414
|
}
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
415
|
+
lodash_1.default.forEach(retries, retry => {
|
|
416
|
+
step.addRetry({
|
|
417
|
+
...retry,
|
|
418
|
+
...{ interval: retry.intervalInSecs ? aws_cdk_lib_1.Duration.seconds(retry.intervalInSecs) : retry.interval },
|
|
419
|
+
});
|
|
420
|
+
});
|
|
401
421
|
return step;
|
|
402
422
|
}
|
|
403
423
|
/**
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.VpcManager = void 0;
|
|
4
7
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
5
8
|
const aws_ec2_1 = require("aws-cdk-lib/aws-ec2");
|
|
6
9
|
const utils_1 = require("../../utils");
|
|
10
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
7
11
|
/**
|
|
8
12
|
*/
|
|
9
13
|
const CommonVpcIdentifier = 'CommonVpc';
|
|
@@ -38,10 +42,10 @@ class VpcManager {
|
|
|
38
42
|
maxAzs: props.maxAzs,
|
|
39
43
|
});
|
|
40
44
|
(0, utils_1.createCfnOutput)(`${id}Id`, scope, vpc.vpcId);
|
|
41
|
-
(0, utils_1.createCfnOutput)(`${id}PublicSubnetIds`, scope,
|
|
42
|
-
(0, utils_1.createCfnOutput)(`${id}PrivateSubnetIds`, scope,
|
|
43
|
-
(0, utils_1.createCfnOutput)(`${id}PublicSubnetRouteTableIds`, scope,
|
|
44
|
-
(0, utils_1.createCfnOutput)(`${id}PrivateSubnetRouteTableIds`, scope,
|
|
45
|
+
(0, utils_1.createCfnOutput)(`${id}PublicSubnetIds`, scope, lodash_1.default.map(vpc.publicSubnets, subnet => subnet.subnetId).toString());
|
|
46
|
+
(0, utils_1.createCfnOutput)(`${id}PrivateSubnetIds`, scope, lodash_1.default.map(vpc.privateSubnets, subnet => subnet.subnetId).toString());
|
|
47
|
+
(0, utils_1.createCfnOutput)(`${id}PublicSubnetRouteTableIds`, scope, lodash_1.default.map(vpc.publicSubnets, subnet => subnet.routeTable.routeTableId).toString());
|
|
48
|
+
(0, utils_1.createCfnOutput)(`${id}PrivateSubnetRouteTableIds`, scope, lodash_1.default.map(vpc.privateSubnets, subnet => subnet.routeTable.routeTableId).toString());
|
|
45
49
|
(0, utils_1.createCfnOutput)(`${id}AvailabilityZones`, scope, vpc.availabilityZones.toString());
|
|
46
50
|
(0, utils_1.createCfnOutput)(`${id}DefaultSecurityGroup`, scope, vpc.vpcDefaultSecurityGroup.toString());
|
|
47
51
|
return vpc;
|
|
@@ -8,6 +8,7 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const construct_1 = require("./construct");
|
|
9
9
|
const app_root_path_1 = __importDefault(require("app-root-path"));
|
|
10
10
|
const cdktf_1 = require("cdktf");
|
|
11
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
11
12
|
const common_1 = require("../../common");
|
|
12
13
|
/**
|
|
13
14
|
* @classdesc Common stack to use as a base for all higher level constructs.
|
|
@@ -64,7 +65,7 @@ class CommonAzureStack extends cdktf_1.TerraformStack {
|
|
|
64
65
|
console.debug(`No additional contexts provided. Using default context properties from cdktf.json`);
|
|
65
66
|
return;
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
+
lodash_1.default.forEach(extraContexts, (context) => {
|
|
68
69
|
const extraContextPath = `${app_root_path_1.default.path}/${context}`;
|
|
69
70
|
/* scenario where extra context is configured in cdk.json but absent in file system */
|
|
70
71
|
if (!fs_1.default.existsSync(extraContextPath))
|
|
@@ -76,7 +77,7 @@ class CommonAzureStack extends cdktf_1.TerraformStack {
|
|
|
76
77
|
/* parse as JSON properties */
|
|
77
78
|
const extraContextProps = JSON.parse(extraContextPropsBuffer.toString('utf-8'));
|
|
78
79
|
/* set each of the property into the cdk node context */
|
|
79
|
-
|
|
80
|
+
lodash_1.default.keys(extraContextProps).forEach((propKey) => {
|
|
80
81
|
this.node.setContext(propKey, extraContextProps[propKey]);
|
|
81
82
|
});
|
|
82
83
|
});
|
|
@@ -110,13 +111,10 @@ class CommonAzureStack extends cdktf_1.TerraformStack {
|
|
|
110
111
|
/* parse as JSON properties */
|
|
111
112
|
const stageContextProps = JSON.parse(stageContextPropsBuffer.toString('utf-8'));
|
|
112
113
|
/* set each of the property into the cdk node context */
|
|
113
|
-
|
|
114
|
+
lodash_1.default.keys(stageContextProps).forEach((propKey) => {
|
|
114
115
|
/* handle object, array properties */
|
|
115
116
|
if (typeof stageContextProps[propKey] === 'object' && !Array.isArray(stageContextProps[propKey])) {
|
|
116
|
-
this.node.setContext(propKey,
|
|
117
|
-
...this.node.tryGetContext(propKey),
|
|
118
|
-
...stageContextProps[propKey],
|
|
119
|
-
});
|
|
117
|
+
this.node.setContext(propKey, lodash_1.default.merge(this.node.tryGetContext(propKey), stageContextProps[propKey]));
|
|
120
118
|
}
|
|
121
119
|
else {
|
|
122
120
|
/* handle all other primitive properties */
|
|
@@ -13,16 +13,20 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
16
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
20
|
exports.applyMixins = void 0;
|
|
21
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
18
22
|
__exportStar(require("./construct"), exports);
|
|
19
23
|
__exportStar(require("./stack"), exports);
|
|
20
24
|
__exportStar(require("./types"), exports);
|
|
21
25
|
__exportStar(require("./utils"), exports);
|
|
22
26
|
const applyMixins = (derivedCtor, constructors) => {
|
|
23
|
-
|
|
24
|
-
Object.getOwnPropertyNames(
|
|
25
|
-
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(
|
|
27
|
+
lodash_1.default.forEach(constructors, baseConstructor => {
|
|
28
|
+
Object.getOwnPropertyNames(baseConstructor.prototype).forEach(name => {
|
|
29
|
+
Object.defineProperty(derivedCtor.prototype, name, Object.getOwnPropertyDescriptor(baseConstructor.prototype, name) || Object.create(null));
|
|
26
30
|
});
|
|
27
31
|
});
|
|
28
32
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.123.0",
|
|
4
4
|
"description": "Utilities for AWS CDK provisioning",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
|
50
|
-
"@aws-sdk/credential-providers": "^3.
|
|
51
|
-
"@aws-sdk/types": "^3.
|
|
52
|
-
"@cdktf/provider-azurerm": "^10.0.
|
|
53
|
-
"@types/lodash": "^4.14.
|
|
49
|
+
"@aws-sdk/client-secrets-manager": "^3.408.0",
|
|
50
|
+
"@aws-sdk/credential-providers": "^3.408.0",
|
|
51
|
+
"@aws-sdk/types": "^3.408.0",
|
|
52
|
+
"@cdktf/provider-azurerm": "^10.0.2",
|
|
53
|
+
"@types/lodash": "^4.14.198",
|
|
54
54
|
"@types/node": "^20.5.9",
|
|
55
55
|
"@types/uuid": "^9.0.3",
|
|
56
56
|
"app-root-path": "^3.1.0",
|
|
57
|
-
"aws-cdk-lib": "^2.
|
|
57
|
+
"aws-cdk-lib": "^2.95.0",
|
|
58
58
|
"cdktf": "^0.18.0",
|
|
59
59
|
"constructs": "^10.2.70",
|
|
60
60
|
"lodash": "^4.17.21",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@types/jest": "^29.5.4",
|
|
72
72
|
"@typescript-eslint/eslint-plugin": "^6.6.0",
|
|
73
73
|
"@typescript-eslint/parser": "^6.6.0",
|
|
74
|
-
"aws-cdk": "^2.
|
|
74
|
+
"aws-cdk": "^2.95.0",
|
|
75
75
|
"better-docs": "^2.7.2",
|
|
76
76
|
"codecov": "^3.8.3",
|
|
77
77
|
"commitizen": "^4.3.0",
|
|
@@ -5,6 +5,7 @@ import { CommonConstruct } from './construct'
|
|
|
5
5
|
import { CommonStackProps } from './types'
|
|
6
6
|
|
|
7
7
|
import appRoot from 'app-root-path'
|
|
8
|
+
import _ from 'lodash'
|
|
8
9
|
import { isDevStage } from '../../common'
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -75,7 +76,7 @@ export class CommonStack extends Stack {
|
|
|
75
76
|
return
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
_.forEach(extraContexts, (context: string) => {
|
|
79
80
|
const extraContextPath = `${appRoot.path}/${context}`
|
|
80
81
|
|
|
81
82
|
/* scenario where extra context is configured in cdk.json but absent in file system */
|
|
@@ -89,7 +90,7 @@ export class CommonStack extends Stack {
|
|
|
89
90
|
const extraContextProps = JSON.parse(extraContextPropsBuffer.toString('utf-8'))
|
|
90
91
|
|
|
91
92
|
/* set each of the property into the cdk node context */
|
|
92
|
-
|
|
93
|
+
_.keys(extraContextProps).forEach((propKey: any) => {
|
|
93
94
|
this.node.setContext(propKey, extraContextProps[propKey])
|
|
94
95
|
})
|
|
95
96
|
})
|
|
@@ -125,13 +126,10 @@ export class CommonStack extends Stack {
|
|
|
125
126
|
const stageContextProps = JSON.parse(stageContextPropsBuffer.toString('utf-8'))
|
|
126
127
|
|
|
127
128
|
/* set each of the property into the cdk node context */
|
|
128
|
-
|
|
129
|
+
_.keys(stageContextProps).forEach((propKey: any) => {
|
|
129
130
|
/* handle object, array properties */
|
|
130
131
|
if (typeof stageContextProps[propKey] === 'object' && !Array.isArray(stageContextProps[propKey])) {
|
|
131
|
-
this.node.setContext(propKey,
|
|
132
|
-
...this.node.tryGetContext(propKey),
|
|
133
|
-
...stageContextProps[propKey],
|
|
134
|
-
})
|
|
132
|
+
this.node.setContext(propKey, _.merge(this.node.tryGetContext(propKey), stageContextProps[propKey]))
|
|
135
133
|
} else {
|
|
136
134
|
/* handle all other primitive properties */
|
|
137
135
|
this.node.setContext(propKey, stageContextProps[propKey])
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
import { ISecret } from 'aws-cdk-lib/aws-secretsmanager'
|
|
13
13
|
import { Construct } from 'constructs'
|
|
14
14
|
import { CommonConstruct } from '../../common'
|
|
15
|
-
import { ApiToAnyTargetProps, ApiToAnyTargetRestApiResource, ApiToAnyTargetRestApiType } from './types'
|
|
16
15
|
import { ApiToAnyTargetRestApi } from './target'
|
|
16
|
+
import { ApiToAnyTargetProps, ApiToAnyTargetRestApiResource, ApiToAnyTargetRestApiType } from './types'
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @classdesc Provides a construct to create and deploy a shallow API Gateway
|
|
@@ -127,33 +127,31 @@ export class ApiToAnyTarget extends CommonConstruct {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
this.apiToAnyTargetRestApi.api = new RestApi(this, `${this.id}-rest-api`, {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
types: [this.isProductionStage() ? EndpointType.EDGE : EndpointType.REGIONAL],
|
|
154
|
-
},
|
|
155
|
-
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
130
|
+
cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
|
|
131
|
+
defaultCorsPreflightOptions: {
|
|
132
|
+
allowHeaders: Cors.DEFAULT_HEADERS,
|
|
133
|
+
allowMethods: Cors.ALL_METHODS,
|
|
134
|
+
allowOrigins: Cors.ALL_ORIGINS,
|
|
135
|
+
},
|
|
136
|
+
defaultIntegration: this.apiToAnyTargetRestApi.integration,
|
|
137
|
+
defaultMethodOptions: {
|
|
138
|
+
methodResponses: [this.apiToAnyTargetRestApi.methodResponse, this.apiToAnyTargetRestApi.methodErrorResponse],
|
|
139
|
+
},
|
|
140
|
+
deploy: this.props.api.restApi?.deploy ?? true,
|
|
141
|
+
deployOptions: {
|
|
142
|
+
accessLogDestination: new LogGroupLogDestination(this.apiToAnyTargetRestApi.accessLogGroup),
|
|
143
|
+
accessLogFormat: AccessLogFormat.jsonWithStandardFields(),
|
|
144
|
+
dataTraceEnabled: this.props.api.restApi?.deployOptions?.dataTraceEnabled,
|
|
145
|
+
description: `${this.id} - ${this.props.stage} stage`,
|
|
146
|
+
loggingLevel: MethodLoggingLevel.INFO,
|
|
147
|
+
metricsEnabled: true,
|
|
148
|
+
stageName: this.props.stage,
|
|
149
|
+
tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
|
|
150
|
+
},
|
|
151
|
+
endpointConfiguration: {
|
|
152
|
+
types: [this.isProductionStage() ? EndpointType.EDGE : EndpointType.REGIONAL],
|
|
156
153
|
},
|
|
154
|
+
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
157
155
|
...this.props.api.restApi,
|
|
158
156
|
})
|
|
159
157
|
this.addCfnOutput(`${this.id}-restApiId`, this.apiToAnyTargetRestApi.api.restApiId)
|
|
@@ -187,12 +187,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
187
187
|
protected createApiToEventBridgeTargetRule() {
|
|
188
188
|
if (this.props.api.useExisting) return
|
|
189
189
|
this.props.event.rule = {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
source: ['api-to-eventbridge-target'],
|
|
193
|
-
},
|
|
194
|
-
ruleName: `${this.id}-api-to-eventbridge-target`,
|
|
190
|
+
eventPattern: {
|
|
191
|
+
source: ['api-to-eventbridge-target'],
|
|
195
192
|
},
|
|
193
|
+
ruleName: `${this.id}-api-to-eventbridge-target`,
|
|
196
194
|
...this.props.event.rule,
|
|
197
195
|
}
|
|
198
196
|
this.apiEvent.rule = this.eventManager.createRule(
|
|
@@ -261,12 +259,10 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
261
259
|
protected createApiToEventBridgeTargetIntegrationResponse() {
|
|
262
260
|
if (!this.props.api.withResource) return
|
|
263
261
|
this.apiToEventBridgeTargetRestApi.integrationResponse = this.props.api.integrationResponse ?? {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
'application/json': JSON.stringify({ message: 'Payload Submitted' }),
|
|
267
|
-
},
|
|
268
|
-
statusCode: '200',
|
|
262
|
+
responseTemplates: {
|
|
263
|
+
'application/json': JSON.stringify({ message: 'Payload Submitted' }),
|
|
269
264
|
},
|
|
265
|
+
statusCode: '200',
|
|
270
266
|
}
|
|
271
267
|
}
|
|
272
268
|
|
|
@@ -276,21 +272,19 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
276
272
|
protected createApiToEventBridgeTargetIntegrationErrorResponse() {
|
|
277
273
|
if (!this.props.api.withResource) return
|
|
278
274
|
this.apiToEventBridgeTargetRestApi.integrationErrorResponse = {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
'method.response.header.Content-Type': "'application/json'",
|
|
284
|
-
},
|
|
285
|
-
responseTemplates: {
|
|
286
|
-
'application/json': JSON.stringify({
|
|
287
|
-
message: "$util.escapeJavaScript($input.path('$.errorMessage'))",
|
|
288
|
-
state: 'error',
|
|
289
|
-
}),
|
|
290
|
-
},
|
|
291
|
-
selectionPattern: '^\\[Error\\].*',
|
|
292
|
-
statusCode: '400',
|
|
275
|
+
responseParameters: {
|
|
276
|
+
'method.response.header.Access-Control-Allow-Credentials': "'true'",
|
|
277
|
+
'method.response.header.Access-Control-Allow-Origin': "'*'",
|
|
278
|
+
'method.response.header.Content-Type': "'application/json'",
|
|
293
279
|
},
|
|
280
|
+
responseTemplates: {
|
|
281
|
+
'application/json': JSON.stringify({
|
|
282
|
+
message: "$util.escapeJavaScript($input.path('$.errorMessage'))",
|
|
283
|
+
state: 'error',
|
|
284
|
+
}),
|
|
285
|
+
},
|
|
286
|
+
selectionPattern: '^\\[Error\\].*',
|
|
287
|
+
statusCode: '400',
|
|
294
288
|
...this.props.api.integrationErrorResponse,
|
|
295
289
|
}
|
|
296
290
|
}
|
|
@@ -303,16 +297,14 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
303
297
|
this.apiToEventBridgeTargetRestApi.integration = new Integration({
|
|
304
298
|
integrationHttpMethod: 'POST',
|
|
305
299
|
options: {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
requestTemplates: this.apiToEventBridgeTargetRestApi.integrationRequestTemplates,
|
|
315
|
-
},
|
|
300
|
+
credentialsRole: this.apiToEventBridgeTargetRestApi.role,
|
|
301
|
+
integrationResponses: [
|
|
302
|
+
this.apiToEventBridgeTargetRestApi.integrationResponse,
|
|
303
|
+
this.apiToEventBridgeTargetRestApi.integrationErrorResponse,
|
|
304
|
+
],
|
|
305
|
+
passthroughBehavior: PassthroughBehavior.NEVER,
|
|
306
|
+
requestParameters: this.apiToEventBridgeTargetRestApi.integrationRequestParameters,
|
|
307
|
+
requestTemplates: this.apiToEventBridgeTargetRestApi.integrationRequestTemplates,
|
|
316
308
|
...this.props.api.integrationOptions,
|
|
317
309
|
},
|
|
318
310
|
type: IntegrationType.AWS,
|
|
@@ -326,17 +318,15 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
326
318
|
protected createApiToEventBridgeTargetMethodResponse() {
|
|
327
319
|
if (!this.props.api.withResource) return
|
|
328
320
|
this.apiToEventBridgeTargetRestApi.methodResponse = {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
'application/json': this.apiToEventBridgeTargetRestApi.responseModel,
|
|
332
|
-
},
|
|
333
|
-
responseParameters: {
|
|
334
|
-
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
335
|
-
'method.response.header.Access-Control-Allow-Origin': true,
|
|
336
|
-
'method.response.header.Content-Type': true,
|
|
337
|
-
},
|
|
338
|
-
statusCode: '200',
|
|
321
|
+
responseModels: {
|
|
322
|
+
'application/json': this.apiToEventBridgeTargetRestApi.responseModel,
|
|
339
323
|
},
|
|
324
|
+
responseParameters: {
|
|
325
|
+
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
326
|
+
'method.response.header.Access-Control-Allow-Origin': true,
|
|
327
|
+
'method.response.header.Content-Type': true,
|
|
328
|
+
},
|
|
329
|
+
statusCode: '200',
|
|
340
330
|
...this.props.api.methodResponse,
|
|
341
331
|
}
|
|
342
332
|
}
|
|
@@ -347,17 +337,15 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
347
337
|
protected createApiToEventBridgeTargetMethodErrorResponse() {
|
|
348
338
|
if (!this.props.api.withResource) return
|
|
349
339
|
this.apiToEventBridgeTargetRestApi.methodErrorResponse = {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
'application/json': this.apiToEventBridgeTargetRestApi.errorResponseModel,
|
|
353
|
-
},
|
|
354
|
-
responseParameters: {
|
|
355
|
-
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
356
|
-
'method.response.header.Access-Control-Allow-Origin': true,
|
|
357
|
-
'method.response.header.Content-Type': true,
|
|
358
|
-
},
|
|
359
|
-
statusCode: '400',
|
|
340
|
+
responseModels: {
|
|
341
|
+
'application/json': this.apiToEventBridgeTargetRestApi.errorResponseModel,
|
|
360
342
|
},
|
|
343
|
+
responseParameters: {
|
|
344
|
+
'method.response.header.Access-Control-Allow-Credentials': true,
|
|
345
|
+
'method.response.header.Access-Control-Allow-Origin': true,
|
|
346
|
+
'method.response.header.Content-Type': true,
|
|
347
|
+
},
|
|
348
|
+
statusCode: '400',
|
|
361
349
|
...this.props.api.methodErrorResponse,
|
|
362
350
|
}
|
|
363
351
|
}
|
|
@@ -387,36 +375,34 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
387
375
|
}
|
|
388
376
|
|
|
389
377
|
this.apiToEventBridgeTargetRestApi.api = new RestApi(this, `${this.id}-rest-api`, {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
|
|
414
|
-
},
|
|
415
|
-
endpointConfiguration: {
|
|
416
|
-
types: [EndpointType.REGIONAL],
|
|
417
|
-
},
|
|
418
|
-
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
378
|
+
cloudWatchRole: this.props.api.restApi?.cloudWatchRole ?? true,
|
|
379
|
+
defaultCorsPreflightOptions: {
|
|
380
|
+
allowHeaders: Cors.DEFAULT_HEADERS,
|
|
381
|
+
allowMethods: ['POST'],
|
|
382
|
+
allowOrigins: Cors.ALL_ORIGINS,
|
|
383
|
+
},
|
|
384
|
+
defaultIntegration: this.apiToEventBridgeTargetRestApi.integration,
|
|
385
|
+
defaultMethodOptions: {
|
|
386
|
+
methodResponses: [
|
|
387
|
+
this.apiToEventBridgeTargetRestApi.methodResponse,
|
|
388
|
+
this.apiToEventBridgeTargetRestApi.methodErrorResponse,
|
|
389
|
+
],
|
|
390
|
+
},
|
|
391
|
+
deploy: this.props.api.restApi?.deploy ?? true,
|
|
392
|
+
deployOptions: {
|
|
393
|
+
accessLogDestination: new LogGroupLogDestination(this.apiToEventBridgeTargetRestApi.accessLogGroup),
|
|
394
|
+
accessLogFormat: AccessLogFormat.jsonWithStandardFields(),
|
|
395
|
+
dataTraceEnabled: this.props.api.restApi?.deployOptions?.dataTraceEnabled,
|
|
396
|
+
description: `${this.id} - ${this.props.stage} stage`,
|
|
397
|
+
loggingLevel: MethodLoggingLevel.INFO,
|
|
398
|
+
metricsEnabled: true,
|
|
399
|
+
stageName: this.props.stage,
|
|
400
|
+
tracingEnabled: this.props.api.restApi?.deployOptions?.tracingEnabled,
|
|
419
401
|
},
|
|
402
|
+
endpointConfiguration: {
|
|
403
|
+
types: [EndpointType.REGIONAL],
|
|
404
|
+
},
|
|
405
|
+
restApiName: `${this.id}-rest-api-${this.props.stage}`,
|
|
420
406
|
...this.props.api.restApi,
|
|
421
407
|
})
|
|
422
408
|
this.addCfnOutput(`${this.id}-restApiId`, this.apiToEventBridgeTargetRestApi.api.restApiId)
|
|
@@ -430,15 +416,13 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
430
416
|
if (!this.props.api.withResource) return
|
|
431
417
|
this.apiToEventBridgeTargetRestApi.responseModel = new Model(this, `${this.id}-response-model`, {
|
|
432
418
|
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
type: JsonSchemaType.OBJECT,
|
|
441
|
-
},
|
|
419
|
+
contentType: 'application/json',
|
|
420
|
+
modelName: 'ResponseModel',
|
|
421
|
+
schema: {
|
|
422
|
+
properties: { message: { type: JsonSchemaType.STRING } },
|
|
423
|
+
schema: JsonSchemaVersion.DRAFT4,
|
|
424
|
+
title: 'pollResponse',
|
|
425
|
+
type: JsonSchemaType.OBJECT,
|
|
442
426
|
},
|
|
443
427
|
...this.props.api.responseModel,
|
|
444
428
|
})
|
|
@@ -451,18 +435,16 @@ export class ApiToEventBridgeTarget extends CommonConstruct {
|
|
|
451
435
|
if (!this.props.api.withResource) return
|
|
452
436
|
this.apiToEventBridgeTargetRestApi.errorResponseModel = new Model(this, `${this.id}-error-response-model`, {
|
|
453
437
|
restApi: this.apiToEventBridgeTargetRestApi.api,
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
state: { type: JsonSchemaType.STRING },
|
|
461
|
-
},
|
|
462
|
-
schema: JsonSchemaVersion.DRAFT4,
|
|
463
|
-
title: 'errorResponse',
|
|
464
|
-
type: JsonSchemaType.OBJECT,
|
|
438
|
+
contentType: 'application/json',
|
|
439
|
+
modelName: 'ErrorResponseModel',
|
|
440
|
+
schema: {
|
|
441
|
+
properties: {
|
|
442
|
+
message: { type: JsonSchemaType.STRING },
|
|
443
|
+
state: { type: JsonSchemaType.STRING },
|
|
465
444
|
},
|
|
445
|
+
schema: JsonSchemaVersion.DRAFT4,
|
|
446
|
+
title: 'errorResponse',
|
|
447
|
+
type: JsonSchemaType.OBJECT,
|
|
466
448
|
},
|
|
467
449
|
...this.props.api.errorResponseModel,
|
|
468
450
|
})
|