@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,28 @@
1
+ import { Key } from 'aws-cdk-lib/aws-kms';
2
+ import { CommonConstruct } from '../../common/index.js';
3
+ import { KmsKeyProps } from './types.js';
4
+ /**
5
+ * @classdesc Provides operations on AWS KMS.
6
+ * - A new instance of this class is injected into {@link CommonConstruct} constructor.
7
+ * - If a custom construct extends {@link CommonConstruct}, an instance is available within the context.
8
+ * @example
9
+ * import { CommonConstruct } from '@gradientedge/cdk-utils'
10
+ *
11
+ * class CustomConstruct extends CommonConstruct {
12
+ * constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
13
+ * super(parent, id, props)
14
+ * this.props = props
15
+ * this.kms.createKey('MyKey', this)
16
+ * }
17
+ * }
18
+ * @see [CDK KMS Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_kms-readme.html}
19
+ */
20
+ export declare class KmsManager {
21
+ /**
22
+ * @summary Method to create a KMS key
23
+ * @param id scoped id of the resource
24
+ * @param scope scope in which this resource is defined
25
+ * @param props KMS key props
26
+ */
27
+ createKey(id: string, scope: CommonConstruct, props: KmsKeyProps): Key;
28
+ }
@@ -0,0 +1,39 @@
1
+ import { Key } from 'aws-cdk-lib/aws-kms';
2
+ import { createCfnOutput } from '../../utils/index.js';
3
+ /**
4
+ * @classdesc Provides operations on AWS KMS.
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.kms.createKey('MyKey', this)
15
+ * }
16
+ * }
17
+ * @see [CDK KMS Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_kms-readme.html}
18
+ */
19
+ export class KmsManager {
20
+ /**
21
+ * @summary Method to create a KMS key
22
+ * @param id scoped id of the resource
23
+ * @param scope scope in which this resource is defined
24
+ * @param props KMS key props
25
+ */
26
+ createKey(id, scope, props) {
27
+ if (!props)
28
+ throw `KMS Key props undefined for ${id}`;
29
+ if (!props.alias)
30
+ throw `KMS Key alias undefined for ${id}`;
31
+ const key = new Key(scope, `${id}`, {
32
+ ...props,
33
+ alias: scope.resourceNameFormatter.format(props.alias, scope.props.resourceNameOptions?.kms),
34
+ });
35
+ createCfnOutput(`${id}-keyId`, scope, key.keyId);
36
+ createCfnOutput(`${id}-keyArn`, scope, key.keyArn);
37
+ return key;
38
+ }
39
+ }
@@ -0,0 +1,5 @@
1
+ import { KeyProps } from 'aws-cdk-lib/aws-kms';
2
+ /**
3
+ */
4
+ export interface KmsKeyProps extends KeyProps {
5
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './main.js';
2
+ export * from './types.js';
@@ -0,0 +1,2 @@
1
+ export * from './main.js';
2
+ export * from './types.js';
@@ -0,0 +1,89 @@
1
+ import { experimental } from 'aws-cdk-lib/aws-cloudfront';
2
+ import { ISecurityGroup, IVpc, SubnetSelection } from 'aws-cdk-lib/aws-ec2';
3
+ import { IAccessPoint } from 'aws-cdk-lib/aws-efs';
4
+ import { CfnRole, Role } from 'aws-cdk-lib/aws-iam';
5
+ import { Alias, Architecture, AssetCode, DockerImageCode, DockerImageFunction, Function, ILayerVersion, IVersion, LayerVersion } from 'aws-cdk-lib/aws-lambda';
6
+ import { CommonConstruct } from '../../common/index.js';
7
+ import { LambdaAliasProps, LambdaEdgeProps, LambdaProps } from './types.js';
8
+ /**
9
+ * @classdesc Provides operations on AWS Lambda
10
+ * - A new instance of this class is injected into {@link CommonConstruct} constructor.
11
+ * - If a custom construct extends {@link CommonConstruct}, an instance is available within the context.
12
+ * @example
13
+ * import { CommonConstruct } from '@gradientedge/cdk-utils'
14
+ *
15
+ * class CustomConstruct extends CommonConstruct {
16
+ * constructor(parent: Construct, id: string, props: common.CommonStackProps) {
17
+ * super(parent, id, props)
18
+ * this.props = props
19
+ * this.lambdaManager.createLambdaFunction('MyFunction', this, role, layers, code)
20
+ * }
21
+ * }
22
+ * @see [CDK Lambda Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda-readme.html}
23
+ */
24
+ export declare class LambdaManager {
25
+ /**
26
+ * @summary Method to create a lambda layer (nodejs)
27
+ * @param id scoped id of the resource
28
+ * @param scope scope in which this resource is defined
29
+ * @param code
30
+ * @param architectures
31
+ */
32
+ createLambdaLayer(id: string, scope: CommonConstruct, code: AssetCode, architectures?: Architecture[]): LayerVersion;
33
+ createWebAdapterLayer(id: string, scope: CommonConstruct): ILayerVersion[];
34
+ /**
35
+ * @summary Method to create a lambda function (nodejs)
36
+ * @param id scoped id of the resource
37
+ * @param scope scope in which this resource is defined
38
+ * @param props
39
+ * @param role
40
+ * @param layers
41
+ * @param code
42
+ * @param handler
43
+ * @param environment
44
+ * @param vpc
45
+ * @param securityGroups
46
+ * @param accessPoint
47
+ * @param mountPath
48
+ * @param vpcSubnets
49
+ */
50
+ createLambdaFunction(id: string, scope: CommonConstruct, props: LambdaProps, role: Role | CfnRole, layers: ILayerVersion[], code: AssetCode, handler?: string, environment?: any, vpc?: IVpc, securityGroups?: ISecurityGroup[], accessPoint?: IAccessPoint, mountPath?: string, vpcSubnets?: SubnetSelection): Function;
51
+ /**
52
+ * @summary Method to provision a Lambda@Edge function
53
+ * @param id scoped id of the resource
54
+ * @param scope scope in which this resource is defined
55
+ * @param props lambda@edge properties
56
+ * @param layers
57
+ * @param code
58
+ * @param role
59
+ * @param environment
60
+ * @param vpc
61
+ * @param securityGroups
62
+ * @param accessPoint
63
+ * @param mountPath
64
+ */
65
+ createEdgeFunction(id: string, scope: CommonConstruct, props: LambdaEdgeProps, layers: ILayerVersion[], code: AssetCode, role: Role, environment?: any, vpc?: IVpc, securityGroups?: ISecurityGroup[], accessPoint?: IAccessPoint, mountPath?: string): experimental.EdgeFunction;
66
+ /**
67
+ * @summary Method to create a lambda function (nodejs) with docker image
68
+ * @param id scoped id of the resource
69
+ * @param scope scope in which this resource is defined
70
+ * @param props
71
+ * @param role
72
+ * @param code
73
+ * @param environment
74
+ * @param vpc
75
+ * @param securityGroups
76
+ * @param accessPoint
77
+ * @param mountPath
78
+ * @param vpcSubnets
79
+ */
80
+ createLambdaDockerFunction(id: string, scope: CommonConstruct, props: LambdaProps, role: Role | CfnRole, code: DockerImageCode, environment?: any, vpc?: IVpc, securityGroups?: ISecurityGroup[], accessPoint?: IAccessPoint, mountPath?: string, vpcSubnets?: SubnetSelection): DockerImageFunction;
81
+ /**
82
+ * @summary Method to create a lambda function Alias
83
+ * @param id scoped id of the resource
84
+ * @param scope scope in which this resource is defined
85
+ * @param props
86
+ * @param lambdaVersion
87
+ */
88
+ createLambdaFunctionAlias(id: string, scope: CommonConstruct, props: LambdaAliasProps, lambdaVersion: IVersion): Alias;
89
+ }
@@ -0,0 +1,232 @@
1
+ import { Duration, RemovalPolicy, Tags } from 'aws-cdk-lib';
2
+ import { Role } from 'aws-cdk-lib/aws-iam';
3
+ import { Alias, Architecture, DockerImageFunction, FileSystem, Function, LayerVersion, } from 'aws-cdk-lib/aws-lambda';
4
+ import { SqsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources';
5
+ import _ from 'lodash';
6
+ import { CommonStack } from '../../common/index.js';
7
+ import { createCfnOutput } from '../../utils/index.js';
8
+ import { CloudFrontManager } from '../cloudfront/index.js';
9
+ /**
10
+ * @classdesc Provides operations on AWS Lambda
11
+ * - A new instance of this class is injected into {@link CommonConstruct} constructor.
12
+ * - If a custom construct extends {@link CommonConstruct}, an instance is available within the context.
13
+ * @example
14
+ * import { CommonConstruct } from '@gradientedge/cdk-utils'
15
+ *
16
+ * class CustomConstruct extends CommonConstruct {
17
+ * constructor(parent: Construct, id: string, props: common.CommonStackProps) {
18
+ * super(parent, id, props)
19
+ * this.props = props
20
+ * this.lambdaManager.createLambdaFunction('MyFunction', this, role, layers, code)
21
+ * }
22
+ * }
23
+ * @see [CDK Lambda Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda-readme.html}
24
+ */
25
+ export class LambdaManager {
26
+ /**
27
+ * @summary Method to create a lambda layer (nodejs)
28
+ * @param id scoped id of the resource
29
+ * @param scope scope in which this resource is defined
30
+ * @param code
31
+ * @param architectures
32
+ */
33
+ createLambdaLayer(id, scope, code, architectures) {
34
+ const lambdaLayer = new LayerVersion(scope, `${id}`, {
35
+ code: code,
36
+ compatibleArchitectures: architectures ?? [Architecture.ARM_64],
37
+ compatibleRuntimes: [scope.props.nodejsRuntime ?? CommonStack.NODEJS_RUNTIME],
38
+ description: `${id}`,
39
+ layerVersionName: scope.resourceNameFormatter.format(id, scope.props.resourceNameOptions?.lambdaLayer),
40
+ });
41
+ createCfnOutput(`${id}-lambdaLayerArn`, scope, lambdaLayer.layerVersionArn);
42
+ return lambdaLayer;
43
+ }
44
+ createWebAdapterLayer(id, scope) {
45
+ return [
46
+ LayerVersion.fromLayerVersionArn(scope, `${id}-${Architecture.X86_64}`, `arn:aws:lambda:${scope.props.region}:753240598075:layer:LambdaAdapterLayerX86:17`),
47
+ LayerVersion.fromLayerVersionArn(scope, `${id}-${Architecture.ARM_64}`, `arn:aws:lambda:${scope.props.region}:753240598075:layer:LambdaAdapterLayerArm64:17`),
48
+ ];
49
+ }
50
+ /**
51
+ * @summary Method to create a lambda function (nodejs)
52
+ * @param id scoped id of the resource
53
+ * @param scope scope in which this resource is defined
54
+ * @param props
55
+ * @param role
56
+ * @param layers
57
+ * @param code
58
+ * @param handler
59
+ * @param environment
60
+ * @param vpc
61
+ * @param securityGroups
62
+ * @param accessPoint
63
+ * @param mountPath
64
+ * @param vpcSubnets
65
+ */
66
+ createLambdaFunction(id, scope, props, role, layers, code, handler, environment, vpc, securityGroups, accessPoint, mountPath, vpcSubnets) {
67
+ if (!props)
68
+ throw `Lambda props undefined for ${id}`;
69
+ if (!props.functionName)
70
+ throw `Lambda functionName undefined for ${id}`;
71
+ const functionName = scope.resourceNameFormatter.format(props.functionName, scope.props.resourceNameOptions?.lambdaFunction);
72
+ let deadLetterQueue;
73
+ if (props.deadLetterQueueEnabled) {
74
+ const redriveQueue = scope.sqsManager.createRedriveQueueForLambda(`${id}-rdq`, scope, props);
75
+ deadLetterQueue = scope.sqsManager.createDeadLetterQueueForLambda(`${id}-dlq`, scope, props, redriveQueue);
76
+ }
77
+ const lambdaFunction = new Function(scope, `${id}`, {
78
+ ...props,
79
+ allowPublicSubnet: !!vpc,
80
+ architecture: props.architecture ?? Architecture.ARM_64,
81
+ code,
82
+ deadLetterQueue,
83
+ environment: {
84
+ LOG_LEVEL: props.logLevel,
85
+ REGION: scope.props.region,
86
+ STAGE: scope.props.stage,
87
+ ...environment,
88
+ },
89
+ filesystem: accessPoint ? FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg') : undefined,
90
+ functionName,
91
+ handler: handler || 'index.lambda_handler',
92
+ layers,
93
+ logGroup: scope.logManager.createLogGroup(`${id}-log-group`, scope, {
94
+ logGroupName: functionName,
95
+ removalPolicy: RemovalPolicy.DESTROY,
96
+ retention: scope.props.logRetention ?? props.logRetentionInDays,
97
+ }),
98
+ reservedConcurrentExecutions: props.reservedConcurrentExecutions ?? scope.props.defaultReservedLambdaConcurrentExecutions,
99
+ role: role instanceof Role ? role : undefined,
100
+ runtime: props.runtime ?? scope.props.nodejsRuntime ?? CommonStack.NODEJS_RUNTIME,
101
+ securityGroups,
102
+ timeout: props.timeoutInSecs ? Duration.seconds(props.timeoutInSecs) : Duration.minutes(15),
103
+ tracing: scope.props.defaultTracing ?? props.tracing,
104
+ vpc,
105
+ vpcSubnets,
106
+ });
107
+ if (lambdaFunction.deadLetterQueue && props.dlq?.retriesEnabled) {
108
+ lambdaFunction.addEventSource(new SqsEventSource(lambdaFunction.deadLetterQueue, {
109
+ batchSize: props.dlq.retryBatchSize ?? 1,
110
+ reportBatchItemFailures: true,
111
+ }));
112
+ }
113
+ if (props.lambdaAliases && !_.isEmpty(props.lambdaAliases)) {
114
+ props.lambdaAliases.forEach(alias => {
115
+ const aliasId = alias.id ?? `${id}-${alias.aliasName}`;
116
+ const functionAlias = this.createLambdaFunctionAlias(`${aliasId}`, scope, alias, lambdaFunction.currentVersion);
117
+ createCfnOutput(`${id}-${alias.aliasName}AliasArn`, scope, functionAlias.functionArn);
118
+ createCfnOutput(`${id}-${alias.aliasName}AliasName`, scope, functionAlias.aliasName);
119
+ if (alias.provisionedConcurrency) {
120
+ const functionAutoScaling = functionAlias.addAutoScaling(alias.provisionedConcurrency);
121
+ functionAutoScaling.scaleOnUtilization({
122
+ utilizationTarget: alias.provisionedConcurrency.utilizationTarget,
123
+ });
124
+ }
125
+ });
126
+ }
127
+ if (props.tags && !_.isEmpty(props.tags)) {
128
+ _.forEach(props.tags, tag => {
129
+ Tags.of(lambdaFunction).add(tag.key, tag.value);
130
+ });
131
+ }
132
+ createCfnOutput(`${id}-lambdaArn`, scope, lambdaFunction.functionArn);
133
+ createCfnOutput(`${id}-lambdaName`, scope, lambdaFunction.functionName);
134
+ return lambdaFunction;
135
+ }
136
+ /**
137
+ * @summary Method to provision a Lambda@Edge function
138
+ * @param id scoped id of the resource
139
+ * @param scope scope in which this resource is defined
140
+ * @param props lambda@edge properties
141
+ * @param layers
142
+ * @param code
143
+ * @param role
144
+ * @param environment
145
+ * @param vpc
146
+ * @param securityGroups
147
+ * @param accessPoint
148
+ * @param mountPath
149
+ */
150
+ createEdgeFunction(id, scope, props, layers, code, role, environment, vpc, securityGroups, accessPoint, mountPath) {
151
+ return new CloudFrontManager().createEdgeFunction(id, scope, props, layers, code, role, environment, vpc, securityGroups, accessPoint, mountPath);
152
+ }
153
+ /**
154
+ * @summary Method to create a lambda function (nodejs) with docker image
155
+ * @param id scoped id of the resource
156
+ * @param scope scope in which this resource is defined
157
+ * @param props
158
+ * @param role
159
+ * @param code
160
+ * @param environment
161
+ * @param vpc
162
+ * @param securityGroups
163
+ * @param accessPoint
164
+ * @param mountPath
165
+ * @param vpcSubnets
166
+ */
167
+ createLambdaDockerFunction(id, scope, props, role, code, environment, vpc, securityGroups, accessPoint, mountPath, vpcSubnets) {
168
+ if (!props)
169
+ throw `Lambda props undefined for ${id}`;
170
+ if (!props.functionName)
171
+ throw `Lambda functionName undefined for ${id}`;
172
+ const functionName = scope.resourceNameFormatter.format(props.functionName, scope.props.resourceNameOptions?.lambdaFunction);
173
+ let deadLetterQueue;
174
+ if (props.deadLetterQueueEnabled) {
175
+ const redriveQueue = scope.sqsManager.createRedriveQueueForLambda(`${id}-rdq`, scope, props);
176
+ deadLetterQueue = scope.sqsManager.createDeadLetterQueueForLambda(`${id}-dlq`, scope, props, redriveQueue);
177
+ }
178
+ const lambdaFunction = new DockerImageFunction(scope, `${id}`, {
179
+ ...props,
180
+ allowPublicSubnet: !!vpc,
181
+ architecture: props.architecture ?? Architecture.ARM_64,
182
+ code,
183
+ deadLetterQueue,
184
+ environment: {
185
+ LOG_LEVEL: props.logLevel,
186
+ REGION: scope.props.region,
187
+ STAGE: scope.props.stage,
188
+ ...environment,
189
+ },
190
+ filesystem: accessPoint ? FileSystem.fromEfsAccessPoint(accessPoint, mountPath || '/mnt/msg') : undefined,
191
+ functionName,
192
+ logGroup: scope.logManager.createLogGroup(`${id}-log-group`, scope, {
193
+ logGroupName: functionName,
194
+ removalPolicy: RemovalPolicy.DESTROY,
195
+ retention: scope.props.logRetention ?? props.logRetentionInDays,
196
+ }),
197
+ role: role instanceof Role ? role : undefined,
198
+ securityGroups: securityGroups,
199
+ timeout: props.timeoutInSecs ? Duration.seconds(props.timeoutInSecs) : Duration.minutes(1),
200
+ tracing: props.tracing,
201
+ vpc,
202
+ vpcSubnets,
203
+ });
204
+ if (lambdaFunction.deadLetterQueue && props.dlq?.retriesEnabled) {
205
+ lambdaFunction.addEventSource(new SqsEventSource(lambdaFunction.deadLetterQueue, {
206
+ batchSize: props.dlq.retryBatchSize ?? 1,
207
+ reportBatchItemFailures: true,
208
+ }));
209
+ }
210
+ createCfnOutput(`${id}-lambdaArn`, scope, lambdaFunction.functionArn);
211
+ createCfnOutput(`${id}-lambdaName`, scope, lambdaFunction.functionName);
212
+ return lambdaFunction;
213
+ }
214
+ /**
215
+ * @summary Method to create a lambda function Alias
216
+ * @param id scoped id of the resource
217
+ * @param scope scope in which this resource is defined
218
+ * @param props
219
+ * @param lambdaVersion
220
+ */
221
+ createLambdaFunctionAlias(id, scope, props, lambdaVersion) {
222
+ if (!props)
223
+ throw `Lambda Alias props undefined for ${id}`;
224
+ const lambdaFunctionAlias = new Alias(scope, `${id}`, {
225
+ ...props,
226
+ version: lambdaVersion,
227
+ });
228
+ createCfnOutput(`${id}-lambdaAliasName`, scope, lambdaFunctionAlias.functionArn);
229
+ createCfnOutput(`${id}-lambdaAliasArn`, scope, lambdaFunctionAlias.functionName);
230
+ return lambdaFunctionAlias;
231
+ }
232
+ }
@@ -0,0 +1,54 @@
1
+ import { AliasProps, FunctionProps } from 'aws-cdk-lib/aws-lambda';
2
+ import { SqsEventSourceProps } from 'aws-cdk-lib/aws-lambda-event-sources';
3
+ import { TagProps } from '../../types/index.js';
4
+ import { QueueProps } from '../simple-queue-service/index.js';
5
+ /**
6
+ * Props for Lambda@Edge function, matching aws-cdk-lib experimental EdgeFunctionProps.
7
+ * Inlined because aws-cdk-lib does not export this subpath via its package exports map.
8
+ */
9
+ export interface EdgeFunctionProps extends FunctionProps {
10
+ readonly stackId?: string;
11
+ }
12
+ /**
13
+ */
14
+ export interface ProvisionedConcurrencyProps {
15
+ maxCapacity: number;
16
+ minCapacity: number;
17
+ utilizationTarget: number;
18
+ }
19
+ /**
20
+ */
21
+ export interface LambdaProps extends FunctionProps {
22
+ dlq?: QueueProps;
23
+ excludeLastModifiedTimestamp?: boolean;
24
+ lambdaAliases?: LambdaAliasProps[];
25
+ logLevel?: string;
26
+ logRetentionInDays?: number;
27
+ redriveq?: QueueProps;
28
+ tags?: TagProps[];
29
+ timeoutInSecs?: number;
30
+ }
31
+ /**
32
+ */
33
+ export interface LambdaAliasProps extends AliasProps {
34
+ id?: string;
35
+ provisionedConcurrency?: ProvisionedConcurrencyProps;
36
+ }
37
+ /**
38
+ */
39
+ export interface LambdaEdgeProps extends EdgeFunctionProps {
40
+ tags?: TagProps[];
41
+ timeoutInSecs?: number;
42
+ }
43
+ /**
44
+ */
45
+ export interface LambdaEnvironment {
46
+ LOG_LEVEL: string;
47
+ NODE_ENV: string;
48
+ REGION?: string;
49
+ STAGE?: string;
50
+ TZ: string;
51
+ }
52
+ export interface SQSEventSourceProps extends SqsEventSourceProps {
53
+ maxBatchingWindowInSecs: number;
54
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './main.js';
2
+ export * from './types.js';
@@ -0,0 +1,2 @@
1
+ export * from './main.js';
2
+ export * from './types.js';
@@ -0,0 +1,66 @@
1
+ import { DomainName } from 'aws-cdk-lib/aws-apigateway';
2
+ import { IDistribution } from 'aws-cdk-lib/aws-cloudfront';
3
+ import { ARecord, IHostedZone } from 'aws-cdk-lib/aws-route53';
4
+ import { CommonConstruct } from '../../common/index.js';
5
+ import { Route53Props } from './types.js';
6
+ /**
7
+ * @classdesc Provides operations on AWS Route53
8
+ * - A new instance of this class is injected into {@link CommonConstruct} constructor.
9
+ * - If a custom construct extends {@link CommonConstruct}, an instance is available within the context.
10
+ * @example
11
+ * import { CommonConstruct } from '@gradientedge/cdk-utils'
12
+ *
13
+ * class CustomConstruct extends CommonConstruct {
14
+ * constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
15
+ * super(parent, id, props)
16
+ * this.props = props
17
+ * this.route53Manager.createHostedZone('MyHostedZone', this)
18
+ * }
19
+ * }
20
+ * @see [CDK Route53 Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_route53-readme.html}
21
+ */
22
+ export declare class Route53Manager {
23
+ /**
24
+ * @summary Method to create a hosted zone
25
+ * @param id scoped id of the resource
26
+ * @param scope scope in which this resource is defined
27
+ * @param props
28
+ */
29
+ createHostedZone(id: string, scope: CommonConstruct, props: Route53Props): IHostedZone;
30
+ /**
31
+ * @summary Method to create/lookup a hosted zone
32
+ * @param id scoped id of the resource
33
+ * @param scope scope in which this resource is defined
34
+ * @param useExistingHostedZone Flag to indicate whether to lookup vs create new hosted zone
35
+ */
36
+ withHostedZoneFromFullyQualifiedDomainName(id: string, scope: CommonConstruct, useExistingHostedZone: boolean): IHostedZone;
37
+ /**
38
+ * @summary Method to create a-record for cloudfront target
39
+ * @param id scoped id of the resource
40
+ * @param scope scope in which this resource is defined
41
+ * @param distribution
42
+ * @param hostedZone
43
+ * @param recordName
44
+ * @param skipStageFromRecord
45
+ */
46
+ createCloudFrontTargetARecord(id: string, scope: CommonConstruct, distribution?: IDistribution, hostedZone?: IHostedZone, recordName?: string, skipStageFromRecord?: boolean): ARecord;
47
+ /**
48
+ * @summary Method to create a-record for cloudfront target
49
+ * @param id scoped id of the resource
50
+ * @param scope scope in which this resource is defined
51
+ * @param distribution
52
+ * @param hostedZone
53
+ * @param recordName
54
+ */
55
+ createCloudFrontTargetARecordV2(id: string, scope: CommonConstruct, distribution?: IDistribution, hostedZone?: IHostedZone, recordName?: string): ARecord;
56
+ /**
57
+ * @summary Method to create a-record for restApi gateway target
58
+ * @param id scoped id of the resource
59
+ * @param scope scope in which this resource is defined
60
+ * @param recordName
61
+ * @param apiDomain
62
+ * @param hostedZone
63
+ * @param skipStageFromRecord
64
+ */
65
+ createApiGatewayARecord(id: string, scope: CommonConstruct, recordName: string, apiDomain: DomainName, hostedZone: IHostedZone, skipStageFromRecord?: boolean): ARecord;
66
+ }
@@ -0,0 +1,136 @@
1
+ import { ARecord, HostedZone, RecordTarget } from 'aws-cdk-lib/aws-route53';
2
+ import { ApiGatewayDomain, CloudFrontTarget } from 'aws-cdk-lib/aws-route53-targets';
3
+ import { createCfnOutput } from '../../utils/index.js';
4
+ /**
5
+ * @classdesc Provides operations on AWS Route53
6
+ * - A new instance of this class is injected into {@link CommonConstruct} constructor.
7
+ * - If a custom construct extends {@link CommonConstruct}, an instance is available within the context.
8
+ * @example
9
+ * import { CommonConstruct } from '@gradientedge/cdk-utils'
10
+ *
11
+ * class CustomConstruct extends CommonConstruct {
12
+ * constructor(parent: cdk.Construct, id: string, props: common.CommonStackProps) {
13
+ * super(parent, id, props)
14
+ * this.props = props
15
+ * this.route53Manager.createHostedZone('MyHostedZone', this)
16
+ * }
17
+ * }
18
+ * @see [CDK Route53 Module]{@link https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_route53-readme.html}
19
+ */
20
+ export class Route53Manager {
21
+ /**
22
+ * @summary Method to create a hosted zone
23
+ * @param id scoped id of the resource
24
+ * @param scope scope in which this resource is defined
25
+ * @param props
26
+ */
27
+ createHostedZone(id, scope, props) {
28
+ let hostedZone;
29
+ if (!props)
30
+ throw `Route53 props undefined for ${id}`;
31
+ if (props.useExistingHostedZone) {
32
+ hostedZone = HostedZone.fromLookup(scope, `${id}`, {
33
+ domainName: scope.props.domainName,
34
+ });
35
+ }
36
+ else {
37
+ hostedZone = new HostedZone(scope, `${id}`, {
38
+ comment: `Hosted zone for ${scope.props.domainName}`,
39
+ zoneName: scope.props.domainName,
40
+ });
41
+ }
42
+ createCfnOutput(`${id}-hostedZoneId`, scope, hostedZone.hostedZoneId);
43
+ createCfnOutput(`${id}-hostedZoneArn`, scope, hostedZone.hostedZoneArn);
44
+ return hostedZone;
45
+ }
46
+ /**
47
+ * @summary Method to create/lookup a hosted zone
48
+ * @param id scoped id of the resource
49
+ * @param scope scope in which this resource is defined
50
+ * @param useExistingHostedZone Flag to indicate whether to lookup vs create new hosted zone
51
+ */
52
+ withHostedZoneFromFullyQualifiedDomainName(id, scope, useExistingHostedZone) {
53
+ let hostedZone;
54
+ if (useExistingHostedZone) {
55
+ hostedZone = HostedZone.fromLookup(scope, `${id}`, {
56
+ domainName: scope.fullyQualifiedDomainName,
57
+ });
58
+ }
59
+ else {
60
+ hostedZone = new HostedZone(scope, `${id}`, {
61
+ comment: `Hosted zone for ${scope.fullyQualifiedDomainName}`,
62
+ zoneName: scope.fullyQualifiedDomainName,
63
+ });
64
+ }
65
+ createCfnOutput(`${id}-hostedZoneId`, scope, hostedZone.hostedZoneId);
66
+ createCfnOutput(`${id}-hostedZoneArn`, scope, hostedZone.hostedZoneArn);
67
+ return hostedZone;
68
+ }
69
+ /**
70
+ * @summary Method to create a-record for cloudfront target
71
+ * @param id scoped id of the resource
72
+ * @param scope scope in which this resource is defined
73
+ * @param distribution
74
+ * @param hostedZone
75
+ * @param recordName
76
+ * @param skipStageFromRecord
77
+ */
78
+ createCloudFrontTargetARecord(id, scope, distribution, hostedZone, recordName, skipStageFromRecord) {
79
+ if (!distribution)
80
+ throw `Distribution undefined for ${id}`;
81
+ if (!hostedZone)
82
+ throw `HostedZone undefined for ${id}`;
83
+ const aRecord = new ARecord(scope, `${id}`, {
84
+ recordName: (recordName && scope.isProductionStage()) || skipStageFromRecord
85
+ ? `${recordName}`
86
+ : `${recordName}-${scope.props.stage}`,
87
+ target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),
88
+ zone: hostedZone,
89
+ });
90
+ createCfnOutput(`${id}-aRecordDomainName`, scope, aRecord.domainName);
91
+ return aRecord;
92
+ }
93
+ /**
94
+ * @summary Method to create a-record for cloudfront target
95
+ * @param id scoped id of the resource
96
+ * @param scope scope in which this resource is defined
97
+ * @param distribution
98
+ * @param hostedZone
99
+ * @param recordName
100
+ */
101
+ createCloudFrontTargetARecordV2(id, scope, distribution, hostedZone, recordName) {
102
+ if (!distribution)
103
+ throw `Distribution undefined for ${id}`;
104
+ if (!hostedZone)
105
+ throw `HostedZone undefined for ${id}`;
106
+ const aRecord = new ARecord(scope, `${id}`, {
107
+ recordName: recordName,
108
+ target: RecordTarget.fromAlias(new CloudFrontTarget(distribution)),
109
+ zone: hostedZone,
110
+ });
111
+ createCfnOutput(`${id}-aRecordDomainName`, scope, aRecord.domainName);
112
+ return aRecord;
113
+ }
114
+ /**
115
+ * @summary Method to create a-record for restApi gateway target
116
+ * @param id scoped id of the resource
117
+ * @param scope scope in which this resource is defined
118
+ * @param recordName
119
+ * @param apiDomain
120
+ * @param hostedZone
121
+ * @param skipStageFromRecord
122
+ */
123
+ createApiGatewayARecord(id, scope, recordName, apiDomain, hostedZone, skipStageFromRecord) {
124
+ let apiRecordName = '';
125
+ if (recordName && recordName !== '')
126
+ apiRecordName =
127
+ scope.isProductionStage() || skipStageFromRecord ? `${recordName}` : `${recordName}-${scope.props.stage}`;
128
+ const apiARecord = new ARecord(scope, `${id}`, {
129
+ recordName: apiRecordName,
130
+ target: RecordTarget.fromAlias(new ApiGatewayDomain(apiDomain)),
131
+ zone: hostedZone,
132
+ });
133
+ createCfnOutput(`${id}-a-record-domain-name`, scope, apiARecord.domainName);
134
+ return apiARecord;
135
+ }
136
+ }