@sylvesterllc/aws-constructs 1.1.26 → 1.1.29

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 (178) hide show
  1. package/.github/workflows/publish.yml +56 -56
  2. package/__tests__/app-config.test.ts +32 -32
  3. package/__tests__/data/testConfig.ts +146 -146
  4. package/__tests__/mocks/ResourceMock.ts +9 -9
  5. package/__tests__/router.test.ts +194 -194
  6. package/dist/config/AppConfig.js +1 -1
  7. package/dist/config/Constants.js +1 -1
  8. package/dist/config/Environments.js +1 -1
  9. package/dist/config/MicroserviceAppConfig.js +1 -1
  10. package/dist/config/ServiceBundleConfig.js +1 -1
  11. package/dist/config/bishopConfig.js +1 -1
  12. package/dist/config/customConfigs/ApiAppConfig.js +1 -1
  13. package/dist/config/customConfigs/GlobalAppConfig.js +1 -1
  14. package/dist/config/customConfigs/IAppConfig.js +1 -1
  15. package/dist/config/customConfigs/ResourceAppConfig.js +1 -1
  16. package/dist/config/microServiceConfig.js +2 -2
  17. package/dist/config/types/LogDuration.js +1 -1
  18. package/dist/config/types/TsgAuthorizerProp.js +1 -1
  19. package/dist/config/types/TsgAuthorizerType.js +1 -1
  20. package/dist/config/types/TsgCdkConfigType.js +1 -1
  21. package/dist/config/types/TsgCognitoConfig.js +1 -1
  22. package/dist/config/types/TsgDnsConfig.js +1 -1
  23. package/dist/config/types/TsgDynamoDbProp.js +1 -1
  24. package/dist/config/types/TsgDynamoIndex.js +1 -1
  25. package/dist/config/types/TsgDynamoProp.js +1 -1
  26. package/dist/config/types/TsgDynamoTable.js +1 -1
  27. package/dist/config/types/TsgDynamoTableRef.js +1 -1
  28. package/dist/config/types/TsgEc2Prop.js +1 -1
  29. package/dist/config/types/TsgKeyPair.js +1 -1
  30. package/dist/config/types/TsgLambda.js +1 -1
  31. package/dist/config/types/TsgLambdaLayerProp.js +1 -1
  32. package/dist/config/types/TsgLambdaMap.js +1 -1
  33. package/dist/config/types/TsgLambdaName.js +1 -1
  34. package/dist/config/types/TsgLambdaNode.js +1 -1
  35. package/dist/config/types/TsgLambdaProp.js +1 -1
  36. package/dist/config/types/TsgLambdaProps.js +1 -1
  37. package/dist/config/types/TsgLambdaRoutable.js +1 -1
  38. package/dist/config/types/index.js +1 -1
  39. package/dist/constants/aws-service-principal-constants.js +1 -1
  40. package/dist/constructs/BasicLambda.js +1 -1
  41. package/dist/constructs/DynamoDbSingleTable.js +1 -1
  42. package/dist/constructs/MicroService.js +1 -1
  43. package/dist/constructs/index.js +1 -1
  44. package/dist/constructs/timer-job.js +1 -1
  45. package/dist/helpers/logger.js +1 -1
  46. package/dist/helpers/util-helper.js +1 -1
  47. package/dist/index.js +1 -1
  48. package/dist/interfaces/ApiLambdaResult.js +1 -1
  49. package/dist/interfaces/BaseResourceProps.js +1 -1
  50. package/dist/interfaces/CreateLambdaFunctionInput.js +1 -1
  51. package/dist/interfaces/MicroserviceProps.js +1 -1
  52. package/dist/interfaces/lambda/index.js +1 -1
  53. package/dist/interfaces/lambda/lambda-props.js +1 -1
  54. package/dist/interfaces/timer-job/timer-job-props.js +1 -1
  55. package/dist/resources/base/baseResource.js +1 -1
  56. package/dist/resources/base/tsgBaseResource.js +1 -1
  57. package/dist/resources/certificate/createCertificate.js +1 -1
  58. package/dist/resources/cognito/createCognito.js +1 -1
  59. package/dist/resources/cognito/createCognitoProps.js +1 -1
  60. package/dist/resources/customResource/createSeedDatabaseCustomResource.js +1 -1
  61. package/dist/resources/dynamodb/CreateDynamo.js +1 -1
  62. package/dist/resources/dynamodb/CreateDynamoSingleTableDesign.js +1 -1
  63. package/dist/resources/ec2/create-ec2-instance.js +3 -3
  64. package/dist/resources/ecr/CreateEcr.js +2 -2
  65. package/dist/resources/gateway/CreateApiAndAttachLambdas.js +1 -1
  66. package/dist/resources/gateway/createApi.js +1 -1
  67. package/dist/resources/gateway/createApiKey.js +1 -1
  68. package/dist/resources/helpers/createCommonLayer.js +1 -1
  69. package/dist/resources/helpers/createRoutes.js +1 -1
  70. package/dist/resources/index.js +1 -1
  71. package/dist/resources/lambda/create-basic-lambda-helper.js +31 -113
  72. package/dist/resources/lambda/create-basic-lambda.js +28 -110
  73. package/dist/resources/lambda/createLambda.js +1 -1
  74. package/dist/resources/lambda/lambdaHelper.js +1 -1
  75. package/dist/resources/lambda-authorizer/TsgJwtTokenAuthorizer.js +1 -1
  76. package/dist/resources/lambda-authorizer/TsgRequestAuthorizer.js +1 -1
  77. package/dist/resources/lambda-authorizer/createAuthorizerHelpers.js +1 -1
  78. package/dist/resources/lambda-layer/createLambdaLayer.js +1 -1
  79. package/dist/resources/layers/common/src/nodejs/api-response/responses.js +1 -1
  80. package/dist/resources/layers/common/src/nodejs/index.js +1 -1
  81. package/dist/resources/layers/common/src/nodejs/logger/IContext.js +1 -1
  82. package/dist/resources/layers/common/src/nodejs/logger/index.js +1 -1
  83. package/dist/resources/layers/common/src/nodejs/logger/logger.js +1 -1
  84. package/dist/resources/resources/iam/policyDocuments/cognitoPolicy.js +1 -1
  85. package/dist/resources/resources/iam/roles/createRole.js +1 -1
  86. package/dist/resources/route53/CreateZone.js +1 -1
  87. package/dist/resources/route53/create-zones.js +1 -1
  88. package/dist/resources/securityManager/index.js +1 -1
  89. package/jest.config.js +8 -8
  90. package/jest.config.ts.old +20 -20
  91. package/package.json +55 -55
  92. package/readme.md +147 -147
  93. package/src/config/AppConfig.ts +106 -106
  94. package/src/config/Constants.ts +26 -26
  95. package/src/config/Environments.ts +1 -1
  96. package/src/config/MicroserviceAppConfig.ts +8 -8
  97. package/src/config/ServiceBundleConfig.ts +17 -17
  98. package/src/config/bishopConfig.ts +82 -82
  99. package/src/config/customConfigs/ApiAppConfig.ts +5 -5
  100. package/src/config/customConfigs/GlobalAppConfig.ts +10 -10
  101. package/src/config/customConfigs/IAppConfig.ts +12 -12
  102. package/src/config/customConfigs/ResourceAppConfig.ts +15 -15
  103. package/src/config/microServiceConfig.ts +83 -83
  104. package/src/config/types/LogDuration.ts +7 -7
  105. package/src/config/types/TsgAuthorizerProp.ts +8 -8
  106. package/src/config/types/TsgAuthorizerType.ts +4 -4
  107. package/src/config/types/TsgCdkConfigType.ts +2 -2
  108. package/src/config/types/TsgCognitoConfig.ts +5 -5
  109. package/src/config/types/TsgDnsConfig.ts +10 -10
  110. package/src/config/types/TsgDynamoDbProp.ts +9 -9
  111. package/src/config/types/TsgDynamoIndex.ts +15 -15
  112. package/src/config/types/TsgDynamoProp.ts +16 -16
  113. package/src/config/types/TsgDynamoTable.ts +4 -4
  114. package/src/config/types/TsgDynamoTableRef.ts +3 -3
  115. package/src/config/types/TsgEc2Prop.ts +8 -8
  116. package/src/config/types/TsgKeyPair.ts +5 -5
  117. package/src/config/types/TsgLambda.ts +5 -5
  118. package/src/config/types/TsgLambdaLayerProp.ts +4 -4
  119. package/src/config/types/TsgLambdaMap.ts +3 -3
  120. package/src/config/types/TsgLambdaName.ts +3 -3
  121. package/src/config/types/TsgLambdaNode.ts +3 -3
  122. package/src/config/types/TsgLambdaProp.ts +19 -19
  123. package/src/config/types/TsgLambdaProps.ts +17 -17
  124. package/src/config/types/TsgLambdaRoutable.ts +8 -8
  125. package/src/config/types/index.ts +11 -11
  126. package/src/constants/aws-service-principal-constants.ts +2 -2
  127. package/src/constructs/BasicLambda.ts +19 -19
  128. package/src/constructs/DynamoDbSingleTable.ts +12 -12
  129. package/src/constructs/MicroService.ts +131 -131
  130. package/src/constructs/index.ts +5 -5
  131. package/src/constructs/timer-job.ts +19 -19
  132. package/src/helpers/logger.ts +12 -12
  133. package/src/helpers/util-helper.ts +19 -19
  134. package/src/index.ts +8 -8
  135. package/src/interfaces/ApiLambdaResult.ts +6 -6
  136. package/src/interfaces/BaseResourceProps.ts +6 -6
  137. package/src/interfaces/CreateLambdaFunctionInput.ts +10 -10
  138. package/src/interfaces/MicroserviceProps.ts +10 -10
  139. package/src/interfaces/lambda/index.ts +1 -1
  140. package/src/interfaces/lambda/lambda-props.ts +15 -15
  141. package/src/interfaces/timer-job/timer-job-props.ts +6 -6
  142. package/src/resources/base/baseResource.ts +14 -14
  143. package/src/resources/base/tsgBaseResource.ts +21 -21
  144. package/src/resources/certificate/createCertificate.ts +57 -57
  145. package/src/resources/cognito/createCognito.ts +47 -47
  146. package/src/resources/cognito/createCognitoProps.ts +46 -46
  147. package/src/resources/customResource/createSeedDatabaseCustomResource.ts +36 -36
  148. package/src/resources/dynamodb/CreateDynamo.ts +110 -110
  149. package/src/resources/dynamodb/CreateDynamoSingleTableDesign.ts +111 -111
  150. package/src/resources/ec2/create-ec2-instance.ts +52 -52
  151. package/src/resources/ecr/CreateEcr.ts +57 -57
  152. package/src/resources/gateway/CreateApiAndAttachLambdas.ts +161 -161
  153. package/src/resources/gateway/createApi.ts +173 -173
  154. package/src/resources/gateway/createApiKey.ts +88 -88
  155. package/src/resources/helpers/createCommonLayer.ts +18 -18
  156. package/src/resources/helpers/createRoutes.ts +74 -74
  157. package/src/resources/index.ts +1 -1
  158. package/src/resources/lambda/create-basic-lambda-helper.ts +128 -243
  159. package/src/resources/lambda/create-basic-lambda.ts +161 -279
  160. package/src/resources/lambda/createLambda.ts +203 -203
  161. package/src/resources/lambda/lambdaHelper.ts +133 -133
  162. package/src/resources/lambda-authorizer/TsgJwtTokenAuthorizer.ts +107 -107
  163. package/src/resources/lambda-authorizer/TsgRequestAuthorizer.ts +44 -44
  164. package/src/resources/lambda-authorizer/createAuthorizerHelpers.ts +76 -76
  165. package/src/resources/lambda-layer/createLambdaLayer.ts +39 -39
  166. package/src/resources/layers/common/package.json +22 -22
  167. package/src/resources/layers/common/src/nodejs/api-response/responses.ts +41 -41
  168. package/src/resources/layers/common/src/nodejs/index.ts +3 -3
  169. package/src/resources/layers/common/src/nodejs/logger/IContext.ts +6 -6
  170. package/src/resources/layers/common/src/nodejs/logger/index.ts +1 -1
  171. package/src/resources/layers/common/src/nodejs/logger/logger.ts +10 -10
  172. package/src/resources/layers/common/tsconfig.json +7 -7
  173. package/src/resources/resources/iam/policyDocuments/cognitoPolicy.ts +54 -54
  174. package/src/resources/resources/iam/roles/createRole.ts +29 -29
  175. package/src/resources/route53/CreateZone.ts +61 -61
  176. package/src/resources/route53/create-zones.ts +40 -40
  177. package/src/resources/securityManager/index.ts +23 -23
  178. package/tsconfig.json +44 -44
