@digitraffic/common 2022.10.14-1 → 2022.10.28-2
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/{aws → dist/aws}/infra/api/integration.d.ts +0 -0
- package/dist/aws/infra/api/integration.js +52 -0
- package/dist/aws/infra/api/integration.js.map +1 -0
- package/{aws → dist/aws}/infra/api/response.d.ts +0 -0
- package/dist/aws/infra/api/response.js +61 -0
- package/dist/aws/infra/api/response.js.map +1 -0
- package/{aws → dist/aws}/infra/api/responses.d.ts +3 -3
- package/dist/aws/infra/api/responses.js +82 -0
- package/dist/aws/infra/api/responses.js.map +1 -0
- package/{aws → dist/aws}/infra/api/static-integration.d.ts +0 -0
- package/dist/aws/infra/api/static-integration.js +54 -0
- package/dist/aws/infra/api/static-integration.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/canary-alarm.d.ts +0 -0
- package/dist/aws/infra/canaries/canary-alarm.js +26 -0
- package/dist/aws/infra/canaries/canary-alarm.js.map +1 -0
- package/dist/aws/infra/canaries/canary-keys.d.ts +3 -0
- package/dist/aws/infra/canaries/canary-keys.js +7 -0
- package/dist/aws/infra/canaries/canary-keys.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/canary-parameters.d.ts +0 -0
- package/dist/aws/infra/canaries/canary-parameters.js +3 -0
- package/dist/aws/infra/canaries/canary-parameters.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/canary-role.d.ts +0 -0
- package/dist/aws/infra/canaries/canary-role.js +46 -0
- package/dist/aws/infra/canaries/canary-role.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/canary.d.ts +0 -0
- package/dist/aws/infra/canaries/canary.js +32 -0
- package/dist/aws/infra/canaries/canary.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/database-canary.d.ts +0 -0
- package/dist/aws/infra/canaries/database-canary.js +70 -0
- package/dist/aws/infra/canaries/database-canary.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/database-checker.d.ts +2 -2
- package/dist/aws/infra/canaries/database-checker.js +103 -0
- package/dist/aws/infra/canaries/database-checker.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/url-canary.d.ts +0 -3
- package/dist/aws/infra/canaries/url-canary.js +47 -0
- package/dist/aws/infra/canaries/url-canary.js.map +1 -0
- package/{aws → dist/aws}/infra/canaries/url-checker.d.ts +0 -0
- package/dist/aws/infra/canaries/url-checker.js +252 -0
- package/dist/aws/infra/canaries/url-checker.js.map +1 -0
- package/{aws → dist/aws}/infra/documentation.d.ts +0 -0
- package/dist/aws/infra/documentation.js +95 -0
- package/dist/aws/infra/documentation.js.map +1 -0
- package/{aws → dist/aws}/infra/scheduler.d.ts +7 -7
- package/dist/aws/infra/scheduler.js +31 -0
- package/dist/aws/infra/scheduler.js.map +1 -0
- package/{aws → dist/aws}/infra/security-rule.d.ts +0 -0
- package/dist/aws/infra/security-rule.js +39 -0
- package/dist/aws/infra/security-rule.js.map +1 -0
- package/{aws → dist/aws}/infra/sqs-integration.d.ts +0 -0
- package/dist/aws/infra/sqs-integration.js +93 -0
- package/dist/aws/infra/sqs-integration.js.map +1 -0
- package/{aws → dist/aws}/infra/sqs-queue.d.ts +0 -0
- package/dist/aws/infra/sqs-queue.js +130 -0
- package/dist/aws/infra/sqs-queue.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/lambda-configs.d.ts +5 -5
- package/dist/aws/infra/stack/lambda-configs.js +105 -0
- package/dist/aws/infra/stack/lambda-configs.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/monitoredfunction.d.ts +1 -1
- package/dist/aws/infra/stack/monitoredfunction.js +143 -0
- package/dist/aws/infra/stack/monitoredfunction.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/rest_apis.d.ts +0 -0
- package/dist/aws/infra/stack/rest_apis.js +185 -0
- package/dist/aws/infra/stack/rest_apis.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/stack-checking-aspect.d.ts +0 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js +174 -0
- package/dist/aws/infra/stack/stack-checking-aspect.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/stack.d.ts +5 -4
- package/dist/aws/infra/stack/stack.js +67 -0
- package/dist/aws/infra/stack/stack.js.map +1 -0
- package/{aws → dist/aws}/infra/stack/subscription.d.ts +3 -3
- package/dist/aws/infra/stack/subscription.js +42 -0
- package/dist/aws/infra/stack/subscription.js.map +1 -0
- package/{aws → dist/aws}/infra/usage-plans.d.ts +0 -0
- package/dist/aws/infra/usage-plans.js +42 -0
- package/dist/aws/infra/usage-plans.js.map +1 -0
- package/{aws → dist/aws}/runtime/apikey.d.ts +0 -0
- package/dist/aws/runtime/apikey.js +13 -0
- package/dist/aws/runtime/apikey.js.map +1 -0
- package/{aws → dist/aws}/runtime/digitraffic-integration-response.d.ts +0 -0
- package/dist/aws/runtime/digitraffic-integration-response.js +26 -0
- package/dist/aws/runtime/digitraffic-integration-response.js.map +1 -0
- package/dist/aws/runtime/environment.d.ts +1 -0
- package/dist/aws/runtime/environment.js +12 -0
- package/dist/aws/runtime/environment.js.map +1 -0
- package/{aws → dist/aws}/runtime/messaging.d.ts +0 -0
- package/dist/aws/runtime/messaging.js +31 -0
- package/dist/aws/runtime/messaging.js.map +1 -0
- package/{aws → dist/aws}/runtime/s3.d.ts +0 -0
- package/dist/aws/runtime/s3.js +30 -0
- package/dist/aws/runtime/s3.js.map +1 -0
- package/{aws → dist/aws}/runtime/secrets/dbsecret.d.ts +0 -0
- package/dist/aws/runtime/secrets/dbsecret.js +96 -0
- package/dist/aws/runtime/secrets/dbsecret.js.map +1 -0
- package/{aws → dist/aws}/runtime/secrets/proxy-holder.d.ts +0 -0
- package/dist/aws/runtime/secrets/proxy-holder.js +27 -0
- package/dist/aws/runtime/secrets/proxy-holder.js.map +1 -0
- package/{aws → dist/aws}/runtime/secrets/rds-holder.d.ts +0 -0
- package/dist/aws/runtime/secrets/rds-holder.js +27 -0
- package/dist/aws/runtime/secrets/rds-holder.js.map +1 -0
- package/{aws → dist/aws}/runtime/secrets/secret-holder.d.ts +0 -0
- package/dist/aws/runtime/secrets/secret-holder.js +76 -0
- package/dist/aws/runtime/secrets/secret-holder.js.map +1 -0
- package/{aws → dist/aws}/runtime/secrets/secret.d.ts +0 -0
- package/dist/aws/runtime/secrets/secret.js +43 -0
- package/dist/aws/runtime/secrets/secret.js.map +1 -0
- package/{aws → dist/aws}/types/errors.d.ts +4 -0
- package/dist/aws/types/errors.js +16 -0
- package/dist/aws/types/errors.js.map +1 -0
- package/{aws → dist/aws}/types/lambda-response.d.ts +4 -3
- package/dist/aws/types/lambda-response.js +33 -0
- package/dist/aws/types/lambda-response.js.map +1 -0
- package/{aws → dist/aws}/types/mediatypes.d.ts +1 -1
- package/dist/aws/types/mediatypes.js +16 -0
- package/dist/aws/types/mediatypes.js.map +1 -0
- package/{aws → dist/aws}/types/model-with-reference.d.ts +0 -0
- package/dist/aws/types/model-with-reference.js +3 -0
- package/dist/aws/types/model-with-reference.js.map +1 -0
- package/{aws → dist/aws}/types/proxytypes.d.ts +0 -0
- package/dist/aws/types/proxytypes.js +3 -0
- package/dist/aws/types/proxytypes.js.map +1 -0
- package/{aws → dist/aws}/types/tags.d.ts +0 -0
- package/dist/aws/types/tags.js +7 -0
- package/dist/aws/types/tags.js.map +1 -0
- package/{database → dist/database}/cached.d.ts +0 -0
- package/dist/database/cached.js +32 -0
- package/dist/database/cached.js.map +1 -0
- package/{database → dist/database}/database.d.ts +0 -0
- package/dist/database/database.js +70 -0
- package/dist/database/database.js.map +1 -0
- package/{database → dist/database}/last-updated.d.ts +0 -0
- package/dist/database/last-updated.js +54 -0
- package/dist/database/last-updated.js.map +1 -0
- package/dist/database/models.d.ts +6 -0
- package/dist/database/models.js +3 -0
- package/dist/database/models.js.map +1 -0
- package/{marine → dist/marine}/id_utils.d.ts +0 -0
- package/dist/marine/id_utils.js +33 -0
- package/dist/marine/id_utils.js.map +1 -0
- package/{marine → dist/marine}/rtz.d.ts +0 -0
- package/dist/marine/rtz.js +3 -0
- package/dist/marine/rtz.js.map +1 -0
- package/{test → dist/test}/asserter.d.ts +0 -0
- package/dist/test/asserter.js +45 -0
- package/dist/test/asserter.js.map +1 -0
- package/{test → dist/test}/db-testutils.d.ts +1 -1
- package/dist/test/db-testutils.js +31 -0
- package/dist/test/db-testutils.js.map +1 -0
- package/{test → dist/test}/httpserver.d.ts +2 -1
- package/dist/test/httpserver.js +74 -0
- package/dist/test/httpserver.js.map +1 -0
- package/{test → dist/test}/secret.d.ts +0 -0
- package/dist/test/secret.js +25 -0
- package/dist/test/secret.js.map +1 -0
- package/{test → dist/test}/secrets-manager.d.ts +0 -0
- package/dist/test/secrets-manager.js +59 -0
- package/dist/test/secrets-manager.js.map +1 -0
- package/{test → dist/test}/testutils.d.ts +0 -0
- package/dist/test/testutils.js +44 -0
- package/dist/test/testutils.js.map +1 -0
- package/dist/types/either.d.ts +9 -0
- package/dist/types/either.js +3 -0
- package/dist/types/either.js.map +1 -0
- package/{types → dist/types}/input-error.d.ts +0 -0
- package/dist/types/input-error.js +7 -0
- package/dist/types/input-error.js.map +1 -0
- package/{types → dist/types}/language.d.ts +0 -0
- package/dist/types/language.js +10 -0
- package/dist/types/language.js.map +1 -0
- package/{types → dist/types}/traffictype.d.ts +0 -0
- package/dist/types/traffictype.js +13 -0
- package/dist/types/traffictype.js.map +1 -0
- package/{types → dist/types}/validator.d.ts +0 -0
- package/dist/types/validator.js +14 -0
- package/dist/types/validator.js.map +1 -0
- package/{utils → dist/utils}/api-model.d.ts +0 -0
- package/dist/utils/api-model.js +129 -0
- package/dist/utils/api-model.js.map +1 -0
- package/{utils → dist/utils}/base64.d.ts +0 -0
- package/dist/utils/base64.js +21 -0
- package/dist/utils/base64.js.map +1 -0
- package/{utils → dist/utils}/date-utils.d.ts +0 -0
- package/dist/utils/date-utils.js +34 -0
- package/dist/utils/date-utils.js.map +1 -0
- package/{utils → dist/utils}/geojson-types.d.ts +0 -0
- package/dist/utils/geojson-types.js +18 -0
- package/dist/utils/geojson-types.js.map +1 -0
- package/{utils → dist/utils}/geometry.d.ts +0 -0
- package/dist/utils/geometry.js +164 -0
- package/dist/utils/geometry.js.map +1 -0
- package/{utils → dist/utils}/retry.d.ts +0 -0
- package/dist/utils/retry.js +50 -0
- package/dist/utils/retry.js.map +1 -0
- package/{utils → dist/utils}/slack.d.ts +0 -0
- package/dist/utils/slack.js +25 -0
- package/dist/utils/slack.js.map +1 -0
- package/{utils → dist/utils}/utils.d.ts +24 -0
- package/dist/utils/utils.js +75 -0
- package/dist/utils/utils.js.map +1 -0
- package/package.json +12 -10
- package/src/@types/geojson-validation/index.d.ts +4 -0
- package/src/aws/infra/api/integration.ts +73 -0
- package/src/aws/infra/api/response.ts +67 -0
- package/src/aws/infra/api/responses.ts +124 -0
- package/src/aws/infra/api/static-integration.ts +62 -0
- package/src/aws/infra/canaries/canary-alarm.ts +31 -0
- package/src/aws/infra/canaries/canary-keys.ts +3 -0
- package/src/aws/infra/canaries/canary-parameters.ts +19 -0
- package/src/aws/infra/canaries/canary-role.ts +47 -0
- package/src/aws/infra/canaries/canary.ts +46 -0
- package/src/aws/infra/canaries/database-canary.ts +98 -0
- package/src/aws/infra/canaries/database-checker.ts +155 -0
- package/src/aws/infra/canaries/url-canary.ts +74 -0
- package/src/aws/infra/canaries/url-checker.ts +366 -0
- package/src/aws/infra/documentation.ts +124 -0
- package/src/aws/infra/scheduler.ts +59 -0
- package/src/aws/infra/security-rule.ts +38 -0
- package/src/aws/infra/sqs-integration.ts +102 -0
- package/src/aws/infra/sqs-queue.ts +148 -0
- package/src/aws/infra/stack/lambda-configs.ts +207 -0
- package/src/aws/infra/stack/monitoredfunction.ts +342 -0
- package/src/aws/infra/stack/rest_apis.ts +223 -0
- package/src/aws/infra/stack/stack-checking-aspect.ts +279 -0
- package/src/aws/infra/stack/stack.ts +145 -0
- package/src/aws/infra/stack/subscription.ts +58 -0
- package/src/aws/infra/usage-plans.ts +41 -0
- package/src/aws/runtime/apikey.ts +9 -0
- package/src/aws/runtime/digitraffic-integration-response.ts +28 -0
- package/src/aws/runtime/environment.ts +9 -0
- package/src/aws/runtime/messaging.ts +26 -0
- package/src/aws/runtime/s3.ts +44 -0
- package/src/aws/runtime/secrets/dbsecret.ts +116 -0
- package/src/aws/runtime/secrets/proxy-holder.ts +37 -0
- package/src/aws/runtime/secrets/rds-holder.ts +33 -0
- package/src/aws/runtime/secrets/secret-holder.ts +116 -0
- package/src/aws/runtime/secrets/secret.ts +50 -0
- package/src/aws/types/errors.ts +14 -0
- package/src/aws/types/lambda-response.ts +43 -0
- package/src/aws/types/mediatypes.ts +11 -0
- package/src/aws/types/model-with-reference.ts +8 -0
- package/src/aws/types/proxytypes.ts +27 -0
- package/src/aws/types/tags.ts +3 -0
- package/src/database/cached.ts +35 -0
- package/src/database/database.ts +96 -0
- package/src/database/last-updated.ts +59 -0
- package/src/database/models.ts +7 -0
- package/src/marine/id_utils.ts +30 -0
- package/src/marine/rtz.ts +57 -0
- package/src/test/asserter.ts +48 -0
- package/src/test/db-testutils.ts +44 -0
- package/src/test/httpserver.ts +96 -0
- package/src/test/secret.ts +23 -0
- package/src/test/secrets-manager.ts +34 -0
- package/src/test/testutils.ts +39 -0
- package/src/types/either.ts +3 -0
- package/src/types/input-error.ts +2 -0
- package/src/types/language.ts +3 -0
- package/src/types/traffictype.ts +8 -0
- package/src/types/validator.ts +10 -0
- package/src/utils/api-model.ts +133 -0
- package/src/utils/base64.ts +16 -0
- package/src/utils/date-utils.ts +30 -0
- package/src/utils/geojson-types.ts +22 -0
- package/src/utils/geometry.ts +164 -0
- package/src/utils/retry.ts +49 -0
- package/src/utils/slack.ts +22 -0
- package/src/utils/utils.ts +105 -0
- package/aws/index.d.ts +0 -1
- package/aws/infra/api/index.d.ts +0 -1
- package/aws/infra/api/integration.js +0 -52
- package/aws/infra/api/response.js +0 -61
- package/aws/infra/api/responses.js +0 -79
- package/aws/infra/api/static-integration.js +0 -54
- package/aws/infra/canaries/canary-alarm.js +0 -26
- package/aws/infra/canaries/canary-parameters.js +0 -3
- package/aws/infra/canaries/canary-role.js +0 -46
- package/aws/infra/canaries/canary.js +0 -29
- package/aws/infra/canaries/database-canary.js +0 -55
- package/aws/infra/canaries/database-checker.js +0 -109
- package/aws/infra/canaries/url-canary.js +0 -46
- package/aws/infra/canaries/url-checker.js +0 -238
- package/aws/infra/documentation.js +0 -95
- package/aws/infra/scheduler.js +0 -31
- package/aws/infra/security-rule.js +0 -39
- package/aws/infra/sqs-integration.js +0 -93
- package/aws/infra/sqs-queue.js +0 -130
- package/aws/infra/stack/lambda-configs.js +0 -93
- package/aws/infra/stack/monitoredfunction.js +0 -135
- package/aws/infra/stack/rest_apis.js +0 -185
- package/aws/infra/stack/stack-checking-aspect.js +0 -174
- package/aws/infra/stack/stack.js +0 -60
- package/aws/infra/stack/subscription.js +0 -41
- package/aws/infra/usage-plans.js +0 -42
- package/aws/runtime/apikey.js +0 -13
- package/aws/runtime/digitraffic-integration-response.js +0 -26
- package/aws/runtime/messaging.js +0 -31
- package/aws/runtime/s3.js +0 -30
- package/aws/runtime/secrets/dbsecret.js +0 -96
- package/aws/runtime/secrets/proxy-holder.js +0 -26
- package/aws/runtime/secrets/rds-holder.js +0 -26
- package/aws/runtime/secrets/secret-holder.js +0 -73
- package/aws/runtime/secrets/secret.js +0 -43
- package/aws/types/errors.js +0 -9
- package/aws/types/lambda-response.js +0 -28
- package/aws/types/mediatypes.js +0 -15
- package/aws/types/model-with-reference.js +0 -3
- package/aws/types/proxytypes.js +0 -3
- package/aws/types/tags.js +0 -7
- package/database/cached.js +0 -32
- package/database/database.js +0 -62
- package/database/last-updated.js +0 -54
- package/index.d.ts +0 -1
- package/index.js +0 -18
- package/marine/id_utils.js +0 -33
- package/marine/rtz.js +0 -3
- package/test/asserter.js +0 -45
- package/test/db-testutils.js +0 -31
- package/test/httpserver.js +0 -67
- package/test/secret.js +0 -25
- package/test/secrets-manager.js +0 -59
- package/test/testutils.js +0 -44
- package/types/index.d.ts +0 -1
- package/types/input-error.js +0 -7
- package/types/language.js +0 -10
- package/types/traffictype.js +0 -13
- package/types/validator.js +0 -14
- package/utils/api-model.js +0 -129
- package/utils/base64.js +0 -21
- package/utils/date-utils.js +0 -34
- package/utils/geojson-types.js +0 -18
- package/utils/geometry.js +0 -140
- package/utils/retry.js +0 -50
- package/utils/slack.js +0 -25
- package/utils/utils.js +0 -40
- package/yarn-error.log +0 -103
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@digitraffic/common",
|
3
|
-
"version": "2022.10.
|
3
|
+
"version": "2022.10.28-2",
|
4
4
|
"description": "",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -10,23 +10,24 @@
|
|
10
10
|
"node": ">=14 <17",
|
11
11
|
"yarn": ">1.2 <2"
|
12
12
|
},
|
13
|
-
"publishConfig": {
|
14
|
-
"@tmfg:registry": "https://npm.pkg.github.com"
|
15
|
-
},
|
16
13
|
"scripts": {
|
17
14
|
"build": "tsc",
|
18
|
-
"lint": "eslint
|
15
|
+
"lint": "eslint --cache .",
|
16
|
+
"eslint-report": "eslint . --format html",
|
17
|
+
"clean": "rimraf dist output",
|
19
18
|
"test": "jest --detectOpenHandles --forceExit --coverage --coverageDirectory=output/coverage/jest",
|
20
|
-
"
|
19
|
+
"prepare": "husky install",
|
20
|
+
"prepublishOnly": "yarn clean && yarn build && yarn test"
|
21
21
|
},
|
22
|
-
"
|
23
|
-
"
|
22
|
+
"license": "EUPL-1.2",
|
23
|
+
"private": false,
|
24
24
|
"files": [
|
25
|
-
"
|
25
|
+
"dist/**/*.js",
|
26
|
+
"src/**/*.ts"
|
26
27
|
],
|
27
28
|
"dependencies": {
|
28
29
|
"@aws-cdk/aws-synthetics-alpha": "2.46.0-alpha.0",
|
29
|
-
"@types/geojson": "^7946.0.
|
30
|
+
"@types/geojson": "^7946.0.10",
|
30
31
|
"aws-cdk-lib": "2.46.0",
|
31
32
|
"aws-sdk": "2.1232.0",
|
32
33
|
"axios": "^0.21.1",
|
@@ -54,6 +55,7 @@
|
|
54
55
|
"lint-staged": ">=10",
|
55
56
|
"prettier": "^2.7.1",
|
56
57
|
"ramda": "^0.28.0",
|
58
|
+
"rimraf": "^3.0.2",
|
57
59
|
"sinon": "^14.0.0",
|
58
60
|
"ts-jest": "^29.0.2",
|
59
61
|
"typescript": "^4.8.4"
|
@@ -0,0 +1,73 @@
|
|
1
|
+
import {IntegrationResponse, LambdaIntegration, PassthroughBehavior} from "aws-cdk-lib/aws-apigateway";
|
2
|
+
import {IFunction} from "aws-cdk-lib/aws-lambda";
|
3
|
+
import {MediaType} from "../../types/mediatypes";
|
4
|
+
import {DigitrafficIntegrationResponse} from "../../runtime/digitraffic-integration-response";
|
5
|
+
|
6
|
+
type ParameterType = 'path' | 'querystring';
|
7
|
+
|
8
|
+
interface ApiParameter {
|
9
|
+
type: ParameterType
|
10
|
+
name: string
|
11
|
+
}
|
12
|
+
|
13
|
+
export class DigitrafficIntegration {
|
14
|
+
readonly lambda: IFunction;
|
15
|
+
readonly mediaType: MediaType;
|
16
|
+
|
17
|
+
readonly parameters: ApiParameter[] = [];
|
18
|
+
|
19
|
+
constructor(lambda: IFunction, mediaType = MediaType.TEXT_PLAIN) {
|
20
|
+
this.lambda = lambda;
|
21
|
+
this.mediaType = mediaType;
|
22
|
+
}
|
23
|
+
|
24
|
+
addPathParameter(...names: string[]): DigitrafficIntegration {
|
25
|
+
names.forEach(name => this.parameters.push({type: 'path', name}));
|
26
|
+
|
27
|
+
return this;
|
28
|
+
}
|
29
|
+
|
30
|
+
addQueryParameter(...names: string[]): DigitrafficIntegration {
|
31
|
+
names.forEach(name => this.parameters.push({type: 'querystring', name}));
|
32
|
+
|
33
|
+
return this;
|
34
|
+
}
|
35
|
+
|
36
|
+
build(): LambdaIntegration {
|
37
|
+
const integrationResponses = this.createResponses();
|
38
|
+
|
39
|
+
return new LambdaIntegration(this.lambda, {
|
40
|
+
proxy: false,
|
41
|
+
integrationResponses,
|
42
|
+
requestParameters: this.parameters.length == 0 ? undefined : this.createRequestParameters(),
|
43
|
+
requestTemplates: this.parameters.length == 0 ? undefined : this.createRequestTemplates(),
|
44
|
+
passthroughBehavior: PassthroughBehavior.WHEN_NO_MATCH,
|
45
|
+
});
|
46
|
+
}
|
47
|
+
|
48
|
+
createRequestParameters(): Record<string, string> {
|
49
|
+
const requestParameters: Record<string, string> = {};
|
50
|
+
|
51
|
+
this.parameters.forEach((parameter: ApiParameter) => {
|
52
|
+
requestParameters[`integration.request.${parameter.type}.${parameter.name}`] = `method.request.${parameter.type}.${parameter.name}`;
|
53
|
+
});
|
54
|
+
|
55
|
+
return requestParameters;
|
56
|
+
}
|
57
|
+
|
58
|
+
createRequestTemplates(): Record<string, string> {
|
59
|
+
const requestJson: Record<string, string> = {};
|
60
|
+
|
61
|
+
this.parameters.forEach((parameter: ApiParameter) => {
|
62
|
+
requestJson[parameter.name] = `$util.escapeJavaScript($input.params('${parameter.name}'))`;
|
63
|
+
});
|
64
|
+
|
65
|
+
return {
|
66
|
+
[MediaType.APPLICATION_JSON]: JSON.stringify(requestJson),
|
67
|
+
};
|
68
|
+
}
|
69
|
+
|
70
|
+
createResponses(): IntegrationResponse[] {
|
71
|
+
return [DigitrafficIntegrationResponse.ok(this.mediaType)];
|
72
|
+
}
|
73
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import apigateway = require('aws-cdk-lib/aws-apigateway');
|
2
|
+
import {MediaType} from "../../types/mediatypes";
|
3
|
+
|
4
|
+
/**
|
5
|
+
* This is velocity-script, that assumes the response to be LambdaResponse(status and body).
|
6
|
+
* It will always return the body and status, but if status in something else than 200 OK the content-type
|
7
|
+
* will be overridden to text/plain. (it's assumed, that lambda will return error text).
|
8
|
+
*
|
9
|
+
* If fileName is set, then Content-Disposition-header will be set to use it
|
10
|
+
*/
|
11
|
+
export const RESPONSE_DEFAULT_LAMBDA = `#set($inputRoot = $input.path('$'))
|
12
|
+
$inputRoot.body
|
13
|
+
#if ($inputRoot.status != 200)
|
14
|
+
#set ($context.responseOverride.status = $inputRoot.status)
|
15
|
+
#set ($context.responseOverride.header.Content-Type = 'text/plain')
|
16
|
+
#end
|
17
|
+
#set ($context.responseOverride.header.Access-Control-Allow-Origin = '*')
|
18
|
+
#if ("$!inputRoot.fileName" != "")
|
19
|
+
#set ($disposition = 'attachment; filename="FN"')
|
20
|
+
#set ($context.responseOverride.header.Content-Disposition = $disposition.replaceAll('FN', $inputRoot.fileName))
|
21
|
+
#end
|
22
|
+
`;
|
23
|
+
|
24
|
+
const BODY_FROM_INPUT_PATH = "$input.path('$').body";
|
25
|
+
|
26
|
+
// DEPRECATED
|
27
|
+
const messageSchema: apigateway.JsonSchema = {
|
28
|
+
schema: apigateway.JsonSchemaVersion.DRAFT4,
|
29
|
+
type: apigateway.JsonSchemaType.OBJECT,
|
30
|
+
description: 'Response with message',
|
31
|
+
properties: {
|
32
|
+
message: {
|
33
|
+
type: apigateway.JsonSchemaType.STRING,
|
34
|
+
description: 'Response message',
|
35
|
+
},
|
36
|
+
},
|
37
|
+
};
|
38
|
+
|
39
|
+
// DEPRECATED
|
40
|
+
export const MessageModel = {
|
41
|
+
contentType: MediaType.APPLICATION_JSON,
|
42
|
+
modelName: 'MessageResponseModel',
|
43
|
+
schema: messageSchema,
|
44
|
+
};
|
45
|
+
|
46
|
+
const NotFoundMessage = 'Not found';
|
47
|
+
export const NotFoundResponse = JSON.stringify({message: NotFoundMessage});
|
48
|
+
|
49
|
+
const InternalServerErrorMessage = 'Error';
|
50
|
+
const InternalServerErrorResponse = JSON.stringify({message: InternalServerErrorMessage});
|
51
|
+
|
52
|
+
const BadRequestMessage = 'Bad request';
|
53
|
+
const BadRequestResponse = JSON.stringify({message: BadRequestMessage});
|
54
|
+
|
55
|
+
export const BadRequestResponseTemplate = createResponses(MediaType.APPLICATION_JSON, BadRequestResponse);
|
56
|
+
export const NotFoundResponseTemplate = createResponses(MediaType.APPLICATION_JSON, NotFoundResponse);
|
57
|
+
export const XmlResponseTemplate = createResponses(MediaType.APPLICATION_XML, BODY_FROM_INPUT_PATH);
|
58
|
+
export const SvgResponseTemplate = createResponses(MediaType.IMAGE_SVG, BODY_FROM_INPUT_PATH);
|
59
|
+
export const InternalServerErrorResponseTemplate = createResponses(MediaType.APPLICATION_JSON, InternalServerErrorResponse);
|
60
|
+
|
61
|
+
export function createResponses<T>(key: MediaType, value: T): Record<string, T> {
|
62
|
+
const map: Record<string, T> = {};
|
63
|
+
|
64
|
+
map[key] = value;
|
65
|
+
|
66
|
+
return map;
|
67
|
+
}
|
@@ -0,0 +1,124 @@
|
|
1
|
+
import {
|
2
|
+
InternalServerErrorResponseTemplate,
|
3
|
+
createResponses,
|
4
|
+
XmlResponseTemplate,
|
5
|
+
NotFoundResponseTemplate,
|
6
|
+
BadRequestResponseTemplate,
|
7
|
+
} from "./response";
|
8
|
+
import {
|
9
|
+
LambdaIntegration,
|
10
|
+
MethodResponse,
|
11
|
+
IntegrationResponse,
|
12
|
+
PassthroughBehavior,
|
13
|
+
} from "aws-cdk-lib/aws-apigateway";
|
14
|
+
import { Function as AWSFunction } from "aws-cdk-lib/aws-lambda";
|
15
|
+
import { IModel } from "aws-cdk-lib/aws-apigateway/lib/model";
|
16
|
+
import {
|
17
|
+
BAD_REQUEST_MESSAGE,
|
18
|
+
ERROR_MESSAGE,
|
19
|
+
NOT_FOUND_MESSAGE,
|
20
|
+
} from "../../types/errors";
|
21
|
+
import { MediaType } from "../../types/mediatypes";
|
22
|
+
|
23
|
+
export const RESPONSE_200_OK: IntegrationResponse = {
|
24
|
+
statusCode: "200",
|
25
|
+
};
|
26
|
+
|
27
|
+
export const RESPONSE_400_BAD_REQUEST: IntegrationResponse = {
|
28
|
+
statusCode: "400",
|
29
|
+
selectionPattern: BAD_REQUEST_MESSAGE,
|
30
|
+
responseTemplates: BadRequestResponseTemplate,
|
31
|
+
};
|
32
|
+
|
33
|
+
export const RESPONSE_500_SERVER_ERROR: IntegrationResponse = {
|
34
|
+
statusCode: "500",
|
35
|
+
selectionPattern: ERROR_MESSAGE,
|
36
|
+
responseTemplates: InternalServerErrorResponseTemplate,
|
37
|
+
};
|
38
|
+
|
39
|
+
const RESPONSE_XML = {
|
40
|
+
responseTemplates: XmlResponseTemplate,
|
41
|
+
};
|
42
|
+
|
43
|
+
export const RESPONSE_CORS_INTEGRATION = {
|
44
|
+
responseParameters: {
|
45
|
+
"method.response.header.Access-Control-Allow-Origin": "'*'",
|
46
|
+
},
|
47
|
+
};
|
48
|
+
|
49
|
+
export const RESPONSE_404_NOT_FOUND = {
|
50
|
+
statusCode: "404",
|
51
|
+
selectionPattern: NOT_FOUND_MESSAGE,
|
52
|
+
responseTemplates: NotFoundResponseTemplate,
|
53
|
+
};
|
54
|
+
|
55
|
+
export function methodResponse(
|
56
|
+
status: string,
|
57
|
+
contentType: MediaType,
|
58
|
+
model: IModel,
|
59
|
+
parameters?: Record<string, boolean>
|
60
|
+
): MethodResponse {
|
61
|
+
return {
|
62
|
+
statusCode: status,
|
63
|
+
responseModels: createResponses(contentType, model),
|
64
|
+
responseParameters: parameters || {},
|
65
|
+
};
|
66
|
+
}
|
67
|
+
|
68
|
+
export function corsMethod(response: MethodResponse): MethodResponse {
|
69
|
+
return {
|
70
|
+
...response,
|
71
|
+
...{
|
72
|
+
responseParameters: {
|
73
|
+
"method.response.header.Access-Control-Allow-Origin": true,
|
74
|
+
},
|
75
|
+
},
|
76
|
+
};
|
77
|
+
}
|
78
|
+
|
79
|
+
interface IntegrationOptions {
|
80
|
+
requestParameters?: { [dest: string]: string };
|
81
|
+
requestTemplates?: { [contentType: string]: string };
|
82
|
+
responses?: IntegrationResponse[];
|
83
|
+
disableCors?: boolean;
|
84
|
+
xml?: boolean;
|
85
|
+
passthroughBehavior?: PassthroughBehavior;
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Creates a default Lambda integration for a REST API resource _root_
|
90
|
+
* @param lambdaFunction The Lambda function
|
91
|
+
* @param options Options
|
92
|
+
*/
|
93
|
+
export function defaultIntegration(
|
94
|
+
lambdaFunction: AWSFunction,
|
95
|
+
options?: IntegrationOptions
|
96
|
+
): LambdaIntegration {
|
97
|
+
return new LambdaIntegration(lambdaFunction, {
|
98
|
+
proxy: false,
|
99
|
+
integrationResponses: options?.responses || [
|
100
|
+
getResponse(RESPONSE_200_OK, options),
|
101
|
+
getResponse(RESPONSE_400_BAD_REQUEST, options),
|
102
|
+
getResponse(RESPONSE_404_NOT_FOUND, options),
|
103
|
+
getResponse(RESPONSE_500_SERVER_ERROR, options),
|
104
|
+
],
|
105
|
+
requestParameters: options?.requestParameters || {},
|
106
|
+
requestTemplates: options?.requestTemplates || {},
|
107
|
+
passthroughBehavior:
|
108
|
+
options?.passthroughBehavior ?? PassthroughBehavior.WHEN_NO_MATCH,
|
109
|
+
});
|
110
|
+
}
|
111
|
+
|
112
|
+
export function getResponse(
|
113
|
+
response: IntegrationResponse,
|
114
|
+
options?: IntegrationOptions
|
115
|
+
): IntegrationResponse {
|
116
|
+
if (options?.xml) {
|
117
|
+
response = { ...response, ...RESPONSE_XML };
|
118
|
+
}
|
119
|
+
if (!options?.disableCors) {
|
120
|
+
response = { ...response, ...RESPONSE_CORS_INTEGRATION };
|
121
|
+
}
|
122
|
+
|
123
|
+
return response;
|
124
|
+
}
|
@@ -0,0 +1,62 @@
|
|
1
|
+
import {MockIntegration, PassthroughBehavior, Resource} from "aws-cdk-lib/aws-apigateway";
|
2
|
+
import {MediaType} from "../../types/mediatypes";
|
3
|
+
import {corsMethod, RESPONSE_CORS_INTEGRATION} from "./responses";
|
4
|
+
|
5
|
+
const INTEGRATION_RESPONSE_200 = `{
|
6
|
+
"statusCode": 200
|
7
|
+
}`;
|
8
|
+
|
9
|
+
const METHOD_RESPONSE_200 = {
|
10
|
+
statusCode: '200',
|
11
|
+
};
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Static integration, that returns the given response with given mediaType from given resource.
|
15
|
+
*
|
16
|
+
* @param resource
|
17
|
+
* @param mediaType
|
18
|
+
* @param response
|
19
|
+
*/
|
20
|
+
export class DigitrafficStaticIntegration extends MockIntegration {
|
21
|
+
constructor(
|
22
|
+
resource: Resource, mediaType: MediaType, response: string, enableCors = true, apiKeyRequired = true,
|
23
|
+
) {
|
24
|
+
const integrationResponse = DigitrafficStaticIntegration.createIntegrationResponse(response, mediaType, enableCors);
|
25
|
+
|
26
|
+
super({
|
27
|
+
passthroughBehavior: PassthroughBehavior.WHEN_NO_TEMPLATES,
|
28
|
+
requestTemplates: {
|
29
|
+
[mediaType]: INTEGRATION_RESPONSE_200,
|
30
|
+
},
|
31
|
+
integrationResponses: [integrationResponse],
|
32
|
+
});
|
33
|
+
|
34
|
+
['GET', 'HEAD'].forEach((httpMethod) => {
|
35
|
+
resource.addMethod(httpMethod, this, {
|
36
|
+
apiKeyRequired,
|
37
|
+
methodResponses: [DigitrafficStaticIntegration.createMethodResponse(enableCors)],
|
38
|
+
});
|
39
|
+
});
|
40
|
+
}
|
41
|
+
|
42
|
+
static json<K>(resource: Resource, response: K, enableCors = true, apiKeyRequired = true) {
|
43
|
+
return new DigitrafficStaticIntegration(
|
44
|
+
resource, MediaType.APPLICATION_JSON, JSON.stringify(response), enableCors, apiKeyRequired,
|
45
|
+
);
|
46
|
+
}
|
47
|
+
|
48
|
+
private static createIntegrationResponse(response: string, mediaType: MediaType, enableCors: boolean) {
|
49
|
+
const integrationResponse = {
|
50
|
+
statusCode: '200',
|
51
|
+
responseTemplates: {
|
52
|
+
[mediaType]: response,
|
53
|
+
},
|
54
|
+
};
|
55
|
+
|
56
|
+
return enableCors ? {...integrationResponse, ...RESPONSE_CORS_INTEGRATION} : integrationResponse;
|
57
|
+
}
|
58
|
+
|
59
|
+
private static createMethodResponse(enableCors: boolean) {
|
60
|
+
return enableCors ? corsMethod(METHOD_RESPONSE_200) : METHOD_RESPONSE_200;
|
61
|
+
}
|
62
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import {Construct} from "constructs";
|
2
|
+
import {CanaryParameters} from "./canary-parameters";
|
3
|
+
import {Alarm, ComparisonOperator} from "aws-cdk-lib/aws-cloudwatch";
|
4
|
+
import {Canary} from "@aws-cdk/aws-synthetics-alpha";
|
5
|
+
import {SnsAction} from "aws-cdk-lib/aws-cloudwatch-actions";
|
6
|
+
import {Topic} from "aws-cdk-lib/aws-sns";
|
7
|
+
|
8
|
+
export class CanaryAlarm {
|
9
|
+
constructor(stack: Construct,
|
10
|
+
canary: Canary,
|
11
|
+
params: CanaryParameters) {
|
12
|
+
if (params.alarm ?? true) {
|
13
|
+
const alarmName = params.alarm?.alarmName ?? `${params.name}-alarm`;
|
14
|
+
|
15
|
+
const alarm = new Alarm(stack, alarmName, {
|
16
|
+
alarmName,
|
17
|
+
alarmDescription: params.alarm?.description ?? '',
|
18
|
+
metric: canary.metricSuccessPercent(),
|
19
|
+
evaluationPeriods: params.alarm?.evalutionPeriods ?? 1,
|
20
|
+
threshold: params.alarm?.threshold ?? 100,
|
21
|
+
comparisonOperator: ComparisonOperator.LESS_THAN_THRESHOLD,
|
22
|
+
});
|
23
|
+
|
24
|
+
if (params.alarm?.topicArn) {
|
25
|
+
alarm.addAlarmAction(new SnsAction(Topic.fromTopicArn(stack,
|
26
|
+
`${alarmName}-action`,
|
27
|
+
params.alarm.topicArn)));
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import {Schedule} from "@aws-cdk/aws-synthetics-alpha";
|
2
|
+
|
3
|
+
/** Optional env parameters for canary */
|
4
|
+
type CanaryEnv = Record<string, string>;
|
5
|
+
|
6
|
+
export type CanaryParameters = {
|
7
|
+
readonly name: string;
|
8
|
+
readonly schedule?: Schedule;
|
9
|
+
readonly secret?: string;
|
10
|
+
readonly handler: string;
|
11
|
+
readonly alarm?: {
|
12
|
+
readonly alarmName?: string;
|
13
|
+
readonly description?: string;
|
14
|
+
readonly evalutionPeriods?: number;
|
15
|
+
readonly threshold?: number;
|
16
|
+
readonly topicArn?: string;
|
17
|
+
}
|
18
|
+
readonly canaryEnv?: CanaryEnv;
|
19
|
+
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import {ManagedPolicy, PolicyStatement, PolicyStatementProps, Role, ServicePrincipal} from "aws-cdk-lib/aws-iam";
|
2
|
+
import {Construct} from "constructs";
|
3
|
+
|
4
|
+
const BASE_POLICY_STATEMENT_PROPS: PolicyStatementProps = {
|
5
|
+
actions: [
|
6
|
+
"logs:CreateLogStream",
|
7
|
+
"logs:PutLogEvents",
|
8
|
+
"logs:CreateLogGroup",
|
9
|
+
"logs:DescribeLogGroups",
|
10
|
+
"logs:DescribeLogStreams",
|
11
|
+
],
|
12
|
+
resources: ["*"],
|
13
|
+
};
|
14
|
+
|
15
|
+
const CLOUDWATCH_STATEMENT_PROPS: PolicyStatementProps = {
|
16
|
+
actions: [
|
17
|
+
"cloudwatch:PutMetricData",
|
18
|
+
],
|
19
|
+
resources: ["*"],
|
20
|
+
conditions: {
|
21
|
+
"StringEquals": {
|
22
|
+
"cloudwatch:namespace": "CloudWatchSynthetics",
|
23
|
+
},
|
24
|
+
},
|
25
|
+
};
|
26
|
+
|
27
|
+
export class DigitrafficCanaryRole extends Role {
|
28
|
+
constructor(stack: Construct, canaryName: string) {
|
29
|
+
super(stack, 'canary-role-' + canaryName, {
|
30
|
+
assumedBy: new ServicePrincipal("lambda.amazonaws.com"),
|
31
|
+
managedPolicies: [
|
32
|
+
ManagedPolicy.fromAwsManagedPolicyName("CloudWatchSyntheticsFullAccess"),
|
33
|
+
],
|
34
|
+
});
|
35
|
+
|
36
|
+
this.addToPolicy(new PolicyStatement(BASE_POLICY_STATEMENT_PROPS));
|
37
|
+
this.addToPolicy(new PolicyStatement(CLOUDWATCH_STATEMENT_PROPS));
|
38
|
+
}
|
39
|
+
|
40
|
+
withDatabaseAccess(): DigitrafficCanaryRole {
|
41
|
+
// Won't work :(
|
42
|
+
// this.addToPolicy(new PolicyStatement(DB_STATEMENT_PROPS));
|
43
|
+
// Works
|
44
|
+
this.addManagedPolicy(ManagedPolicy.fromAwsManagedPolicyName("service-role/AWSLambdaVPCAccessExecutionRole"));
|
45
|
+
return this;
|
46
|
+
}
|
47
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { Duration } from "aws-cdk-lib";
|
2
|
+
import {
|
3
|
+
AssetCode,
|
4
|
+
Canary,
|
5
|
+
Runtime,
|
6
|
+
Schedule,
|
7
|
+
Test,
|
8
|
+
} from "@aws-cdk/aws-synthetics-alpha";
|
9
|
+
import { Role } from "aws-cdk-lib/aws-iam";
|
10
|
+
import { CanaryAlarm } from "./canary-alarm";
|
11
|
+
import { CanaryParameters } from "./canary-parameters";
|
12
|
+
import { Construct } from "constructs";
|
13
|
+
import { LambdaEnvironment } from "../stack/lambda-configs";
|
14
|
+
|
15
|
+
export class DigitrafficCanary extends Canary {
|
16
|
+
constructor(
|
17
|
+
scope: Construct,
|
18
|
+
canaryName: string,
|
19
|
+
role: Role,
|
20
|
+
params: CanaryParameters,
|
21
|
+
environmentVariables: LambdaEnvironment
|
22
|
+
) {
|
23
|
+
super(scope, canaryName, {
|
24
|
+
runtime: Runtime.SYNTHETICS_NODEJS_PUPPETEER_3_6,
|
25
|
+
role,
|
26
|
+
test: Test.custom({
|
27
|
+
code: new AssetCode("dist", {
|
28
|
+
exclude: ["lambda", "out", "canaries"],
|
29
|
+
}),
|
30
|
+
handler: params.handler,
|
31
|
+
}),
|
32
|
+
environmentVariables: {
|
33
|
+
...environmentVariables,
|
34
|
+
...params?.canaryEnv,
|
35
|
+
},
|
36
|
+
canaryName,
|
37
|
+
schedule: params.schedule ?? Schedule.rate(Duration.minutes(15)),
|
38
|
+
});
|
39
|
+
|
40
|
+
this.artifactsBucket.grantWrite(role);
|
41
|
+
|
42
|
+
if (params.alarm ?? true) {
|
43
|
+
new CanaryAlarm(scope, this, params);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
@@ -0,0 +1,98 @@
|
|
1
|
+
import { Role } from "aws-cdk-lib/aws-iam";
|
2
|
+
import { ISecret } from "aws-cdk-lib/aws-secretsmanager";
|
3
|
+
import { CfnCanary } from "aws-cdk-lib/aws-synthetics";
|
4
|
+
import { Schedule } from "aws-cdk-lib/aws-events";
|
5
|
+
import { Duration } from "aws-cdk-lib";
|
6
|
+
|
7
|
+
import { CanaryParameters } from "./canary-parameters";
|
8
|
+
import { DigitrafficCanary } from "./canary";
|
9
|
+
import { DigitrafficStack } from "../stack/stack";
|
10
|
+
|
11
|
+
export class DatabaseCanary extends DigitrafficCanary {
|
12
|
+
constructor(
|
13
|
+
stack: DigitrafficStack,
|
14
|
+
role: Role,
|
15
|
+
secret: ISecret,
|
16
|
+
params: CanaryParameters
|
17
|
+
) {
|
18
|
+
const canaryName = `${params.name}-db`;
|
19
|
+
const environmentVariables = stack.createDefaultLambdaEnvironment(
|
20
|
+
`Synthetics-${canaryName}`
|
21
|
+
);
|
22
|
+
|
23
|
+
// the handler code is defined at the actual project using this
|
24
|
+
super(stack, canaryName, role, params, environmentVariables);
|
25
|
+
|
26
|
+
this.artifactsBucket.grantWrite(this.role);
|
27
|
+
secret.grantRead(this.role);
|
28
|
+
|
29
|
+
// need to override vpc and security group, can't do this with cdk
|
30
|
+
if (this.node.defaultChild instanceof CfnCanary) {
|
31
|
+
const subnetIds =
|
32
|
+
stack.vpc === undefined
|
33
|
+
? []
|
34
|
+
: stack.vpc.privateSubnets.map((subnet) => subnet.subnetId);
|
35
|
+
|
36
|
+
const securityGroupIds =
|
37
|
+
stack.lambdaDbSg === undefined
|
38
|
+
? []
|
39
|
+
: [stack.lambdaDbSg.securityGroupId];
|
40
|
+
|
41
|
+
this.node.defaultChild.vpcConfig = {
|
42
|
+
vpcId: stack.vpc?.vpcId,
|
43
|
+
securityGroupIds,
|
44
|
+
subnetIds,
|
45
|
+
};
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
static create(
|
50
|
+
stack: DigitrafficStack,
|
51
|
+
role: Role,
|
52
|
+
params: CanaryParameters
|
53
|
+
): DatabaseCanary {
|
54
|
+
const secret = stack.getSecret();
|
55
|
+
return new DatabaseCanary(stack, role, secret, {
|
56
|
+
...{
|
57
|
+
secret: stack.configuration.secretId,
|
58
|
+
schedule: Schedule.rate(Duration.hours(1)),
|
59
|
+
handler: `${params.name}.handler`,
|
60
|
+
},
|
61
|
+
...params,
|
62
|
+
});
|
63
|
+
}
|
64
|
+
|
65
|
+
/**
|
66
|
+
*
|
67
|
+
* @param stack
|
68
|
+
* @param role
|
69
|
+
* @param name name of the typescipt file without -db -suffix. Max len is 10 char if @param canaryName is not given.
|
70
|
+
* @param params
|
71
|
+
* @param canaryName Optional name for canary if multiple canaries is made from same ${name}-db.ts canary file.
|
72
|
+
*/
|
73
|
+
static createV2(
|
74
|
+
stack: DigitrafficStack,
|
75
|
+
role: Role,
|
76
|
+
name: string,
|
77
|
+
params: Partial<CanaryParameters> = {},
|
78
|
+
canaryName = name
|
79
|
+
): DatabaseCanary {
|
80
|
+
const secret = stack.getSecret();
|
81
|
+
return new DatabaseCanary(stack, role, secret, {
|
82
|
+
...{
|
83
|
+
secret: stack.configuration.secretId,
|
84
|
+
schedule: Schedule.rate(Duration.hours(1)),
|
85
|
+
handler: `${name}-db.handler`,
|
86
|
+
name: canaryName,
|
87
|
+
alarm: {
|
88
|
+
alarmName:
|
89
|
+
canaryName === name
|
90
|
+
? `${stack.configuration.shortName}-DB-Alarm`
|
91
|
+
: `${canaryName}-DB-Alarm`,
|
92
|
+
topicArn: stack.configuration.alarmTopicArn,
|
93
|
+
},
|
94
|
+
},
|
95
|
+
...params,
|
96
|
+
});
|
97
|
+
}
|
98
|
+
}
|