@digitraffic/common 2024.1.24-3 → 2024.3.11-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/dist/__test__/api/handler-factory.test.d.mts +1 -0
  2. package/dist/__test__/api/handler-factory.test.mjs +43 -0
  3. package/dist/__test__/api/response.test.d.mts +1 -0
  4. package/dist/__test__/api/response.test.mjs +86 -0
  5. package/dist/__test__/imports.test.d.mts +1 -0
  6. package/dist/__test__/imports.test.mjs +332 -0
  7. package/dist/__test__/marine/id_utils.test.d.mts +1 -0
  8. package/dist/__test__/marine/id_utils.test.mjs +44 -0
  9. package/dist/__test__/promise/promise.test.d.mts +1 -0
  10. package/dist/__test__/promise/promise.test.mjs +130 -0
  11. package/dist/__test__/runtime/dt-logger.test.d.mts +1 -0
  12. package/dist/__test__/runtime/dt-logger.test.mjs +108 -0
  13. package/dist/__test__/secrets/secret-holder.test.d.mts +1 -0
  14. package/dist/__test__/secrets/secret-holder.test.mjs +86 -0
  15. package/dist/__test__/secrets/secret.test.d.mts +1 -0
  16. package/dist/__test__/secrets/secret.test.mjs +38 -0
  17. package/dist/__test__/test/httpserver.test.d.mts +1 -0
  18. package/dist/__test__/test/httpserver.test.mjs +154 -0
  19. package/dist/__test__/test/mock-ky.test.d.mts +1 -0
  20. package/dist/__test__/test/mock-ky.test.mjs +46 -0
  21. package/dist/__test__/types/lambda-response.test.d.mts +1 -0
  22. package/dist/__test__/types/lambda-response.test.mjs +58 -0
  23. package/dist/__test__/utils/date-utils.test.d.mts +1 -0
  24. package/dist/__test__/utils/date-utils.test.mjs +27 -0
  25. package/dist/__test__/utils/geometry.test.d.mts +1 -0
  26. package/dist/__test__/utils/geometry.test.mjs +24 -0
  27. package/dist/__test__/utils/logging.test.d.mts +1 -0
  28. package/dist/__test__/utils/logging.test.mjs +78 -0
  29. package/dist/__test__/utils/utils.test.d.mts +1 -0
  30. package/dist/__test__/utils/utils.test.mjs +43 -0
  31. package/dist/aws/infra/api/handler-factory.mjs +4 -0
  32. package/dist/aws/infra/api/integration.d.mts +2 -2
  33. package/dist/aws/infra/api/integration.mjs +4 -1
  34. package/dist/aws/infra/api/response.d.mts +1 -1
  35. package/dist/aws/infra/api/responses.d.mts +1 -1
  36. package/dist/aws/infra/api/responses.mjs +2 -0
  37. package/dist/aws/infra/api/static-integration.mjs +1 -1
  38. package/dist/aws/infra/canaries/canary-alarm.d.mts +1 -1
  39. package/dist/aws/infra/canaries/canary-alarm.mjs +2 -0
  40. package/dist/aws/infra/canaries/canary-parameters.mjs +1 -1
  41. package/dist/aws/infra/canaries/canary-role.mjs +1 -0
  42. package/dist/aws/infra/canaries/canary.d.mts +2 -2
  43. package/dist/aws/infra/canaries/canary.mjs +2 -0
  44. package/dist/aws/infra/canaries/database-canary.d.mts +2 -2
  45. package/dist/aws/infra/canaries/database-canary.mjs +2 -0
  46. package/dist/aws/infra/canaries/database-checker.d.mts +1 -1
  47. package/dist/aws/infra/canaries/database-checker.mjs +7 -1
  48. package/dist/aws/infra/canaries/url-canary.d.mts +2 -2
  49. package/dist/aws/infra/canaries/url-canary.mjs +3 -0
  50. package/dist/aws/infra/canaries/url-checker.d.mts +1 -1
  51. package/dist/aws/infra/canaries/url-checker.mjs +4 -1
  52. package/dist/aws/infra/documentation.mjs +5 -1
  53. package/dist/aws/infra/import-util.d.mts +1 -1
  54. package/dist/aws/infra/import-util.mjs +4 -3
  55. package/dist/aws/infra/scheduler.mjs +2 -0
  56. package/dist/aws/infra/security-rule.d.mts +1 -1
  57. package/dist/aws/infra/security-rule.mjs +1 -0
  58. package/dist/aws/infra/sqs-integration.d.mts +1 -1
  59. package/dist/aws/infra/sqs-integration.mjs +3 -1
  60. package/dist/aws/infra/sqs-queue.d.mts +1 -1
  61. package/dist/aws/infra/sqs-queue.mjs +2 -1
  62. package/dist/aws/infra/stack/lambda-configs.d.mts +4 -4
  63. package/dist/aws/infra/stack/lambda-configs.mjs +4 -2
  64. package/dist/aws/infra/stack/monitoredfunction.d.mts +3 -3
  65. package/dist/aws/infra/stack/monitoredfunction.mjs +23 -18
  66. package/dist/aws/infra/stack/parameters.mjs +1 -0
  67. package/dist/aws/infra/stack/rest_apis.d.mts +2 -2
  68. package/dist/aws/infra/stack/rest_apis.mjs +6 -1
  69. package/dist/aws/infra/stack/stack-checking-aspect.d.mts +2 -2
  70. package/dist/aws/infra/stack/stack-checking-aspect.mjs +6 -1
  71. package/dist/aws/infra/stack/stack.d.mts +5 -5
  72. package/dist/aws/infra/stack/stack.mjs +9 -0
  73. package/dist/aws/infra/stack/subscription.mjs +4 -0
  74. package/dist/aws/infra/stacks/db-dns-stack.d.mts +1 -1
  75. package/dist/aws/infra/stacks/db-dns-stack.mjs +1 -0
  76. package/dist/aws/infra/stacks/db-proxy-stack.d.mts +3 -3
  77. package/dist/aws/infra/stacks/db-proxy-stack.mjs +4 -2
  78. package/dist/aws/infra/stacks/db-stack.d.mts +3 -3
  79. package/dist/aws/infra/stacks/db-stack.mjs +11 -7
  80. package/dist/aws/infra/stacks/intra-stack-configuration.d.mts +1 -1
  81. package/dist/aws/infra/stacks/network-stack.d.mts +2 -2
  82. package/dist/aws/infra/stacks/network-stack.mjs +8 -0
  83. package/dist/aws/infra/usage-plans.d.mts +1 -1
  84. package/dist/aws/infra/usage-plans.mjs +1 -0
  85. package/dist/aws/runtime/apikey.d.mts +2 -2
  86. package/dist/aws/runtime/apikey.mjs +2 -2
  87. package/dist/aws/runtime/digitraffic-integration-response.d.mts +1 -1
  88. package/dist/aws/runtime/dt-logger.mjs +6 -2
  89. package/dist/aws/runtime/messaging.d.mts +2 -2
  90. package/dist/aws/runtime/messaging.mjs +5 -4
  91. package/dist/aws/runtime/s3.d.mts +4 -2
  92. package/dist/aws/runtime/s3.mjs +15 -10
  93. package/dist/aws/runtime/secrets/dbsecret.d.mts +1 -1
  94. package/dist/aws/runtime/secrets/proxy-holder.mjs +1 -0
  95. package/dist/aws/runtime/secrets/rds-holder.mjs +1 -0
  96. package/dist/aws/runtime/secrets/secret-holder.d.mts +1 -1
  97. package/dist/aws/runtime/secrets/secret-holder.mjs +6 -1
  98. package/dist/aws/runtime/secrets/secret.mjs +5 -6
  99. package/dist/aws/types/errors.mjs +1 -0
  100. package/dist/aws/types/lambda-response.mjs +5 -0
  101. package/dist/aws/types/model-with-reference.mjs +1 -1
  102. package/dist/database/cached.d.mts +1 -1
  103. package/dist/database/database.mjs +1 -0
  104. package/dist/database/last-updated.d.mts +1 -1
  105. package/dist/test/db-testutils.d.mts +1 -1
  106. package/dist/test/db-testutils.mjs +1 -1
  107. package/dist/test/httpserver.mjs +7 -3
  108. package/dist/test/mock-ky.d.mts +2 -0
  109. package/dist/test/mock-ky.mjs +15 -0
  110. package/dist/test/secrets-manager.d.mts +3 -2
  111. package/dist/test/secrets-manager.mjs +14 -16
  112. package/dist/test/testutils.mjs +1 -1
  113. package/dist/types/http-error.mjs +1 -0
  114. package/dist/types/nullable.d.mts +1 -1
  115. package/dist/utils/api-model.d.mts +2 -2
  116. package/dist/utils/api-model.mjs +1 -1
  117. package/dist/utils/geojson-types.d.mts +1 -1
  118. package/dist/utils/geojson-types.mjs +4 -2
  119. package/dist/utils/geometry.d.mts +1 -1
  120. package/dist/utils/geometry.mjs +3 -0
  121. package/dist/utils/logging.mjs +2 -2
  122. package/dist/utils/retry.d.mts +2 -2
  123. package/dist/utils/retry.mjs +2 -2
  124. package/dist/utils/slack.mjs +4 -3
  125. package/dist/utils/utils.d.mts +2 -2
  126. package/package.json +25 -15
  127. package/src/@types/geojson-validation/index.d.mts +0 -4
  128. package/src/aws/infra/api/handler-factory.mts +0 -86
  129. package/src/aws/infra/api/integration.mts +0 -147
  130. package/src/aws/infra/api/response.mts +0 -165
  131. package/src/aws/infra/api/responses.mts +0 -127
  132. package/src/aws/infra/api/static-integration.mts +0 -108
  133. package/src/aws/infra/canaries/Synthetics.d.mts +0 -21
  134. package/src/aws/infra/canaries/canary-alarm.mts +0 -33
  135. package/src/aws/infra/canaries/canary-keys.mts +0 -3
  136. package/src/aws/infra/canaries/canary-parameters.mts +0 -19
  137. package/src/aws/infra/canaries/canary-role.mts +0 -73
  138. package/src/aws/infra/canaries/canary.mts +0 -44
  139. package/src/aws/infra/canaries/database-canary.mts +0 -98
  140. package/src/aws/infra/canaries/database-checker.mts +0 -163
  141. package/src/aws/infra/canaries/url-canary.mts +0 -98
  142. package/src/aws/infra/canaries/url-checker.mts +0 -388
  143. package/src/aws/infra/documentation.mts +0 -142
  144. package/src/aws/infra/import-util.mts +0 -57
  145. package/src/aws/infra/scheduler.mts +0 -59
  146. package/src/aws/infra/security-rule.mts +0 -38
  147. package/src/aws/infra/sqs-integration.mts +0 -106
  148. package/src/aws/infra/sqs-queue.mts +0 -162
  149. package/src/aws/infra/stack/lambda-configs.mts +0 -135
  150. package/src/aws/infra/stack/monitoredfunction.mts +0 -352
  151. package/src/aws/infra/stack/parameters.mts +0 -74
  152. package/src/aws/infra/stack/rest_apis.mts +0 -322
  153. package/src/aws/infra/stack/stack-checking-aspect.mts +0 -233
  154. package/src/aws/infra/stack/stack.mts +0 -144
  155. package/src/aws/infra/stack/subscription.mts +0 -58
  156. package/src/aws/infra/stacks/db-dns-stack.mts +0 -77
  157. package/src/aws/infra/stacks/db-proxy-stack.mts +0 -134
  158. package/src/aws/infra/stacks/db-stack.mts +0 -292
  159. package/src/aws/infra/stacks/intra-stack-configuration.mts +0 -6
  160. package/src/aws/infra/stacks/network-stack.mts +0 -76
  161. package/src/aws/infra/usage-plans.mts +0 -50
  162. package/src/aws/runtime/apikey.mts +0 -9
  163. package/src/aws/runtime/digitraffic-integration-response.mts +0 -35
  164. package/src/aws/runtime/dt-logger-default.mts +0 -11
  165. package/src/aws/runtime/dt-logger.mts +0 -184
  166. package/src/aws/runtime/environment.mts +0 -22
  167. package/src/aws/runtime/messaging.mts +0 -26
  168. package/src/aws/runtime/s3.mts +0 -44
  169. package/src/aws/runtime/secrets/dbsecret.mts +0 -31
  170. package/src/aws/runtime/secrets/node-ttl.d.mts +0 -12
  171. package/src/aws/runtime/secrets/proxy-holder.mts +0 -34
  172. package/src/aws/runtime/secrets/rds-holder.mts +0 -34
  173. package/src/aws/runtime/secrets/secret-holder.mts +0 -106
  174. package/src/aws/runtime/secrets/secret.mts +0 -58
  175. package/src/aws/types/errors.mts +0 -14
  176. package/src/aws/types/lambda-response.mts +0 -100
  177. package/src/aws/types/mediatypes.mts +0 -12
  178. package/src/aws/types/model-with-reference.mts +0 -8
  179. package/src/aws/types/proxytypes.mts +0 -27
  180. package/src/aws/types/tags.mts +0 -3
  181. package/src/database/cached.mts +0 -64
  182. package/src/database/database.mts +0 -107
  183. package/src/database/last-updated.mts +0 -103
  184. package/src/database/models.mts +0 -7
  185. package/src/index.mts +0 -2
  186. package/src/marine/id_utils.mts +0 -30
  187. package/src/marine/rtz.mts +0 -57
  188. package/src/test/asserter.mts +0 -58
  189. package/src/test/db-testutils.mts +0 -52
  190. package/src/test/httpserver.mts +0 -111
  191. package/src/test/secrets-manager.mts +0 -37
  192. package/src/test/testutils.mts +0 -39
  193. package/src/types/async-timeout-error.mts +0 -5
  194. package/src/types/aws-env.mts +0 -3
  195. package/src/types/either.mts +0 -9
  196. package/src/types/http-error.mts +0 -8
  197. package/src/types/input-error.mts +0 -2
  198. package/src/types/language.mts +0 -3
  199. package/src/types/nullable.mts +0 -21
  200. package/src/types/traffictype.mts +0 -8
  201. package/src/types/urn.mts +0 -1
  202. package/src/types/util-types.mts +0 -10
  203. package/src/types/validator.mts +0 -10
  204. package/src/utils/api-model.mts +0 -133
  205. package/src/utils/base64.mts +0 -16
  206. package/src/utils/date-utils.mts +0 -53
  207. package/src/utils/geojson-types.mts +0 -22
  208. package/src/utils/geometry.mts +0 -171
  209. package/src/utils/logging.mts +0 -75
  210. package/src/utils/retry.mts +0 -200
  211. package/src/utils/slack.mts +0 -26
  212. package/src/utils/utils.mts +0 -184
