@sylvesterllc/aws-constructs 1.1.37 → 1.1.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +56 -56
- package/__tests__/app-config.test.ts +32 -32
- package/__tests__/data/testConfig.ts +146 -146
- package/__tests__/mocks/ResourceMock.ts +9 -9
- package/__tests__/router.test.ts +194 -194
- package/dist/config/AppConfig.js +1 -1
- package/dist/config/Constants.js +1 -1
- package/dist/config/Environments.js +1 -1
- package/dist/config/MicroserviceAppConfig.js +1 -1
- package/dist/config/ServiceBundleConfig.js +1 -1
- package/dist/config/bishopConfig.js +1 -1
- package/dist/config/customConfigs/ApiAppConfig.js +1 -1
- package/dist/config/customConfigs/GlobalAppConfig.js +1 -1
- package/dist/config/customConfigs/IAppConfig.js +1 -1
- package/dist/config/customConfigs/ResourceAppConfig.js +1 -1
- package/dist/config/microServiceConfig.js +1 -1
- package/dist/config/types/LogDuration.js +1 -1
- package/dist/config/types/TsgAuthorizerProp.js +1 -1
- package/dist/config/types/TsgAuthorizerType.js +1 -1
- package/dist/config/types/TsgCdkConfigType.js +1 -1
- package/dist/config/types/TsgCognitoConfig.js +1 -1
- package/dist/config/types/TsgDnsConfig.js +1 -1
- package/dist/config/types/TsgDynamoDbProp.js +1 -1
- package/dist/config/types/TsgDynamoIndex.js +1 -1
- package/dist/config/types/TsgDynamoProp.js +1 -1
- package/dist/config/types/TsgDynamoTable.js +1 -1
- package/dist/config/types/TsgDynamoTableRef.js +1 -1
- package/dist/config/types/TsgEc2Prop.js +1 -1
- package/dist/config/types/TsgKeyPair.js +1 -1
- package/dist/config/types/TsgLambda.js +1 -1
- package/dist/config/types/TsgLambdaLayerProp.js +1 -1
- package/dist/config/types/TsgLambdaMap.js +1 -1
- package/dist/config/types/TsgLambdaName.js +1 -1
- package/dist/config/types/TsgLambdaNode.js +1 -1
- package/dist/config/types/TsgLambdaProp.js +1 -1
- package/dist/config/types/TsgLambdaProps.js +1 -1
- package/dist/config/types/TsgLambdaRoutable.js +1 -1
- package/dist/config/types/index.js +1 -1
- package/dist/constants/aws-service-principal-constants.js +1 -1
- package/dist/constructs/BasicLambda.js +1 -1
- package/dist/constructs/DynamoDbSingleTable.js +4 -2
- package/dist/constructs/MicroService.js +1 -1
- package/dist/constructs/basic-queue.d.ts +9 -0
- package/dist/constructs/basic-queue.js +16 -0
- package/dist/constructs/index.d.ts +1 -0
- package/dist/constructs/index.js +16 -1
- package/dist/constructs/timer-job.js +1 -1
- package/dist/helpers/logger.js +1 -1
- package/dist/helpers/util-helper.js +1 -1
- package/dist/index.js +1 -1
- package/dist/interfaces/ApiLambdaResult.js +1 -1
- package/dist/interfaces/BaseResourceProps.js +1 -1
- package/dist/interfaces/CreateLambdaFunctionInput.js +1 -1
- package/dist/interfaces/MicroserviceProps.js +1 -1
- package/dist/interfaces/lambda/index.js +1 -1
- package/dist/interfaces/lambda/lambda-props.js +1 -1
- package/dist/interfaces/timer-job/timer-job-props.js +1 -1
- package/dist/resources/base/baseResource.js +1 -1
- package/dist/resources/base/tsgBaseResource.js +1 -1
- package/dist/resources/certificate/createCertificate.js +1 -1
- package/dist/resources/cognito/createCognito.js +1 -1
- package/dist/resources/cognito/createCognitoProps.js +1 -1
- package/dist/resources/customResource/createSeedDatabaseCustomResource.js +1 -1
- package/dist/resources/dynamodb/CreateDynamo.js +1 -1
- package/dist/resources/dynamodb/CreateDynamoSingleTableDesign.d.ts +2 -1
- package/dist/resources/dynamodb/CreateDynamoSingleTableDesign.js +29 -28
- package/dist/resources/ec2/create-ec2-instance.js +3 -3
- package/dist/resources/ecr/CreateEcr.js +2 -2
- package/dist/resources/gateway/CreateApiAndAttachLambdas.js +1 -1
- package/dist/resources/gateway/createApi.js +1 -1
- package/dist/resources/gateway/createApiKey.js +1 -1
- package/dist/resources/helpers/createCommonLayer.js +1 -1
- package/dist/resources/helpers/createRoutes.js +1 -1
- package/dist/resources/index.js +1 -1
- package/dist/resources/lambda/create-basic-lambda-helper.js +11 -24
- package/dist/resources/lambda/create-basic-lambda.js +8 -21
- package/dist/resources/lambda/createLambda.js +1 -1
- package/dist/resources/lambda/lambdaHelper.js +1 -1
- package/dist/resources/lambda-authorizer/TsgJwtTokenAuthorizer.js +1 -1
- package/dist/resources/lambda-authorizer/TsgRequestAuthorizer.js +1 -1
- package/dist/resources/lambda-authorizer/createAuthorizerHelpers.js +1 -1
- package/dist/resources/lambda-layer/createLambdaLayer.js +1 -1
- package/dist/resources/layers/common/src/nodejs/api-response/responses.js +1 -1
- package/dist/resources/layers/common/src/nodejs/index.js +1 -1
- package/dist/resources/layers/common/src/nodejs/logger/IContext.js +1 -1
- package/dist/resources/layers/common/src/nodejs/logger/index.js +1 -1
- package/dist/resources/layers/common/src/nodejs/logger/logger.js +1 -1
- package/dist/resources/resources/iam/policyDocuments/cognitoPolicy.js +1 -1
- package/dist/resources/resources/iam/roles/createRole.js +1 -1
- package/dist/resources/route53/CreateZone.js +1 -1
- package/dist/resources/route53/create-zones.js +1 -1
- package/dist/resources/securityManager/index.js +1 -1
- package/dist/resources/sqs/create-sqs-resource.d.ts +3 -0
- package/dist/resources/sqs/create-sqs-resource.js +21 -0
- package/jest.config.js +8 -8
- package/jest.config.ts.old +20 -20
- package/package.json +57 -55
- package/readme.md +147 -147
- package/src/config/AppConfig.ts +106 -106
- package/src/config/Constants.ts +26 -26
- package/src/config/Environments.ts +1 -1
- package/src/config/MicroserviceAppConfig.ts +8 -8
- package/src/config/ServiceBundleConfig.ts +17 -17
- package/src/config/bishopConfig.ts +82 -82
- package/src/config/customConfigs/ApiAppConfig.ts +5 -5
- package/src/config/customConfigs/GlobalAppConfig.ts +10 -10
- package/src/config/customConfigs/IAppConfig.ts +12 -12
- package/src/config/customConfigs/ResourceAppConfig.ts +15 -15
- package/src/config/microServiceConfig.ts +83 -83
- package/src/config/types/LogDuration.ts +7 -7
- package/src/config/types/TsgAuthorizerProp.ts +8 -8
- package/src/config/types/TsgAuthorizerType.ts +4 -4
- package/src/config/types/TsgCdkConfigType.ts +2 -2
- package/src/config/types/TsgCognitoConfig.ts +5 -5
- package/src/config/types/TsgDnsConfig.ts +10 -10
- package/src/config/types/TsgDynamoDbProp.ts +9 -9
- package/src/config/types/TsgDynamoIndex.ts +15 -15
- package/src/config/types/TsgDynamoProp.ts +16 -16
- package/src/config/types/TsgDynamoTable.ts +4 -4
- package/src/config/types/TsgDynamoTableRef.ts +3 -3
- package/src/config/types/TsgEc2Prop.ts +8 -8
- package/src/config/types/TsgKeyPair.ts +5 -5
- package/src/config/types/TsgLambda.ts +5 -5
- package/src/config/types/TsgLambdaLayerProp.ts +4 -4
- package/src/config/types/TsgLambdaMap.ts +3 -3
- package/src/config/types/TsgLambdaName.ts +3 -3
- package/src/config/types/TsgLambdaNode.ts +3 -3
- package/src/config/types/TsgLambdaProp.ts +19 -19
- package/src/config/types/TsgLambdaProps.ts +17 -17
- package/src/config/types/TsgLambdaRoutable.ts +8 -8
- package/src/config/types/index.ts +11 -11
- package/src/constants/aws-service-principal-constants.ts +2 -2
- package/src/constructs/BasicLambda.ts +19 -19
- package/src/constructs/DynamoDbSingleTable.ts +13 -12
- package/src/constructs/MicroService.ts +131 -131
- package/src/constructs/basic-queue.ts +19 -0
- package/src/constructs/index.ts +6 -5
- package/src/constructs/timer-job.ts +19 -19
- package/src/helpers/logger.ts +12 -12
- package/src/helpers/util-helper.ts +19 -19
- package/src/index.ts +8 -8
- package/src/interfaces/ApiLambdaResult.ts +6 -6
- package/src/interfaces/BaseResourceProps.ts +6 -6
- package/src/interfaces/CreateLambdaFunctionInput.ts +10 -10
- package/src/interfaces/MicroserviceProps.ts +10 -10
- package/src/interfaces/lambda/index.ts +1 -1
- package/src/interfaces/lambda/lambda-props.ts +15 -15
- package/src/interfaces/timer-job/timer-job-props.ts +6 -6
- package/src/resources/base/baseResource.ts +14 -14
- package/src/resources/base/tsgBaseResource.ts +21 -21
- package/src/resources/certificate/createCertificate.ts +57 -57
- package/src/resources/cognito/createCognito.ts +47 -47
- package/src/resources/cognito/createCognitoProps.ts +46 -46
- package/src/resources/customResource/createSeedDatabaseCustomResource.ts +36 -36
- package/src/resources/dynamodb/CreateDynamo.ts +110 -110
- package/src/resources/dynamodb/CreateDynamoSingleTableDesign.ts +112 -118
- package/src/resources/ec2/create-ec2-instance.ts +52 -52
- package/src/resources/ecr/CreateEcr.ts +57 -57
- package/src/resources/gateway/CreateApiAndAttachLambdas.ts +161 -161
- package/src/resources/gateway/createApi.ts +173 -173
- package/src/resources/gateway/createApiKey.ts +88 -88
- package/src/resources/helpers/createCommonLayer.ts +18 -18
- package/src/resources/helpers/createRoutes.ts +74 -74
- package/src/resources/index.ts +1 -1
- package/src/resources/lambda/create-basic-lambda-helper.ts +124 -146
- package/src/resources/lambda/create-basic-lambda.ts +159 -173
- package/src/resources/lambda/createLambda.ts +203 -203
- package/src/resources/lambda/lambdaHelper.ts +133 -133
- package/src/resources/lambda-authorizer/TsgJwtTokenAuthorizer.ts +107 -107
- package/src/resources/lambda-authorizer/TsgRequestAuthorizer.ts +44 -44
- package/src/resources/lambda-authorizer/createAuthorizerHelpers.ts +76 -76
- package/src/resources/lambda-layer/createLambdaLayer.ts +39 -39
- package/src/resources/layers/common/package.json +22 -22
- package/src/resources/layers/common/src/nodejs/api-response/responses.ts +41 -41
- package/src/resources/layers/common/src/nodejs/index.ts +3 -3
- package/src/resources/layers/common/src/nodejs/logger/IContext.ts +6 -6
- package/src/resources/layers/common/src/nodejs/logger/index.ts +1 -1
- package/src/resources/layers/common/src/nodejs/logger/logger.ts +10 -10
- package/src/resources/layers/common/tsconfig.json +7 -7
- package/src/resources/resources/iam/policyDocuments/cognitoPolicy.ts +54 -54
- package/src/resources/resources/iam/roles/createRole.ts +29 -29
- package/src/resources/route53/CreateZone.ts +61 -61
- package/src/resources/route53/create-zones.ts +40 -40
- package/src/resources/securityManager/index.ts +23 -23
- package/src/resources/sqs/create-sqs-resource.ts +22 -0
- package/tsconfig.json +44 -44
|
@@ -1,173 +1,159 @@
|
|
|
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 { TimerJobProps } from "../../interfaces/timer-job";
|
|
12
|
-
import { Construct } from "constructs";
|
|
13
|
-
import { SERVICE_PRINCIPAL } from "../../constants/aws-service-principal-constants";
|
|
14
|
-
import { CronOptions, Rule, Schedule } from "aws-cdk-lib/aws-events";
|
|
15
|
-
import { LambdaFunction } from "aws-cdk-lib/aws-events-targets";
|
|
16
|
-
import { Table } from "aws-cdk-lib/aws-dynamodb";
|
|
17
|
-
|
|
18
|
-
export const createBasicLambdaTimerJob = (
|
|
19
|
-
scope: Construct,
|
|
20
|
-
props: TimerJobProps
|
|
21
|
-
): NodejsFunction => {
|
|
22
|
-
const lambdaProps = createBasicLambdaProps(props);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
...props.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
{
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
};
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
scope: Construct,
|
|
145
|
-
lambda: NodejsFunction,
|
|
146
|
-
|
|
147
|
-
) => {
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
layerArns?: string[]
|
|
161
|
-
) => {
|
|
162
|
-
if (layerArns && layerArns.length > 0) {
|
|
163
|
-
layerArns.forEach((arn: string, idx: number) => {
|
|
164
|
-
const layer = LayerVersion.fromLayerVersionArn(
|
|
165
|
-
scope,
|
|
166
|
-
`common-layer-${idx}`,
|
|
167
|
-
arn
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
lambda.addLayers(layer);
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
};
|
|
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 { TimerJobProps } from "../../interfaces/timer-job";
|
|
12
|
+
import { Construct } from "constructs";
|
|
13
|
+
import { SERVICE_PRINCIPAL } from "../../constants/aws-service-principal-constants";
|
|
14
|
+
import { CronOptions, Rule, Schedule } from "aws-cdk-lib/aws-events";
|
|
15
|
+
import { LambdaFunction } from "aws-cdk-lib/aws-events-targets";
|
|
16
|
+
import { Table } from "aws-cdk-lib/aws-dynamodb";
|
|
17
|
+
|
|
18
|
+
export const createBasicLambdaTimerJob = (
|
|
19
|
+
scope: Construct,
|
|
20
|
+
props: TimerJobProps
|
|
21
|
+
): NodejsFunction => {
|
|
22
|
+
const lambdaProps = createBasicLambdaProps(props);
|
|
23
|
+
|
|
24
|
+
let lambdaFunction = new NodejsFunction(
|
|
25
|
+
scope,
|
|
26
|
+
`${props.appPrefix}${props.functionName}`,
|
|
27
|
+
lambdaProps
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
addInvokePermissionToLambdaForEvents(lambdaFunction);
|
|
31
|
+
|
|
32
|
+
const eventRule = createEventRuleForLambda(
|
|
33
|
+
scope,
|
|
34
|
+
lambdaFunction,
|
|
35
|
+
props.cronOptions
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
eventRule.addTarget(new LambdaFunction(lambdaFunction));
|
|
39
|
+
|
|
40
|
+
grantAccessToDynamoTables(scope, lambdaFunction, props.dynamoTableNames);
|
|
41
|
+
|
|
42
|
+
addLambdaLayers(scope, lambdaFunction, props.lambdaLayerArn);
|
|
43
|
+
|
|
44
|
+
return lambdaFunction;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const createBasicLambdaProps = (props: TimerJobProps): NodejsFunctionProps => {
|
|
48
|
+
let resolvedEntry: string;
|
|
49
|
+
|
|
50
|
+
if (props.codePath && path.isAbsolute(props.codePath)) {
|
|
51
|
+
resolvedEntry = props.codePath;
|
|
52
|
+
} else if (props.codePath && props.projectRoot) {
|
|
53
|
+
// codePath is relative, resolve from current directory + projectRoot
|
|
54
|
+
resolvedEntry = path.resolve(process.cwd(), props.codePath);
|
|
55
|
+
} else if (props.projectRoot) {
|
|
56
|
+
// No codePath, use default path with projectRoot
|
|
57
|
+
resolvedEntry = path.resolve(
|
|
58
|
+
process.cwd(),
|
|
59
|
+
props.projectRoot,
|
|
60
|
+
`resources/lambdas/timer-jobs/${props.functionName}/main.mts`
|
|
61
|
+
);
|
|
62
|
+
} else if (props.codePath) {
|
|
63
|
+
// codePath without projectRoot
|
|
64
|
+
resolvedEntry = path.resolve(process.cwd(), props.codePath);
|
|
65
|
+
} else {
|
|
66
|
+
// Default path without projectRoot
|
|
67
|
+
resolvedEntry = path.join(
|
|
68
|
+
`./resources/lambdas/timer-jobs/${props.functionName}/main.mts`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const lambdaProp: NodejsFunctionProps = {
|
|
73
|
+
entry: resolvedEntry,
|
|
74
|
+
functionName: `${props.appPrefix ? `${props.appPrefix}-` : ""}${
|
|
75
|
+
props.functionName
|
|
76
|
+
}`,
|
|
77
|
+
handler: "main.ts",
|
|
78
|
+
logRetention: RetentionDays.TWO_WEEKS,
|
|
79
|
+
runtime: Runtime.NODEJS_LATEST,
|
|
80
|
+
timeout: Duration.minutes(
|
|
81
|
+
props.timeoutInMinutes ? props.timeoutInMinutes : 1
|
|
82
|
+
),
|
|
83
|
+
memorySize: props.memory,
|
|
84
|
+
environment: {
|
|
85
|
+
...props.envs,
|
|
86
|
+
},
|
|
87
|
+
bundling: {
|
|
88
|
+
minify: true,
|
|
89
|
+
target: `esnext`,
|
|
90
|
+
sourceMap: true,
|
|
91
|
+
sourceMapMode: SourceMapMode.EXTERNAL,
|
|
92
|
+
environment: {
|
|
93
|
+
...props.envs,
|
|
94
|
+
},
|
|
95
|
+
...(props.projectRoot && { projectRoot: props.projectRoot }),
|
|
96
|
+
...(props.depsLockFilePath && {
|
|
97
|
+
depsLockFilePath: props.depsLockFilePath,
|
|
98
|
+
}),
|
|
99
|
+
},
|
|
100
|
+
role: props.role,
|
|
101
|
+
layers: undefined,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return lambdaProp;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const addInvokePermissionToLambdaForEvents = (lambda: NodejsFunction) => {
|
|
108
|
+
lambda.addPermission(`InvokePermission-${lambda.functionName}`, {
|
|
109
|
+
principal: new ServicePrincipal(SERVICE_PRINCIPAL.EVENTS),
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const createEventRuleForLambda = (
|
|
114
|
+
scope: Construct,
|
|
115
|
+
lambda: NodejsFunction,
|
|
116
|
+
options: CronOptions
|
|
117
|
+
) => {
|
|
118
|
+
const eventRule = new Rule(
|
|
119
|
+
scope,
|
|
120
|
+
`scheduleRule-${lambda?.node.id || "010"}`,
|
|
121
|
+
{
|
|
122
|
+
schedule: Schedule.cron(options),
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return eventRule;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const grantAccessToDynamoTables = (
|
|
130
|
+
scope: Construct,
|
|
131
|
+
lambda: NodejsFunction,
|
|
132
|
+
tableNames?: string[]
|
|
133
|
+
) => {
|
|
134
|
+
if (tableNames && tableNames.length > 0) {
|
|
135
|
+
tableNames.forEach((tableName) => {
|
|
136
|
+
const table = Table.fromTableName(scope, `${tableName}-table`, tableName);
|
|
137
|
+
|
|
138
|
+
table.grantReadWriteData(lambda);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const addLambdaLayers = (
|
|
144
|
+
scope: Construct,
|
|
145
|
+
lambda: NodejsFunction,
|
|
146
|
+
layerArns?: string[]
|
|
147
|
+
) => {
|
|
148
|
+
if (layerArns && layerArns.length > 0) {
|
|
149
|
+
layerArns.forEach((arn: string, idx: number) => {
|
|
150
|
+
const layer = LayerVersion.fromLayerVersionArn(
|
|
151
|
+
scope,
|
|
152
|
+
`common-layer-${idx}`,
|
|
153
|
+
arn
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
lambda.addLayers(layer);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
};
|