@gradientedge/cdk-utils-aws 1.0.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.
Files changed (288) hide show
  1. package/LICENSE +21 -0
  2. package/dist/src/common/construct.d.ts +85 -0
  3. package/dist/src/common/construct.js +125 -0
  4. package/dist/src/common/index.d.ts +4 -0
  5. package/dist/src/common/index.js +4 -0
  6. package/dist/src/common/resource-name-formatter.d.ts +13 -0
  7. package/dist/src/common/resource-name-formatter.js +30 -0
  8. package/dist/src/common/stack.d.ts +62 -0
  9. package/dist/src/common/stack.js +139 -0
  10. package/dist/src/common/types.d.ts +30 -0
  11. package/dist/src/common/types.js +1 -0
  12. package/dist/src/construct/api-to-any-target/index.d.ts +3 -0
  13. package/dist/src/construct/api-to-any-target/index.js +3 -0
  14. package/dist/src/construct/api-to-any-target/main.d.ts +47 -0
  15. package/dist/src/construct/api-to-any-target/main.js +154 -0
  16. package/dist/src/construct/api-to-any-target/target.d.ts +23 -0
  17. package/dist/src/construct/api-to-any-target/target.js +14 -0
  18. package/dist/src/construct/api-to-any-target/types.d.ts +60 -0
  19. package/dist/src/construct/api-to-any-target/types.js +1 -0
  20. package/dist/src/construct/api-to-eventbridge-target/api.d.ts +34 -0
  21. package/dist/src/construct/api-to-eventbridge-target/api.js +23 -0
  22. package/dist/src/construct/api-to-eventbridge-target/event.d.ts +15 -0
  23. package/dist/src/construct/api-to-eventbridge-target/event.js +12 -0
  24. package/dist/src/construct/api-to-eventbridge-target/index.d.ts +4 -0
  25. package/dist/src/construct/api-to-eventbridge-target/index.js +4 -0
  26. package/dist/src/construct/api-to-eventbridge-target/main.d.ts +121 -0
  27. package/dist/src/construct/api-to-eventbridge-target/main.js +442 -0
  28. package/dist/src/construct/api-to-eventbridge-target/types.d.ts +100 -0
  29. package/dist/src/construct/api-to-eventbridge-target/types.js +1 -0
  30. package/dist/src/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.d.ts +16 -0
  31. package/dist/src/construct/api-to-eventbridge-target-with-sns/api-destined-lambda.js +12 -0
  32. package/dist/src/construct/api-to-eventbridge-target-with-sns/index.d.ts +3 -0
  33. package/dist/src/construct/api-to-eventbridge-target-with-sns/index.js +3 -0
  34. package/dist/src/construct/api-to-eventbridge-target-with-sns/main.d.ts +159 -0
  35. package/dist/src/construct/api-to-eventbridge-target-with-sns/main.js +547 -0
  36. package/dist/src/construct/api-to-eventbridge-target-with-sns/types.d.ts +22 -0
  37. package/dist/src/construct/api-to-eventbridge-target-with-sns/types.js +1 -0
  38. package/dist/src/construct/api-to-lambda-target/api.d.ts +35 -0
  39. package/dist/src/construct/api-to-lambda-target/api.js +24 -0
  40. package/dist/src/construct/api-to-lambda-target/index.d.ts +3 -0
  41. package/dist/src/construct/api-to-lambda-target/index.js +3 -0
  42. package/dist/src/construct/api-to-lambda-target/main.d.ts +70 -0
  43. package/dist/src/construct/api-to-lambda-target/main.js +218 -0
  44. package/dist/src/construct/api-to-lambda-target/types.d.ts +62 -0
  45. package/dist/src/construct/api-to-lambda-target/types.js +1 -0
  46. package/dist/src/construct/application-configuration/index.d.ts +2 -0
  47. package/dist/src/construct/application-configuration/index.js +2 -0
  48. package/dist/src/construct/application-configuration/main.d.ts +23 -0
  49. package/dist/src/construct/application-configuration/main.js +79 -0
  50. package/dist/src/construct/application-configuration/types.d.ts +6 -0
  51. package/dist/src/construct/application-configuration/types.js +1 -0
  52. package/dist/src/construct/event-handler/handler.d.ts +29 -0
  53. package/dist/src/construct/event-handler/handler.js +21 -0
  54. package/dist/src/construct/event-handler/index.d.ts +3 -0
  55. package/dist/src/construct/event-handler/index.js +3 -0
  56. package/dist/src/construct/event-handler/main.d.ts +91 -0
  57. package/dist/src/construct/event-handler/main.js +196 -0
  58. package/dist/src/construct/event-handler/types.d.ts +41 -0
  59. package/dist/src/construct/event-handler/types.js +1 -0
  60. package/dist/src/construct/index.d.ts +14 -0
  61. package/dist/src/construct/index.js +14 -0
  62. package/dist/src/construct/lambda-with-iam-access/index.d.ts +2 -0
  63. package/dist/src/construct/lambda-with-iam-access/index.js +2 -0
  64. package/dist/src/construct/lambda-with-iam-access/main.d.ts +78 -0
  65. package/dist/src/construct/lambda-with-iam-access/main.js +182 -0
  66. package/dist/src/construct/lambda-with-iam-access/types.d.ts +20 -0
  67. package/dist/src/construct/lambda-with-iam-access/types.js +1 -0
  68. package/dist/src/construct/piped-event-handler/index.d.ts +2 -0
  69. package/dist/src/construct/piped-event-handler/index.js +2 -0
  70. package/dist/src/construct/piped-event-handler/main.d.ts +38 -0
  71. package/dist/src/construct/piped-event-handler/main.js +62 -0
  72. package/dist/src/construct/piped-event-handler/types.d.ts +9 -0
  73. package/dist/src/construct/piped-event-handler/types.js +1 -0
  74. package/dist/src/construct/rest-api-lambda/index.d.ts +2 -0
  75. package/dist/src/construct/rest-api-lambda/index.js +2 -0
  76. package/dist/src/construct/rest-api-lambda/main.d.ts +96 -0
  77. package/dist/src/construct/rest-api-lambda/main.js +170 -0
  78. package/dist/src/construct/rest-api-lambda/types.d.ts +23 -0
  79. package/dist/src/construct/rest-api-lambda/types.js +1 -0
  80. package/dist/src/construct/rest-api-lambda-with-cache/index.d.ts +2 -0
  81. package/dist/src/construct/rest-api-lambda-with-cache/index.js +2 -0
  82. package/dist/src/construct/rest-api-lambda-with-cache/main.d.ts +56 -0
  83. package/dist/src/construct/rest-api-lambda-with-cache/main.js +118 -0
  84. package/dist/src/construct/rest-api-lambda-with-cache/types.d.ts +11 -0
  85. package/dist/src/construct/rest-api-lambda-with-cache/types.js +1 -0
  86. package/dist/src/construct/site-with-ecs-backend/constants.d.ts +4 -0
  87. package/dist/src/construct/site-with-ecs-backend/constants.js +5 -0
  88. package/dist/src/construct/site-with-ecs-backend/index.d.ts +3 -0
  89. package/dist/src/construct/site-with-ecs-backend/index.js +3 -0
  90. package/dist/src/construct/site-with-ecs-backend/main.d.ts +154 -0
  91. package/dist/src/construct/site-with-ecs-backend/main.js +437 -0
  92. package/dist/src/construct/site-with-ecs-backend/types.d.ts +49 -0
  93. package/dist/src/construct/site-with-ecs-backend/types.js +1 -0
  94. package/dist/src/construct/site-with-lambda-backend/constants.d.ts +5 -0
  95. package/dist/src/construct/site-with-lambda-backend/constants.js +6 -0
  96. package/dist/src/construct/site-with-lambda-backend/index.d.ts +3 -0
  97. package/dist/src/construct/site-with-lambda-backend/index.js +3 -0
  98. package/dist/src/construct/site-with-lambda-backend/main.d.ts +116 -0
  99. package/dist/src/construct/site-with-lambda-backend/main.js +316 -0
  100. package/dist/src/construct/site-with-lambda-backend/types.d.ts +45 -0
  101. package/dist/src/construct/site-with-lambda-backend/types.js +1 -0
  102. package/dist/src/construct/static-asset-deployment/index.d.ts +2 -0
  103. package/dist/src/construct/static-asset-deployment/index.js +2 -0
  104. package/dist/src/construct/static-asset-deployment/main.d.ts +41 -0
  105. package/dist/src/construct/static-asset-deployment/main.js +113 -0
  106. package/dist/src/construct/static-asset-deployment/types.d.ts +41 -0
  107. package/dist/src/construct/static-asset-deployment/types.js +1 -0
  108. package/dist/src/construct/static-site/index.d.ts +2 -0
  109. package/dist/src/construct/static-site/index.js +2 -0
  110. package/dist/src/construct/static-site/main.d.ts +84 -0
  111. package/dist/src/construct/static-site/main.js +136 -0
  112. package/dist/src/construct/static-site/types.d.ts +30 -0
  113. package/dist/src/construct/static-site/types.js +1 -0
  114. package/dist/src/index.d.ts +5 -0
  115. package/dist/src/index.js +5 -0
  116. package/dist/src/services/api-gateway/index.d.ts +2 -0
  117. package/dist/src/services/api-gateway/index.js +2 -0
  118. package/dist/src/services/api-gateway/main.d.ts +68 -0
  119. package/dist/src/services/api-gateway/main.js +173 -0
  120. package/dist/src/services/api-gateway/types.d.ts +10 -0
  121. package/dist/src/services/api-gateway/types.js +1 -0
  122. package/dist/src/services/appconfig/constants.d.ts +12 -0
  123. package/dist/src/services/appconfig/constants.js +51 -0
  124. package/dist/src/services/appconfig/index.d.ts +3 -0
  125. package/dist/src/services/appconfig/index.js +3 -0
  126. package/dist/src/services/appconfig/main.d.ts +63 -0
  127. package/dist/src/services/appconfig/main.js +119 -0
  128. package/dist/src/services/appconfig/types.d.ts +17 -0
  129. package/dist/src/services/appconfig/types.js +1 -0
  130. package/dist/src/services/certificate-manager/index.d.ts +2 -0
  131. package/dist/src/services/certificate-manager/index.js +2 -0
  132. package/dist/src/services/certificate-manager/main.d.ts +41 -0
  133. package/dist/src/services/certificate-manager/main.js +62 -0
  134. package/dist/src/services/certificate-manager/types.d.ts +11 -0
  135. package/dist/src/services/certificate-manager/types.js +1 -0
  136. package/dist/src/services/cloudfront/index.d.ts +2 -0
  137. package/dist/src/services/cloudfront/index.js +2 -0
  138. package/dist/src/services/cloudfront/main.d.ts +96 -0
  139. package/dist/src/services/cloudfront/main.js +233 -0
  140. package/dist/src/services/cloudfront/types.d.ts +13 -0
  141. package/dist/src/services/cloudfront/types.js +1 -0
  142. package/dist/src/services/cloudtrail/index.d.ts +2 -0
  143. package/dist/src/services/cloudtrail/index.js +2 -0
  144. package/dist/src/services/cloudtrail/main.d.ts +44 -0
  145. package/dist/src/services/cloudtrail/main.js +71 -0
  146. package/dist/src/services/cloudtrail/types.d.ts +5 -0
  147. package/dist/src/services/cloudtrail/types.js +1 -0
  148. package/dist/src/services/cloudwatch/index.d.ts +3 -0
  149. package/dist/src/services/cloudwatch/index.js +3 -0
  150. package/dist/src/services/cloudwatch/logs.d.ts +47 -0
  151. package/dist/src/services/cloudwatch/logs.js +98 -0
  152. package/dist/src/services/cloudwatch/main.d.ts +207 -0
  153. package/dist/src/services/cloudwatch/main.js +552 -0
  154. package/dist/src/services/cloudwatch/types.d.ts +89 -0
  155. package/dist/src/services/cloudwatch/types.js +1 -0
  156. package/dist/src/services/codebuild/index.d.ts +1 -0
  157. package/dist/src/services/codebuild/index.js +1 -0
  158. package/dist/src/services/codebuild/main.d.ts +36 -0
  159. package/dist/src/services/codebuild/main.js +67 -0
  160. package/dist/src/services/constants.d.ts +4 -0
  161. package/dist/src/services/constants.js +5 -0
  162. package/dist/src/services/dynamodb/index.d.ts +2 -0
  163. package/dist/src/services/dynamodb/index.js +2 -0
  164. package/dist/src/services/dynamodb/main.d.ts +35 -0
  165. package/dist/src/services/dynamodb/main.js +72 -0
  166. package/dist/src/services/dynamodb/types.d.ts +10 -0
  167. package/dist/src/services/dynamodb/types.js +1 -0
  168. package/dist/src/services/elastic-container-registry/index.d.ts +1 -0
  169. package/dist/src/services/elastic-container-registry/index.js +1 -0
  170. package/dist/src/services/elastic-container-registry/main.d.ts +27 -0
  171. package/dist/src/services/elastic-container-registry/main.js +33 -0
  172. package/dist/src/services/elastic-container-service/index.d.ts +2 -0
  173. package/dist/src/services/elastic-container-service/index.js +2 -0
  174. package/dist/src/services/elastic-container-service/main.d.ts +56 -0
  175. package/dist/src/services/elastic-container-service/main.js +149 -0
  176. package/dist/src/services/elastic-container-service/types.d.ts +45 -0
  177. package/dist/src/services/elastic-container-service/types.js +1 -0
  178. package/dist/src/services/elastic-file-system/index.d.ts +2 -0
  179. package/dist/src/services/elastic-file-system/index.js +2 -0
  180. package/dist/src/services/elastic-file-system/main.d.ts +42 -0
  181. package/dist/src/services/elastic-file-system/main.js +76 -0
  182. package/dist/src/services/elastic-file-system/types.d.ts +15 -0
  183. package/dist/src/services/elastic-file-system/types.js +1 -0
  184. package/dist/src/services/elastic-kubernetes-service/index.d.ts +2 -0
  185. package/dist/src/services/elastic-kubernetes-service/index.js +2 -0
  186. package/dist/src/services/elastic-kubernetes-service/main.d.ts +32 -0
  187. package/dist/src/services/elastic-kubernetes-service/main.js +85 -0
  188. package/dist/src/services/elastic-kubernetes-service/types.d.ts +7 -0
  189. package/dist/src/services/elastic-kubernetes-service/types.js +1 -0
  190. package/dist/src/services/elasticache/index.d.ts +2 -0
  191. package/dist/src/services/elasticache/index.js +2 -0
  192. package/dist/src/services/elasticache/main.d.ts +47 -0
  193. package/dist/src/services/elasticache/main.js +90 -0
  194. package/dist/src/services/elasticache/types.d.ts +9 -0
  195. package/dist/src/services/elasticache/types.js +1 -0
  196. package/dist/src/services/eventbridge/index.d.ts +3 -0
  197. package/dist/src/services/eventbridge/index.js +3 -0
  198. package/dist/src/services/eventbridge/main.d.ts +93 -0
  199. package/dist/src/services/eventbridge/main.js +295 -0
  200. package/dist/src/services/eventbridge/target.d.ts +57 -0
  201. package/dist/src/services/eventbridge/target.js +61 -0
  202. package/dist/src/services/eventbridge/types.d.ts +43 -0
  203. package/dist/src/services/eventbridge/types.js +1 -0
  204. package/dist/src/services/evidently/index.d.ts +2 -0
  205. package/dist/src/services/evidently/index.js +2 -0
  206. package/dist/src/services/evidently/main.d.ts +56 -0
  207. package/dist/src/services/evidently/main.js +114 -0
  208. package/dist/src/services/evidently/types.d.ts +21 -0
  209. package/dist/src/services/evidently/types.js +1 -0
  210. package/dist/src/services/identity-access-management/index.d.ts +1 -0
  211. package/dist/src/services/identity-access-management/index.js +1 -0
  212. package/dist/src/services/identity-access-management/main.d.ts +263 -0
  213. package/dist/src/services/identity-access-management/main.js +609 -0
  214. package/dist/src/services/index.d.ts +28 -0
  215. package/dist/src/services/index.js +28 -0
  216. package/dist/src/services/key-management-service/index.d.ts +2 -0
  217. package/dist/src/services/key-management-service/index.js +2 -0
  218. package/dist/src/services/key-management-service/main.d.ts +28 -0
  219. package/dist/src/services/key-management-service/main.js +39 -0
  220. package/dist/src/services/key-management-service/types.d.ts +5 -0
  221. package/dist/src/services/key-management-service/types.js +1 -0
  222. package/dist/src/services/lambda/index.d.ts +2 -0
  223. package/dist/src/services/lambda/index.js +2 -0
  224. package/dist/src/services/lambda/main.d.ts +89 -0
  225. package/dist/src/services/lambda/main.js +232 -0
  226. package/dist/src/services/lambda/types.d.ts +54 -0
  227. package/dist/src/services/lambda/types.js +1 -0
  228. package/dist/src/services/route53/index.d.ts +2 -0
  229. package/dist/src/services/route53/index.js +2 -0
  230. package/dist/src/services/route53/main.d.ts +66 -0
  231. package/dist/src/services/route53/main.js +136 -0
  232. package/dist/src/services/route53/types.d.ts +6 -0
  233. package/dist/src/services/route53/types.js +1 -0
  234. package/dist/src/services/secrets-manager/index.d.ts +2 -0
  235. package/dist/src/services/secrets-manager/index.js +2 -0
  236. package/dist/src/services/secrets-manager/main.d.ts +43 -0
  237. package/dist/src/services/secrets-manager/main.js +71 -0
  238. package/dist/src/services/secrets-manager/types.d.ts +3 -0
  239. package/dist/src/services/secrets-manager/types.js +1 -0
  240. package/dist/src/services/simple-notification-service/index.d.ts +2 -0
  241. package/dist/src/services/simple-notification-service/index.js +2 -0
  242. package/dist/src/services/simple-notification-service/main.d.ts +38 -0
  243. package/dist/src/services/simple-notification-service/main.js +68 -0
  244. package/dist/src/services/simple-notification-service/types.d.ts +5 -0
  245. package/dist/src/services/simple-notification-service/types.js +1 -0
  246. package/dist/src/services/simple-queue-service/index.d.ts +2 -0
  247. package/dist/src/services/simple-queue-service/index.js +2 -0
  248. package/dist/src/services/simple-queue-service/main.d.ts +45 -0
  249. package/dist/src/services/simple-queue-service/main.js +101 -0
  250. package/dist/src/services/simple-queue-service/types.d.ts +15 -0
  251. package/dist/src/services/simple-queue-service/types.js +1 -0
  252. package/dist/src/services/simple-storage-service/index.d.ts +2 -0
  253. package/dist/src/services/simple-storage-service/index.js +2 -0
  254. package/dist/src/services/simple-storage-service/main.d.ts +79 -0
  255. package/dist/src/services/simple-storage-service/main.js +191 -0
  256. package/dist/src/services/simple-storage-service/types.d.ts +25 -0
  257. package/dist/src/services/simple-storage-service/types.js +1 -0
  258. package/dist/src/services/step-function/index.d.ts +2 -0
  259. package/dist/src/services/step-function/index.js +2 -0
  260. package/dist/src/services/step-function/main.d.ts +161 -0
  261. package/dist/src/services/step-function/main.js +380 -0
  262. package/dist/src/services/step-function/types.d.ts +88 -0
  263. package/dist/src/services/step-function/types.js +1 -0
  264. package/dist/src/services/systems-manager/index.d.ts +2 -0
  265. package/dist/src/services/systems-manager/index.js +2 -0
  266. package/dist/src/services/systems-manager/main.d.ts +55 -0
  267. package/dist/src/services/systems-manager/main.js +97 -0
  268. package/dist/src/services/systems-manager/types.d.ts +9 -0
  269. package/dist/src/services/systems-manager/types.js +1 -0
  270. package/dist/src/services/virtual-private-cloud/index.d.ts +2 -0
  271. package/dist/src/services/virtual-private-cloud/index.js +2 -0
  272. package/dist/src/services/virtual-private-cloud/ipv6.d.ts +7 -0
  273. package/dist/src/services/virtual-private-cloud/ipv6.js +38 -0
  274. package/dist/src/services/virtual-private-cloud/main.d.ts +43 -0
  275. package/dist/src/services/virtual-private-cloud/main.js +87 -0
  276. package/dist/src/services/virtual-private-cloud/types.d.ts +4 -0
  277. package/dist/src/services/virtual-private-cloud/types.js +1 -0
  278. package/dist/src/services/web-application-firewall/index.d.ts +2 -0
  279. package/dist/src/services/web-application-firewall/index.js +2 -0
  280. package/dist/src/services/web-application-firewall/main.d.ts +35 -0
  281. package/dist/src/services/web-application-firewall/main.js +61 -0
  282. package/dist/src/services/web-application-firewall/types.d.ts +9 -0
  283. package/dist/src/services/web-application-firewall/types.js +1 -0
  284. package/dist/src/types/index.d.ts +6 -0
  285. package/dist/src/types/index.js +1 -0
  286. package/dist/src/utils/index.d.ts +45 -0
  287. package/dist/src/utils/index.js +61 -0
  288. package/package.json +44 -0