@@ -1,352 +0,0 @@
1
- import { Function, FunctionProps } from "aws-cdk-lib/aws-lambda";
2
- import { Stack } from "aws-cdk-lib";
3
- import { SnsAction } from "aws-cdk-lib/aws-cloudwatch-actions";
4
- import { ComparisonOperator, Metric } from "aws-cdk-lib/aws-cloudwatch";
5
- import { DigitrafficStack } from "./stack.mjs";
6
- import { ITopic } from "aws-cdk-lib/aws-sns";
7
- import {
8
- databaseFunctionProps,
9
- LambdaEnvironment,
10
- MonitoredFunctionParameters,
11
- } from "./lambda-configs.mjs";
12
- import { DigitrafficLogSubscriptions } from "./subscription.mjs";
13
- import { TrafficType } from "../../../types/traffictype.mjs";
14
-
15
- import _ from "lodash";
16
-
17
- /**
18
- * Allows customization of CloudWatch Alarm properties
19
- */
20
- export interface MonitoredFunctionAlarmProps {
21
- /**
22
- * Setting this to false will not create a CloudWatch alarm
23
- */
24
- readonly create: boolean;
25
-
26
- readonly threshold?: number;
27
-
28
- readonly evaluationPeriods?: number;
29
-
30
- readonly datapointsToAlarm?: number;
31
-
32
- readonly comparisonOperator?: ComparisonOperator;
33
- }
34
-
35
- export interface MonitoredFunctionProps {
36
- readonly durationAlarmProps?: MonitoredFunctionAlarmProps;
37
-
38
- readonly durationWarningProps?: MonitoredFunctionAlarmProps;
39
-
40
- readonly errorAlarmProps?: MonitoredFunctionAlarmProps;
41
-
42
- readonly throttleAlarmProps?: MonitoredFunctionAlarmProps;
43
- }
44
-
45
- /**
46
- * Creates a Lambda function that monitors default CloudWatch Lambda metrics with CloudWatch Alarms.
47
- */
48
- export class MonitoredFunction extends Function {
49
- readonly givenName: string;
50
-
51
- /** disable all alarms */
52
- public static readonly DISABLE_ALARMS: MonitoredFunctionProps = {
53
- durationAlarmProps: {
54
- create: false,
55
- },
56
- durationWarningProps: {
57
- create: false,
58
- },
59
- errorAlarmProps: {
60
- create: false,
61
- },
62
- throttleAlarmProps: {
63
- create: false,
64
- },
65
- };
66
-
67
- /**
68
- * Create new MonitoredFunction. Use topics from given DigitrafficStack.
69
- *
70
- * @param stack DigitrafficStack
71
- * @param id Lambda construct Id
72
- * @param functionProps Lambda function properties
73
- * @param props Monitored function properties
74
- */
75
- static create(
76
- stack: DigitrafficStack,
77
- id: string,
78
- functionProps: FunctionProps,
79
- props?: Partial<MonitoredFunctionProps>
80
- ): MonitoredFunction {
81
- if (
82
- props === MonitoredFunction.DISABLE_ALARMS &&
83
- stack.configuration.production
84
- ) {
85
- throw new Error(
86
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
87
- `Function ${functionProps.functionName!} has DISABLE_ALARMS. Remove before installing to production or define your own properties!`
88
- );
89
- }
90
-
91
- return new MonitoredFunction(
92
- stack,
93
- id,
94
- functionProps,
95
- stack.alarmTopic,
96
- stack.warningTopic,
97
- stack.configuration.production,
98
- stack.configuration.trafficType,
99
- props
100
- );
101
- }
102
-
103
- /**
104
- * Create new MonitoredFunction. Use topics from given DigitrafficStack. Generate names from given name and configuration shortName.
105
- *
106
- * For example, shortName FOO and given name update-things will create function FOO-UpdateThings and use code from lambda/update-things/update-things.ts method handler.
107
- *
108
- * @param stack DigitrafficStack
109
- * @param name param-case name
110
- * @param environment Lambda environment
111
- * @param functionParameters Lambda function parameters
112
- */
113
- static createV2(
114
- stack: DigitrafficStack,
115
- name: string,
116
- environment: LambdaEnvironment,
117
- functionParameters?: Partial<MonitoredFunctionParameters>
118
- ): MonitoredFunction {
119
- const functionName =
120
- functionParameters?.functionName ??
121
- `${stack.configuration.shortName}-${_.chain(name)
122
- .camelCase()
123
- .startCase()
124
- .replace(/\s/g, "")
125
- .value()}`;
126
- const functionProps = databaseFunctionProps(
127
- stack,
128
- environment,
129
- functionName,
130
- name,
131
- functionParameters
132
- );
133
-
134
- return MonitoredFunction.create(
135
- stack,
136
- functionName,
137
- functionProps,
138
- functionParameters
139
- );
140
- }
141
-
142
- /**
143
- * @param scope Stack
144
- * @param id Lambda construct Id
145
- * @param functionProps Lambda function properties
146
- * @param alarmSnsTopic SNS topic for alarms
147
- * @param warningSnsTopic SNS topic for warnings
148
- * @param production Is the stack a production stack, used for determining the alarm topic
149
- * @param trafficType Traffic type, used for alarm names. Set to null if Lambda is not related to any traffic type.
150
- * @param props Monitored function properties
151
- */
152
- constructor(
153
- scope: Stack,
154
- id: string,
155
- functionProps: FunctionProps,
156
- alarmSnsTopic: ITopic,
157
- warningSnsTopic: ITopic,
158
- production: boolean,
159
- trafficType: TrafficType | null,
160
- props?: MonitoredFunctionProps
161
- ) {
162
- super(scope, id, functionProps);
163
-
164
- if (functionProps.functionName === undefined) {
165
- throw new Error("Function name not provided");
166
- }
167
- this.givenName = functionProps.functionName;
168
-
169
- const alarmSnsAction = new SnsAction(alarmSnsTopic);
170
- const warningSnsAction = new SnsAction(warningSnsTopic);
171
-
172
- if (props?.durationAlarmProps?.create !== false) {
173
- if (!functionProps.timeout) {
174
- throw new Error("Timeout needs to be explicitly set");
175
- }
176
-
177
- this.createAlarm(
178
- scope,
179
- this.metricDuration().with({ statistic: "max" }),
180
- "Duration",
181
- "Duration alarm",
182
- `Duration has exceeded ${functionProps.timeout.toSeconds()} seconds`,
183
- trafficType,
184
- this.getAlarmActionForEnv(
185
- alarmSnsAction,
186
- warningSnsAction,
187
- production
188
- ),
189
- functionProps.timeout.toMilliseconds(),
190
- 1,
191
- 1,
192
- ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
193
- props?.durationAlarmProps
194
- );
195
- }
196
- if (props?.durationWarningProps?.create !== false) {
197
- if (!functionProps.timeout) {
198
- throw new Error("Timeout needs to be explicitly set");
199
- }
200
-
201
- this.createAlarm(
202
- scope,
203
- this.metricDuration().with({ statistic: "max" }),
204
- "Duration-Warning",
205
- "Duration warning",
206
- `Duration is 85 % of max ${functionProps.timeout.toSeconds()} seconds`,
207
- trafficType,
208
- warningSnsAction,
209
- functionProps.timeout.toMilliseconds() * 0.85,
210
- 1,
211
- 1,
212
- ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
213
- props?.durationWarningProps
214
- );
215
- }
216
-
217
- if (props?.errorAlarmProps?.create !== false) {
218
- this.createAlarm(
219
- scope,
220
- this.metricErrors(),
221
- "Errors",
222
- "Errors alarm",
223
- "Invocations did not succeed",
224
- trafficType,
225
- this.getAlarmActionForEnv(
226
- alarmSnsAction,
227
- warningSnsAction,
228
- production
229
- ),
230
- 1,
231
- 1,
232
- 1,
233
- ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
234
- props?.errorAlarmProps
235
- );
236
- }
237
-
238
- if (props?.throttleAlarmProps?.create !== false) {
239
- this.createAlarm(
240
- scope,
241
- this.metricThrottles(),
242
- "Throttles",
243
- "Throttles alarm",
244
- "Has throttled",
245
- trafficType,
246
- this.getAlarmActionForEnv(
247
- alarmSnsAction,
248
- warningSnsAction,
249
- production
250
- ),
251
- 0,
252
- 1,
253
- 1,
254
- ComparisonOperator.GREATER_THAN_THRESHOLD,
255
- props?.throttleAlarmProps
256
- );
257
- }
258
- }
259
-
260
- private createAlarm(
261
- stack: Stack,
262
- metric: Metric,
263
- alarmId: string,
264
- alarmName: string,
265
- alarmDescription: string,
266
- trafficType: TrafficType | null,
267
- alarmSnsAction: SnsAction,
268
- threshold: number,
269
- evaluationPeriods: number,
270
- datapointsToAlarm: number,
271
- comparisonOperator: ComparisonOperator,
272
- alarmProps?: MonitoredFunctionAlarmProps
273
- ) {
274
- metric
275
- .createAlarm(stack, `${this.node.id}-${alarmId}`, {
276
- alarmName: `${trafficType ?? ""} ${stack.stackName} ${
277
- this.functionName
278
- } ${alarmName}`.trim(),
279
- alarmDescription,
280
- threshold: alarmProps?.threshold ?? threshold,
281
- evaluationPeriods:
282
- alarmProps?.evaluationPeriods ?? evaluationPeriods,
283
- datapointsToAlarm:
284
- alarmProps?.datapointsToAlarm ?? datapointsToAlarm,
285
- comparisonOperator:
286
- alarmProps?.comparisonOperator ?? comparisonOperator,
287
- })
288
- .addAlarmAction(alarmSnsAction);
289
- }
290
-
291
- private getAlarmActionForEnv(
292
- alarmAction: SnsAction,
293
- warningAction: SnsAction,
294
- production: boolean
295
- ): SnsAction {
296
- return production ? alarmAction : warningAction;
297
- }
298
- }
299
-
300
- export class MonitoredDBFunction {
301
- /**
302
- * Create new MonitoredDBFunction. Use topics from given DigitrafficStack. Generate names from given name and configuration shortName.
303
- * Grant secret and create log subscription.
304
- *
305
- * For example, shortName FOO and given name update-things will create function FOO-UpdateThings and use code from lambda/update-things/update-things.ts method handler.
306
- *
307
- * If you don't need to pass any extra arguments to lambda-environment, you can leave environment out and this function will create the
308
- * default Lambda Environment with SECRET_ID and DB_APPLICATION.
309
- *
310
- * @param stack DigitrafficStack
311
- * @param name param-case name
312
- * @param environment Lambda environment
313
- * @param functionParameters Lambda function parameters
314
- */
315
- static create(
316
- stack: DigitrafficStack,
317
- name: string,
318
- environment?: LambdaEnvironment,
319
- functionParameters?: Partial<MonitoredFunctionParameters>
320
- ): MonitoredFunction {
321
- const functionName =
322
- functionParameters?.functionName ??
323
- `${stack.configuration.shortName}-${_.chain(name)
324
- .camelCase()
325
- .startCase()
326
- .replace(/\s/g, "")
327
- .value()}`;
328
- const env = environment ? environment : stack.createLambdaEnvironment();
329
- const functionProps = databaseFunctionProps(
330
- stack,
331
- env,
332
- functionName,
333
- name,
334
- functionParameters
335
- );
336
-
337
- const mf = MonitoredFunction.create(
338
- stack,
339
- functionName,
340
- functionProps,
341
- functionParameters
342
- );
343
-
344
- stack.grantSecret(mf);
345
-
346
- if (stack.configuration.logsDestinationArn) {
347
- new DigitrafficLogSubscriptions(stack, mf);
348
- }
349
-
350
- return mf;
351
- }
352
- }
@@ -1,74 +0,0 @@
1
- import { StringParameter } from "aws-cdk-lib/aws-ssm";
2
- import { type Construct } from "constructs";
3
-
4
- const SSM_ROOT = "/digitraffic" as const;
5
- const MONITORING_ROOT = "/monitoring" as const;
6
- const DB_ROOT = "/db" as const;
7
-
8
- interface Parameter {
9
- readonly id?: string;
10
- readonly parameterName: string;
11
- readonly description?: string;
12
- }
13
-
14
- const PARAMETERS = {
15
- "topic.alarm": {
16
- parameterName: `${SSM_ROOT}${MONITORING_ROOT}/alarm-topic`,
17
- },
18
- "topic.warning": {
19
- parameterName: `${SSM_ROOT}${MONITORING_ROOT}/warning-topic`,
20
- },
21
- "cluster.reader": {
22
- id: "ClusterReaderEndpointParameter",
23
- parameterName: `${SSM_ROOT}${DB_ROOT}/reader-endpoint`,
24
- description: "Cluster reader endpoint",
25
- },
26
- "cluster.writer": {
27
- id: "ClusterWriterEndpointParameter",
28
- parameterName: `${SSM_ROOT}${DB_ROOT}/writer-endpoint`,
29
- description: "Cluster writer endpoint",
30
- },
31
- "cluster.identifier": {
32
- id: "ClusterIdentifierParameter",
33
- parameterName: `${SSM_ROOT}${DB_ROOT}/identifier`,
34
- description: "Cluster identifier",
35
- },
36
- "proxy.reader": {
37
- id: "ProxyReaderEndpointParameter",
38
- parameterName: `${SSM_ROOT}${DB_ROOT}/proxy-reader-endpoint`,
39
- description: "Proxy reader endpoint",
40
- },
41
- "proxy.writer": {
42
- id: "ProxyWriterEndpointParameter",
43
- parameterName: `${SSM_ROOT}${DB_ROOT}/proxy-writer-endpoint`,
44
- description: "Proxy writer endpoint",
45
- },
46
- } as const satisfies Record<string, Parameter>;
47
-
48
- export type ReadParameterType = keyof typeof PARAMETERS;
49
- export type WriteParameterType = Exclude<
50
- Exclude<ReadParameterType, "topic.alarm">,
51
- "topic.warning"
52
- >;
53
-
54
- export function getParameterValue(
55
- scope: Construct,
56
- parameterType: ReadParameterType
57
- ) {
58
- const parameterName = PARAMETERS[parameterType].parameterName;
59
- return StringParameter.valueForStringParameter(scope, parameterName);
60
- }
61
-
62
- export function createParameter(
63
- scope: Construct,
64
- parameterType: WriteParameterType,
65
- stringValue: string
66
- ): StringParameter {
67
- const { id, parameterName, description } = PARAMETERS[parameterType];
68
-
69
- return new StringParameter(scope, id, {
70
- parameterName,
71
- description,
72
- stringValue,
73
- });
74
- }