@@ -1,243 +1,128 @@
1
- import { Duration } from "aws-cdk-lib";
2
- import { ServicePrincipal } from "aws-cdk-lib/aws-iam";
3
- import { LayerVersion, Runtime } from "aws-cdk-lib/aws-lambda";
4
- import {
5
- NodejsFunction,
6
- NodejsFunctionProps,
7
- SourceMapMode,
8
- } from "aws-cdk-lib/aws-lambda-nodejs";
9
- import { RetentionDays } from "aws-cdk-lib/aws-logs";
10
- import fs = require("fs");
11
- import path = require("path");
12
- import { LambdaProps } from "../../interfaces/lambda";
13
- import { Construct } from "constructs";
14
- import { Table } from "aws-cdk-lib/aws-dynamodb";
15
-
16
- const isSubPath = (root: string, target: string): boolean => {
17
- const relative = path.relative(path.resolve(root), path.resolve(target));
18
- return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
19
- };
20
-
21
- const LOCK_FILE_NAMES = ["pnpm-lock.yaml", "yarn.lock", "package-lock.json"];
22
-
23
- const resolveProjectRoot = (projectRoot?: string): string | undefined => {
24
- if (!projectRoot) {
25
- return undefined;
26
- }
27
-
28
- return path.isAbsolute(projectRoot)
29
- ? path.resolve(projectRoot)
30
- : path.resolve(process.cwd(), projectRoot);
31
- };
32
-
33
- const findNearestLockFile = (startDir: string): string | undefined => {
34
- let current = path.resolve(startDir);
35
- const { root } = path.parse(current);
36
-
37
- while (true) {
38
- for (const candidate of LOCK_FILE_NAMES) {
39
- const resolvedCandidate = path.join(current, candidate);
40
- if (fs.existsSync(resolvedCandidate) && fs.statSync(resolvedCandidate).isFile()) {
41
- return resolvedCandidate;
42
- }
43
- }
44
-
45
- if (current === root) {
46
- return undefined;
47
- }
48
-
49
- current = path.dirname(current);
50
- }
51
- };
52
-
53
- const findCommonAncestor = (paths: string[]): string | undefined => {
54
- if (paths.length === 0) {
55
- return undefined;
56
- }
57
-
58
- let ancestor = path.resolve(paths[0]);
59
-
60
- for (const currentPath of paths.slice(1)) {
61
- const target = path.resolve(currentPath);
62
- const ancestorRoot = path.parse(ancestor).root;
63
-
64
- if (path.parse(ancestor).root.toLowerCase() !== path.parse(target).root.toLowerCase()) {
65
- return undefined;
66
- }
67
-
68
- let candidate = ancestor;
69
- while (!isSubPath(candidate, target)) {
70
- if (candidate === ancestorRoot) {
71
- candidate = ancestorRoot;
72
- break;
73
- }
74
- candidate = path.dirname(candidate);
75
- }
76
-
77
- ancestor = candidate;
78
- }
79
-
80
- return ancestor;
81
- };
82
-
83
- const resolvePath = (inputPath: string, projectRoot?: string): string => {
84
- if (path.isAbsolute(inputPath)) {
85
- return path.resolve(inputPath);
86
- }
87
-
88
- if (projectRoot) {
89
- const candidateFromProjectRoot = path.resolve(projectRoot, inputPath);
90
- if (isSubPath(projectRoot, candidateFromProjectRoot)) {
91
- return candidateFromProjectRoot;
92
- }
93
- }
94
-
95
- return path.resolve(process.cwd(), inputPath);
96
- };
97
-
98
- export const createBasicLambda = (
99
- scope: Construct,
100
- props: LambdaProps
101
- ): NodejsFunction => {
102
- const lambdaProps = createBasicLambdaProps(props);
103
-
104
- let lambdaFunction = new NodejsFunction(
105
- scope,
106
- `${props.appPrefix || ""}${props.functionName}`,
107
- lambdaProps
108
- );
109
-
110
- grantAccessToDynamoTables(scope, lambdaFunction, props.dynamoTableNames);
111
-
112
- addLambdaLayers(scope, lambdaFunction, props.lambdaLayerArn);
113
-
114
- return lambdaFunction;
115
- };
116
-
117
- const createBasicLambdaProps = (props: LambdaProps): NodejsFunctionProps => {
118
- const resolvedProjectRoot = resolveProjectRoot(props.projectRoot);
119
- const defaultRelativeEntry = path.join(
120
- "resources",
121
- "lambdas",
122
- props.functionName,
123
- "main.mts"
124
- );
125
- const entryPath = props.codePath ?? defaultRelativeEntry;
126
- const resolvedEntry = resolvePath(entryPath, resolvedProjectRoot);
127
-
128
- const cwd = path.resolve(process.cwd());
129
- const entryDir = path.dirname(resolvedEntry);
130
-
131
- let effectiveProjectRoot = resolvedProjectRoot ?? cwd;
132
- if (!isSubPath(effectiveProjectRoot, resolvedEntry)) {
133
- const ancestor = findCommonAncestor([effectiveProjectRoot, entryDir]);
134
- if (!ancestor) {
135
- throw new Error(
136
- `Unable to determine a projectRoot that contains both ${effectiveProjectRoot} and ${resolvedEntry}.`
137
- );
138
- }
139
- effectiveProjectRoot = ancestor;
140
- }
141
-
142
- if (!isSubPath(effectiveProjectRoot, resolvedEntry)) {
143
- throw new Error(
144
- `Resolved lambda entry ${resolvedEntry} must be located within projectRoot ${effectiveProjectRoot}.`
145
- );
146
- }
147
-
148
- let resolvedDepsLockFilePath = props.depsLockFilePath
149
- ? resolvePath(props.depsLockFilePath, resolvedProjectRoot)
150
- : undefined;
151
-
152
- if (!resolvedDepsLockFilePath) {
153
- const potentialLockFiles = [
154
- findNearestLockFile(entryDir),
155
- findNearestLockFile(cwd),
156
- effectiveProjectRoot !== cwd ? findNearestLockFile(effectiveProjectRoot) : undefined,
157
- ];
158
-
159
- for (const lockFile of potentialLockFiles) {
160
- if (lockFile && isSubPath(effectiveProjectRoot, lockFile)) {
161
- resolvedDepsLockFilePath = lockFile;
162
- break;
163
- }
164
- }
165
- }
166
-
167
- if (
168
- resolvedDepsLockFilePath &&
169
- !isSubPath(effectiveProjectRoot, resolvedDepsLockFilePath)
170
- ) {
171
- throw new Error(
172
- `Resolved depsLockFilePath ${resolvedDepsLockFilePath} must be located within projectRoot ${effectiveProjectRoot}.`
173
- );
174
- }
175
-
176
- const environmentVars = props.envs ?? {};
177
-
178
- const lambdaProp: NodejsFunctionProps = {
179
- entry: resolvedEntry,
180
- functionName: `${props.appPrefix ? `${props.appPrefix}-` : ""}${
181
- props.functionName
182
- }`,
183
- handler: "main.ts",
184
- logRetention: RetentionDays.TWO_WEEKS,
185
- runtime: Runtime.NODEJS_LATEST,
186
- timeout: Duration.minutes(
187
- props.timeoutInMinutes ? props.timeoutInMinutes : 1
188
- ),
189
- memorySize: props.memory,
190
- environment: {
191
- ...environmentVars,
192
- },
193
- bundling: {
194
- minify: true,
195
- target: `esnext`,
196
- sourceMap: true,
197
- sourceMapMode: SourceMapMode.EXTERNAL,
198
- environment: {
199
- ...environmentVars,
200
- },
201
- },
202
- role: props.role,
203
- layers: undefined,
204
- ...(effectiveProjectRoot && { projectRoot: effectiveProjectRoot }),
205
- ...(resolvedDepsLockFilePath && {
206
- depsLockFilePath: resolvedDepsLockFilePath,
207
- }),
208
- };
209
-
210
- return lambdaProp;
211
- };
212
-
213
- const grantAccessToDynamoTables = (
214
- scope: Construct,
215
- lambda: NodejsFunction,
216
- tableNames?: string[]
217
- ) => {
218
- if (tableNames && tableNames.length > 0) {
219
- tableNames.forEach((tableName) => {
220
- const table = Table.fromTableName(scope, `${tableName}-table`, tableName);
221
-
222
- table.grantReadWriteData(lambda);
223
- });
224
- }
225
- };
226
-
227
- const addLambdaLayers = (
228
- scope: Construct,
229
- lambda: NodejsFunction,
230
- layerArns?: string[]
231
- ) => {
232
- if (layerArns && layerArns.length > 0) {
233
- layerArns.forEach((arn: string, idx: number) => {
234
- const layer = LayerVersion.fromLayerVersionArn(
235
- scope,
236
- `common-layer-${idx}`,
237
- arn
238
- );
239
-
240
- lambda.addLayers(layer);
241
- });
242
- }
243
- };
1
+ import { Duration } from "aws-cdk-lib";
2
+ import { ServicePrincipal } from "aws-cdk-lib/aws-iam";
3
+ import { LayerVersion, Runtime } from "aws-cdk-lib/aws-lambda";
4
+ import {
5
+ NodejsFunction,
6
+ NodejsFunctionProps,
7
+ SourceMapMode,
8
+ } from "aws-cdk-lib/aws-lambda-nodejs";
9
+ import { RetentionDays } from "aws-cdk-lib/aws-logs";
10
+ import path = require("path");
11
+ import { LambdaProps } from "../../interfaces/lambda";
12
+ import { Construct } from "constructs";
13
+ import { Table } from "aws-cdk-lib/aws-dynamodb";
14
+
15
+ export const createBasicLambda = (
16
+ scope: Construct,
17
+ props: LambdaProps
18
+ ): NodejsFunction => {
19
+ const lambdaProps = createBasicLambdaProps(props);
20
+
21
+ const functionName = `${props.appPrefix || ""}${props.functionName}`;
22
+
23
+ let lambdaFunction = new NodejsFunction(
24
+ scope,
25
+ functionName,
26
+ lambdaProps
27
+ );
28
+
29
+ grantAccessToDynamoTables(scope, lambdaFunction, functionName, props.dynamoTableNames);
30
+
31
+ addLambdaLayers(scope, lambdaFunction, functionName, props.lambdaLayerArn);
32
+
33
+ return lambdaFunction;
34
+ };
35
+
36
+ const createBasicLambdaProps = (props: LambdaProps): NodejsFunctionProps => {
37
+ let resolvedEntry: string;
38
+
39
+ if (props.codePath && path.isAbsolute(props.codePath)) {
40
+ resolvedEntry = props.codePath;
41
+ } else if (props.codePath && props.projectRoot) {
42
+ // codePath is relative, resolve from current directory + projectRoot
43
+ resolvedEntry = path.resolve(process.cwd(), props.codePath);
44
+ } else if (props.projectRoot) {
45
+ // No codePath, use default path with projectRoot
46
+ resolvedEntry = path.resolve(
47
+ process.cwd(),
48
+ props.projectRoot,
49
+ `resources/lambdas/${props.functionName}/main.mts`
50
+ );
51
+ } else if (props.codePath) {
52
+ // codePath without projectRoot
53
+ resolvedEntry = path.resolve(process.cwd(), props.codePath);
54
+ } else {
55
+ // Default path without projectRoot
56
+ resolvedEntry = path.join(
57
+ `./resources/lambdas/${props.functionName}/main.mts`
58
+ );
59
+ }
60
+
61
+ const lambdaProp: NodejsFunctionProps = {
62
+ entry: resolvedEntry,
63
+ functionName: `${props.appPrefix ? `${props.appPrefix}-` : ""}${
64
+ props.functionName
65
+ }`,
66
+ handler: "main.ts",
67
+ logRetention: RetentionDays.TWO_WEEKS,
68
+ runtime: Runtime.NODEJS_LATEST,
69
+ timeout: Duration.minutes(
70
+ props.timeoutInMinutes ? props.timeoutInMinutes : 1
71
+ ),
72
+ memorySize: props.memory,
73
+ environment: {
74
+ ...props.envs,
75
+ },
76
+ bundling: {
77
+ minify: true,
78
+ target: `esnext`,
79
+ sourceMap: true,
80
+ sourceMapMode: SourceMapMode.EXTERNAL,
81
+ environment: {
82
+ ...props.envs,
83
+ },
84
+ ...(props.projectRoot && { projectRoot: props.projectRoot }),
85
+ ...(props.depsLockFilePath && {
86
+ depsLockFilePath: props.depsLockFilePath,
87
+ }),
88
+ },
89
+ role: props.role,
90
+ layers: undefined,
91
+ };
92
+
93
+ return lambdaProp;
94
+ };
95
+
96
+ const grantAccessToDynamoTables = (
97
+ scope: Construct,
98
+ lambda: NodejsFunction,
99
+ functionName: string,
100
+ tableNames?: string[],
101
+ ) => {
102
+ if (tableNames && tableNames.length > 0) {
103
+ tableNames.forEach((tableName, idx) => {
104
+ const table = Table.fromTableName(scope, `${tableName}-table-${idx}`, tableName);
105
+
106
+ table.grantReadWriteData(lambda);
107
+ });
108
+ }
109
+ };
110
+
111
+ const addLambdaLayers = (
112
+ scope: Construct,
113
+ lambda: NodejsFunction,
114
+ functionName: string,
115
+ layerArns?: string[]
116
+ ) => {
117
+ if (layerArns && layerArns.length > 0) {
118
+ layerArns.forEach((arn: string, idx: number) => {
119
+ const layer = LayerVersion.fromLayerVersionArn(
120
+ scope,
121
+ `common-layer-${idx}`,
122
+ arn
123
+ );
124
+
125
+ lambda.addLayers(layer);
126
+ });
127
+ }
128
+ };