@@ -0,0 +1,552 @@
1
+ import * as cdk from 'aws-cdk-lib';
2
+ import * as watch from 'aws-cdk-lib/aws-cloudwatch';
3
+ import _ from 'lodash';
4
+ import * as utils from '../../utils/index.js';
5
+ /**
6
+ */
7
+ var CloudWatchWidgetType;
8
+ (function (CloudWatchWidgetType) {
9
+ CloudWatchWidgetType["Text"] = "Text";
10
+ CloudWatchWidgetType["SingleValue"] = "SingleValue";
11
+ CloudWatchWidgetType["Gauge"] = "Gauge";
12
+ CloudWatchWidgetType["Graph"] = "Graph";
13
+ CloudWatchWidgetType["AlarmStatus"] = "AlarmStatus";
14
+ CloudWatchWidgetType["LogQuery"] = "LogQuery";
15
+ })(CloudWatchWidgetType || (CloudWatchWidgetType = {}));
16
+ /**
17
+ * @classdesc Provides operations on AWS CloudWatch.
18
+ * - A new instance of this class is injected into {@link CommonConstruct} constructor.
19
+ * - If a custom construct extends {@link CommonConstruct}, an instance is available within the context.
20
+ * @example
21
+ * import { CommonConstruct } from '@gradientedge/cdk-utils'
22
+ *
23
+ * class CustomConstruct extends CommonConstruct {
24
+ * constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
25
+ * super(parent, id, props)
26
+ * this.props = props
27
+ * this.cloudWatchManager.createAlarmForMetric('MyAlarm', this, metric)
28
+ * }
29
+ * }
30
+ * @see [CDK CloudWatch Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch-readme.html}
31
+ */
32
+ export class CloudWatchManager {
33
+ /**
34
+ * @summary Method to create a cloudwatch alarm for a given expression
35
+ * @param id scoped id of the resource
36
+ * @param scope scope in which this resource is defined
37
+ * @param props
38
+ */
39
+ createAlarmForExpression(id, scope, props) {
40
+ if (!props)
41
+ throw `Alarm props undefined for ${id}`;
42
+ if (!props.expression)
43
+ throw `Could not find expression for Alarm props for id:${id}`;
44
+ if (!props.metricProps)
45
+ throw `Could not find metricProps for Alarm props for id:${id}`;
46
+ const metrics = {};
47
+ _.map(this.determineMetrics(scope, props.metricProps), (metric, index) => {
48
+ metrics[`m${index}`] = metric;
49
+ });
50
+ const expression = new watch.MathExpression({
51
+ ...props,
52
+ expression: props.expression,
53
+ period: props.periodInSecs ? cdk.Duration.seconds(props.periodInSecs) : cdk.Duration.minutes(5),
54
+ usingMetrics: metrics,
55
+ });
56
+ const alarm = expression.createAlarm(scope, `${id}`, {
57
+ ...props,
58
+ });
59
+ utils.createCfnOutput(`${id}-alarmArn`, scope, alarm.alarmArn);
60
+ utils.createCfnOutput(`${id}-alarmName`, scope, alarm.alarmName);
61
+ return alarm;
62
+ }
63
+ /**
64
+ * @summary Method to create a cloudwatch alarm for a given metric
65
+ * @param id scoped id of the resource
66
+ * @param scope scope in which this resource is defined
67
+ * @param props
68
+ * @param metric
69
+ */
70
+ createAlarmForMetric(id, scope, props, metric) {
71
+ if (!props)
72
+ throw `Alarm props undefined for ${id}`;
73
+ const alarm = metric.createAlarm(scope, `${id}`, {
74
+ ...props,
75
+ });
76
+ utils.createCfnOutput(`${id}-alarmArn`, scope, alarm.alarmArn);
77
+ utils.createCfnOutput(`${id}-alarmName`, scope, alarm.alarmName);
78
+ return alarm;
79
+ }
80
+ /**
81
+ * @summary Method to create a cloudwatch dashboard
82
+ * @param id scoped id of the resource
83
+ * @param scope scope in which this resource is defined
84
+ * @param props
85
+ * @param widgets
86
+ */
87
+ createDashboard(id, scope, props, widgets) {
88
+ if (!props)
89
+ throw `Dashboard props undefined for ${id}`;
90
+ if (!props.dashboardName)
91
+ throw `Dashboard dashboardName undefined for ${id}`;
92
+ const dashboard = new watch.Dashboard(scope, `${id}`, {
93
+ ...props,
94
+ dashboardName: scope.resourceNameFormatter.format(props.dashboardName, scope.props.resourceNameOptions?.cloudwatch),
95
+ end: CloudWatchManager.determineTimeRange(props.end),
96
+ start: CloudWatchManager.determineTimeRange(props.start),
97
+ widgets,
98
+ });
99
+ utils.createCfnOutput(`${id}-dashboardName`, scope, props.dashboardName);
100
+ return dashboard;
101
+ }
102
+ /**
103
+ * @summary Method to create cloudwatch widgets
104
+ * @param scope scope in which this resource is defined
105
+ * @param props
106
+ */
107
+ createWidgets(scope, props) {
108
+ if (!props || props.length == 0)
109
+ throw `Widget props undefined`;
110
+ const widgets = [];
111
+ _.forEach(props, (widgetProps) => {
112
+ widgets.push(this.createWidget(widgetProps.id, scope, widgetProps));
113
+ });
114
+ return widgets;
115
+ }
116
+ /**
117
+ * @summary Method to create a cloudwatch widget
118
+ * @param id scoped id of the resource
119
+ * @param scope scope in which this resource is defined
120
+ * @param props
121
+ */
122
+ createWidget(id, scope, props) {
123
+ if (!props)
124
+ throw `Widget props undefined for ${id}`;
125
+ const metrics = this.determineMetrics(scope, props.metricProps);
126
+ let alarms, logGroupNames = [];
127
+ switch (props.type) {
128
+ case CloudWatchWidgetType.Text:
129
+ return this.createTextWidget(id, scope, props);
130
+ case CloudWatchWidgetType.SingleValue:
131
+ return this.createSingleValueWidget(id, scope, props, metrics);
132
+ case CloudWatchWidgetType.Gauge:
133
+ return this.createGuageWidget(id, scope, props, metrics);
134
+ case CloudWatchWidgetType.Graph:
135
+ return this.createGraphWidget(id, scope, props, metrics);
136
+ case CloudWatchWidgetType.AlarmStatus:
137
+ alarms = this.determineAlarms(id, scope, props.alarmProps);
138
+ return this.createAlarmStatusWidget(id, scope, props, alarms);
139
+ case CloudWatchWidgetType.LogQuery:
140
+ logGroupNames = props.logGroupNames.map((name) => `${name}-${scope.props.stage}`);
141
+ return this.createLogQueryWidget(id, scope, props, logGroupNames);
142
+ default:
143
+ throw `Unsupported widget type ${props.type}`;
144
+ }
145
+ }
146
+ /**
147
+ * @summary Method to create a cloudfront distribution widget
148
+ * @param id scoped id of the resource
149
+ * @param scope scope in which this resource is defined
150
+ * @param props
151
+ * @param distributionId the cloudfront distribution id
152
+ */
153
+ createCloudfrontDistributionWidget(id, scope, props, distributionId) {
154
+ if (!props)
155
+ throw `Widget props undefined for ${id}`;
156
+ const metricProps = props.metricProps;
157
+ return this.createWidget(id, scope, {
158
+ ...props,
159
+ metricProps: metricProps.map(metricProp => ({ ...metricProp, distributionId })),
160
+ });
161
+ }
162
+ /**
163
+ * @summary Method to create a step function widget
164
+ * @param id scoped id of the resource
165
+ * @param scope scope in which this resource is defined
166
+ * @param props
167
+ * @param stateMachineArn the step function arn
168
+ */
169
+ createStateWidget(id, scope, props, stateMachineArn) {
170
+ if (!props)
171
+ throw `Widget props undefined for ${id}`;
172
+ const metricProps = props.metricProps;
173
+ return this.createWidget(id, scope, {
174
+ ...props,
175
+ metricProps: metricProps.map(metricProp => ({ ...metricProp, stateMachineArn })),
176
+ });
177
+ }
178
+ /**
179
+ * @summary Method to create an event widget
180
+ * @param id scoped id of the resource
181
+ * @param scope scope in which this resource is defined
182
+ * @param props
183
+ * @param eventBusName the event bus name
184
+ * @param ruleName the event rule name
185
+ */
186
+ createEventWidget(id, scope, props, eventBusName, ruleName) {
187
+ if (!props)
188
+ throw `Widget props undefined for ${id}`;
189
+ const metricProps = props.metricProps;
190
+ return this.createWidget(id, scope, {
191
+ ...props,
192
+ metricProps: metricProps.map(metricProp => ({ ...metricProp, eventBusName, ruleName })),
193
+ });
194
+ }
195
+ /**
196
+ * @summary Method to create an api gateway widget
197
+ * @param id scoped id of the resource
198
+ * @param scope scope in which this resource is defined
199
+ * @param props
200
+ * @param apiName the api name
201
+ */
202
+ createApiGatewayWidget(id, scope, props, apiName) {
203
+ if (!props)
204
+ throw `Widget props undefined for ${id}`;
205
+ const metricProps = props.metricProps;
206
+ return this.createWidget(id, scope, {
207
+ ...props,
208
+ metricProps: metricProps.map(metricProp => ({ ...metricProp, apiName })),
209
+ });
210
+ }
211
+ /**
212
+ * @summary Method to create a lambda function widget
213
+ * @param id scoped id of the resource
214
+ * @param scope scope in which this resource is defined
215
+ * @param props
216
+ * @param functionName the lambda function name
217
+ */
218
+ createLambdaWidget(id, scope, props, functionName) {
219
+ if (!props)
220
+ throw `Widget props undefined for ${id}`;
221
+ const metricProps = props.metricProps;
222
+ return this.createWidget(id, scope, {
223
+ ...props,
224
+ metricProps: metricProps.map(metricProp => ({ ...metricProp, functionName })),
225
+ });
226
+ }
227
+ /**
228
+ * @summary Method to create a custom widget
229
+ * @param id scoped id of the resource
230
+ * @param scope scope in which this resource is defined
231
+ * @param props
232
+ * @param service the service identifier
233
+ */
234
+ createCustomWidget(id, scope, props, service) {
235
+ if (!props)
236
+ throw `Widget props undefined for ${id}`;
237
+ const metricProps = props.metricProps;
238
+ return this.createWidget(id, scope, {
239
+ ...props,
240
+ metricProps: metricProps.map(metricProp => ({ ...metricProp, service })),
241
+ });
242
+ }
243
+ /**
244
+ * @summary Method to create an ecs cluster widget
245
+ * @param id scoped id of the resource
246
+ * @param scope scope in which this resource is defined
247
+ * @param props
248
+ * @param clusterName the ecs cluster name
249
+ */
250
+ createEcsClusterWidget(id, scope, props, clusterName) {
251
+ if (!props)
252
+ throw `Widget props undefined for ${id}`;
253
+ const metricProps = props.metricProps;
254
+ return this.createWidget(id, scope, {
255
+ ...props,
256
+ metricProps: metricProps.map(metricProp => ({ ...metricProp, clusterName })),
257
+ });
258
+ }
259
+ /**
260
+ * @summary Method to create an ecs service widget
261
+ * @param id scoped id of the resource
262
+ * @param scope scope in which this resource is defined
263
+ * @param props
264
+ * @param clusterName the ecs cluster name
265
+ * @param serviceName the ecs service name
266
+ */
267
+ createEcsServiceWidget(id, scope, props, clusterName, serviceName) {
268
+ if (!props)
269
+ throw `Widget props undefined for ${id}`;
270
+ const metricProps = props.metricProps;
271
+ return this.createWidget(id, scope, {
272
+ ...props,
273
+ metricProps: metricProps.map(metricProp => ({ ...metricProp, clusterName, serviceName })),
274
+ });
275
+ }
276
+ /**
277
+ * @summary Method to create an elb widget
278
+ * @param id scoped id of the resource
279
+ * @param scope scope in which this resource is defined
280
+ * @param props
281
+ * @param loadBalancer the loadbalancer reference
282
+ */
283
+ createElbWidget(id, scope, props, loadBalancer) {
284
+ if (!props)
285
+ throw `Widget props undefined for ${id}`;
286
+ const metricProps = props.metricProps;
287
+ return this.createWidget(id, scope, {
288
+ ...props,
289
+ metricProps: metricProps.map(metricProp => ({ ...metricProp, loadBalancer })),
290
+ });
291
+ }
292
+ /**
293
+ * @summary Method to create an elasticache widget
294
+ * @param id scoped id of the resource
295
+ * @param scope scope in which this resource is defined
296
+ * @param props
297
+ * @param cacheClusterId the elasticache cluster id
298
+ */
299
+ createCacheWidget(id, scope, props, cacheClusterId) {
300
+ if (!props)
301
+ throw `Widget props undefined for ${id}`;
302
+ const metricProps = props.metricProps;
303
+ return this.createWidget(id, scope, {
304
+ ...props,
305
+ metricProps: metricProps.map(metricProp => ({ ...metricProp, cacheClusterId })),
306
+ });
307
+ }
308
+ /**
309
+ * @summary Method to create a cloudwatch text widget
310
+ * @param id scoped id of the resource
311
+ * @param scope scope in which this resource is defined
312
+ * @param props
313
+ */
314
+ createTextWidget(id, scope, props) {
315
+ if (!props)
316
+ throw `Widget props undefined for ${id}`;
317
+ const widget = new watch.TextWidget({
318
+ ...props,
319
+ });
320
+ if (props.positionX && props.positionY)
321
+ widget.position(props.positionX, props.positionY);
322
+ return widget;
323
+ }
324
+ /**
325
+ * @summary Method to create a cloudwatch numeric widget
326
+ * @param id scoped id of the resource
327
+ * @param scope scope in which this resource is defined
328
+ * @param props
329
+ * @param metrics
330
+ */
331
+ createSingleValueWidget(id, scope, props, metrics) {
332
+ if (!props)
333
+ throw `Widget props undefined for ${id}`;
334
+ const widget = new watch.SingleValueWidget({
335
+ ...props,
336
+ metrics,
337
+ region: props.region ?? scope.props.region,
338
+ });
339
+ if (props.positionX && props.positionY)
340
+ widget.position(props.positionX, props.positionY);
341
+ return widget;
342
+ }
343
+ /**
344
+ * @summary Method to create a cloudwatch guage widget
345
+ * @param id scoped id of the resource
346
+ * @param scope scope in which this resource is defined
347
+ * @param props
348
+ * @param metrics
349
+ */
350
+ createGuageWidget(id, scope, props, metrics) {
351
+ if (!props)
352
+ throw `Widget props undefined for ${id}`;
353
+ const widget = new watch.GaugeWidget({
354
+ ...props,
355
+ metrics,
356
+ region: props.region ?? scope.props.region,
357
+ });
358
+ if (props.positionX && props.positionY)
359
+ widget.position(props.positionX, props.positionY);
360
+ return widget;
361
+ }
362
+ /**
363
+ * @summary Method to create a cloudwatch graph widget
364
+ * @param id scoped id of the resource
365
+ * @param scope scope in which this resource is defined
366
+ * @param props
367
+ * @param leftYMetrics
368
+ * @param rightYMetrics
369
+ */
370
+ createGraphWidget(id, scope, props, leftYMetrics, rightYMetrics) {
371
+ if (!props)
372
+ throw `Widget props undefined for ${id}`;
373
+ const widget = new watch.GraphWidget({
374
+ ...props,
375
+ left: leftYMetrics,
376
+ region: props.region ?? scope.props.region,
377
+ right: rightYMetrics,
378
+ });
379
+ if (props.positionX && props.positionY)
380
+ widget.position(props.positionX, props.positionY);
381
+ return widget;
382
+ }
383
+ /**
384
+ * @summary Method to create a cloudwatch alarm status widget
385
+ * @param id scoped id of the resource
386
+ * @param scope scope in which this resource is defined
387
+ * @param props
388
+ * @param alarms
389
+ */
390
+ createAlarmStatusWidget(id, scope, props, alarms) {
391
+ if (!props)
392
+ throw `Widget props undefined for ${id}`;
393
+ const widget = new watch.AlarmStatusWidget({
394
+ ...props,
395
+ alarms,
396
+ });
397
+ if (props.positionX && props.positionY)
398
+ widget.position(props.positionX, props.positionY);
399
+ return widget;
400
+ }
401
+ /**
402
+ * @summary Method to create a cloudwatch log query widget
403
+ * @param id scoped id of the resource
404
+ * @param scope scope in which this resource is defined
405
+ * @param props
406
+ * @param logGroupNames
407
+ */
408
+ createLogQueryWidget(id, scope, props, logGroupNames) {
409
+ if (!props)
410
+ throw `Widget props undefined for ${id}`;
411
+ const widget = new watch.LogQueryWidget({
412
+ ...props,
413
+ logGroupNames,
414
+ region: props.region ?? scope.props.region,
415
+ });
416
+ if (props.positionX && props.positionY)
417
+ widget.position(props.positionX, props.positionY);
418
+ return widget;
419
+ }
420
+ /**
421
+ * @summary Utility method to determine the metrics and dimensions
422
+ * @param scope scope in which this resource is defined
423
+ * @param metricProps
424
+ */
425
+ determineMetrics(scope, metricProps) {
426
+ const metrics = [];
427
+ if (metricProps) {
428
+ metricProps.forEach((metricProp) => {
429
+ let metricDimensions = metricProp.dimensionsMap || {};
430
+ if (metricProp.functionName) {
431
+ metricDimensions = {
432
+ ...metricProp.dimensionsMap,
433
+ FunctionName: `${metricProp.functionName}`,
434
+ };
435
+ }
436
+ if (metricProp.serviceName && metricProp.clusterName) {
437
+ metricDimensions = {
438
+ ...metricProp.dimensionsMap,
439
+ ClusterName: `${metricProp.clusterName}`,
440
+ ServiceName: `${metricProp.serviceName}`,
441
+ };
442
+ }
443
+ if (!metricProp.serviceName && metricProp.clusterName) {
444
+ metricDimensions = {
445
+ ...metricProp.dimensionsMap,
446
+ ClusterName: `${metricProp.clusterName}`,
447
+ };
448
+ }
449
+ if (metricProp.serviceName && !metricProp.clusterName) {
450
+ metricDimensions = {
451
+ ...metricProp.dimensionsMap,
452
+ ServiceName: `${metricProp.serviceName}`,
453
+ };
454
+ }
455
+ if (metricProp.loadBalancer) {
456
+ metricDimensions = {
457
+ ...metricProp.dimensionsMap,
458
+ LoadBalancer: `${metricProp.loadBalancer}`,
459
+ };
460
+ }
461
+ if (metricProp.service) {
462
+ metricDimensions = {
463
+ ...metricProp.dimensionsMap,
464
+ service: `${metricProp.service}`,
465
+ };
466
+ }
467
+ if (metricProp.distributionId) {
468
+ metricDimensions = {
469
+ ...metricProp.dimensionsMap,
470
+ DistributionId: `${metricProp.distributionId}`,
471
+ Region: `Global`,
472
+ };
473
+ }
474
+ if (metricProp.apiName) {
475
+ metricDimensions = {
476
+ ...metricProp.dimensionsMap,
477
+ ApiName: `${metricProp.apiName}`,
478
+ };
479
+ }
480
+ if (metricProp.cacheClusterId) {
481
+ metricDimensions = {
482
+ ...metricProp.dimensionsMap,
483
+ CacheClusterId: `${metricProp.cacheClusterId}`,
484
+ };
485
+ }
486
+ if (metricProp.dbClusterIdentifier) {
487
+ metricDimensions = {
488
+ ...metricProp.dimensionsMap,
489
+ DBClusterIdentifier: `${metricProp.dbClusterIdentifier}`,
490
+ };
491
+ }
492
+ if (metricProp.stateMachineArn) {
493
+ metricDimensions = {
494
+ ...metricProp.dimensionsMap,
495
+ StateMachineArn: `${metricProp.stateMachineArn}`,
496
+ };
497
+ }
498
+ if (metricProp.eventBusName && metricProp.ruleName) {
499
+ metricDimensions = {
500
+ ...metricProp.dimensionsMap,
501
+ EventBusName: `${metricProp.eventBusName}`,
502
+ RuleName: `${metricProp.ruleName}`,
503
+ };
504
+ }
505
+ const metric = new watch.Metric({
506
+ dimensionsMap: metricDimensions,
507
+ metricName: metricProp.stageSuffix ? `${metricProp.metricName}-${scope.props.stage}` : metricProp.metricName,
508
+ namespace: metricProp.stageSuffix ? `${metricProp.namespace}-${scope.props.stage}` : metricProp.namespace,
509
+ period: metricProp.periodInSecs ? cdk.Duration.seconds(metricProp.periodInSecs) : cdk.Duration.minutes(5),
510
+ region: metricProp.region,
511
+ statistic: metricProp.statistic,
512
+ });
513
+ metrics.push(metric);
514
+ });
515
+ }
516
+ return metrics;
517
+ }
518
+ /**
519
+ * @summary Utility method to determine the time range
520
+ * @param range
521
+ */
522
+ static determineTimeRange(range) {
523
+ const moment = require('moment');
524
+ switch (range) {
525
+ case 'START_TODAY':
526
+ return moment().startOf('day').format();
527
+ case 'END_TODAY':
528
+ return moment().endOf('day').format();
529
+ default:
530
+ return range;
531
+ }
532
+ }
533
+ /**
534
+ * @summary Utility method to determine the configured alarms
535
+ * @param id scoped id of the resource
536
+ * @param scope scope in which this resource is defined
537
+ * @param alarmProps
538
+ */
539
+ determineAlarms(id, scope, alarmProps) {
540
+ const alarms = [];
541
+ if (alarmProps) {
542
+ _.forEach(alarmProps, (alarmProp) => {
543
+ if (!alarmProp.alarmName)
544
+ throw `Alarm name undefined for ${id}`;
545
+ const alarmArn = `arn:aws:cloudwatch:${cdk.Stack.of(scope).region}:${cdk.Stack.of(scope).account}:alarm:${alarmProp.alarmName}`;
546
+ const alarm = watch.Alarm.fromAlarmArn(scope, `${alarmProp.alarmName}`, alarmArn);
547
+ alarms.push(alarm);
548
+ });
549
+ }
550
+ return alarms;
551
+ }
552
+ }
@@ -0,0 +1,89 @@
1
+ import * as watch from 'aws-cdk-lib/aws-cloudwatch';
2
+ import * as logs from 'aws-cdk-lib/aws-logs';
3
+ import { TagProps } from '../../types/index.js';
4
+ /**
5
+ */
6
+ export interface AlarmProps extends watch.AlarmProps {
7
+ expression?: string;
8
+ metricProps?: MetricProps[];
9
+ periodInSecs?: number;
10
+ }
11
+ /**
12
+ */
13
+ export interface DashboardProps extends watch.DashboardProps {
14
+ }
15
+ /**
16
+ */
17
+ export interface MetricProps extends watch.MetricProps {
18
+ apiName?: string;
19
+ cacheClusterId?: string;
20
+ clusterName?: string;
21
+ dbClusterIdentifier?: string;
22
+ distributionId?: string;
23
+ eventBusName?: string;
24
+ functionName?: string;
25
+ loadBalancer?: string;
26
+ periodInSecs?: number;
27
+ ruleName?: string;
28
+ service?: string;
29
+ serviceName?: string;
30
+ stageSuffix: boolean;
31
+ stateMachineArn?: string;
32
+ }
33
+ /**
34
+ */
35
+ export interface TextWidgetProps extends watch.TextWidgetProps {
36
+ positionX: number;
37
+ positionY: number;
38
+ type: string;
39
+ }
40
+ /**
41
+ */
42
+ export interface NumericWidgetProps extends watch.SingleValueWidgetProps {
43
+ metricProps: watch.MetricProps[];
44
+ positionX: number;
45
+ positionY: number;
46
+ type: string;
47
+ }
48
+ /**
49
+ */
50
+ export interface GuageWidgetProps extends watch.GaugeWidgetProps {
51
+ metricProps: watch.MetricProps[];
52
+ positionX: number;
53
+ positionY: number;
54
+ type: string;
55
+ }
56
+ /**
57
+ */
58
+ export interface GraphWidgetProps extends watch.GraphWidgetProps {
59
+ metricProps: MetricProps[];
60
+ positionX: number;
61
+ positionY: number;
62
+ type: string;
63
+ }
64
+ /**
65
+ */
66
+ export interface AlarmStatusWidgetProps extends watch.AlarmStatusWidgetProps {
67
+ alarmProps: watch.AlarmProps[];
68
+ positionX: number;
69
+ positionY: number;
70
+ type: string;
71
+ }
72
+ /**
73
+ */
74
+ export interface LogQueryWidgetProps extends watch.LogQueryWidgetProps {
75
+ positionX: number;
76
+ positionY: number;
77
+ type: string;
78
+ }
79
+ /**
80
+ */
81
+ export interface MetricFilterProps extends logs.MetricFilterProps {
82
+ options: watch.MetricOptions;
83
+ periodInSecs: number;
84
+ }
85
+ /**
86
+ */
87
+ export interface LogProps extends logs.LogGroupProps {
88
+ tags?: TagProps[];
89
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export * from './main.js';
@@ -0,0 +1 @@
1
+ export * from './main.js';
@@ -0,0 +1,36 @@
1
+ import { Project } from 'aws-cdk-lib/aws-codebuild';
2
+ import { CommonConstruct } from '../../common/index.js';
3
+ /**
4
+ * @classdesc Provides operations on AWS Code Build.
5
+ * - A new instance of this class is injected into {@link CommonConstruct} constructor.
6
+ * - If a custom construct extends {@link CommonConstruct}, an instance is available within the context.
7
+ * @example
8
+ * import { CommonConstruct } from '@gradientedge/cdk-utils'
9
+ *
10
+ * class CustomConstruct extends CommonConstruct {
11
+ * constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
12
+ * super(parent, id, props)
13
+ * this.props = props
14
+ * this.codeBuildManager.createImageForCloudfrontInvalidation('MyInvalidation', this, './docker ')
15
+ * }
16
+ * }
17
+ * @see [CDK Codebuild Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codebuild-readme.html}
18
+ */
19
+ export declare class CodeBuildManager {
20
+ /**
21
+ *
22
+ * @param id
23
+ * @param scope
24
+ * @param dockerfilePath
25
+ */
26
+ createImageForCloudfrontInvalidation(id: string, scope: CommonConstruct, dockerfilePath: string): import("aws-cdk-lib/aws-ecr-assets").DockerImageAsset;
27
+ /**
28
+ *
29
+ * @param id
30
+ * @param scope
31
+ * @param dockerFilepath
32
+ * @param distributionId
33
+ * @param paths
34
+ */
35
+ createProjectForCloudfrontInvalidation(id: string, scope: CommonConstruct, dockerFilepath: string, distributionId: string, paths?: string): Project;
36
+ }