@sylvesterllc/aws-constructs 1.1.11 → 1.1.13
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 +58 -38
- 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.d.ts +3 -0
- package/dist/constants/aws-service-principal-constants.js +7 -0
- package/dist/constructs/DynamoDbSingleTable.js +1 -1
- package/dist/constructs/MicroService.js +1 -1
- package/dist/constructs/index.d.ts +1 -0
- package/dist/constructs/index.js +4 -2
- package/dist/constructs/timer-job.d.ts +6 -0
- package/dist/constructs/timer-job.js +15 -0
- package/dist/helpers/logger.js +1 -1
- package/dist/helpers/util-helper.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +18 -4
- 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/timer-job/index.d.ts +1 -0
- package/dist/interfaces/timer-job/index.js +18 -0
- package/dist/interfaces/timer-job/timer-job-props.d.ts +14 -0
- package/dist/interfaces/timer-job/timer-job-props.js +3 -0
- 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.js +1 -1
- 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.d.ts +3 -0
- package/dist/resources/lambda/create-basic-lambda.js +77 -0
- 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/jest.config.js +8 -8
- package/jest.config.ts.old +20 -20
- package/package.json +55 -56
- 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 +3 -0
- package/src/constructs/DynamoDbSingleTable.ts +12 -12
- package/src/constructs/MicroService.ts +131 -132
- package/src/constructs/index.ts +4 -3
- package/src/constructs/timer-job.ts +17 -0
- package/src/helpers/logger.ts +12 -12
- package/src/helpers/util-helper.ts +19 -19
- package/src/index.ts +6 -5
- 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/timer-job/index.ts +1 -0
- package/src/interfaces/timer-job/timer-job-props.ts +17 -0
- 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 +111 -111
- 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.ts +104 -0
- package/src/resources/lambda/createLambda.ts +203 -200
- 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/tsconfig.json +44 -42
|
@@ -1,134 +1,134 @@
|
|
|
1
|
-
import { IRole } from "aws-cdk-lib/aws-iam";
|
|
2
|
-
import { LayerVersion } from "aws-cdk-lib/aws-lambda";
|
|
3
|
-
import { Construct } from "constructs";
|
|
4
|
-
import { TsgLambdaProp } from "../../config/types";
|
|
5
|
-
import { NodejsFunction, NodejsFunctionProps, SourceMapMode } from "aws-cdk-lib/aws-lambda-nodejs";
|
|
6
|
-
import { TsgLambdaProps } from "../../config/types/TsgLambdaProps";
|
|
7
|
-
import { CreateLambdaFunctionInput } from "../../interfaces/CreateLambdaFunctionInput";
|
|
8
|
-
import * as path from "node:path";
|
|
9
|
-
import { AppConfig } from "../../config/AppConfig";
|
|
10
|
-
import { RetentionDays } from "aws-cdk-lib/aws-logs";
|
|
11
|
-
import { Duration } from "aws-cdk-lib";
|
|
12
|
-
import { LogDuration } from "../../config/types/LogDuration";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export class LambdaHelper {
|
|
16
|
-
|
|
17
|
-
public static createLambdaFunctions(scope: Construct,
|
|
18
|
-
config: AppConfig,
|
|
19
|
-
lambdaConfigs: TsgLambdaProp | TsgLambdaProp[],
|
|
20
|
-
role?: IRole,
|
|
21
|
-
layers?: LayerVersion[]) {
|
|
22
|
-
|
|
23
|
-
const isArrayOfLambdaProps = Array.isArray(lambdaConfigs);
|
|
24
|
-
|
|
25
|
-
const appConfig = config;
|
|
26
|
-
|
|
27
|
-
if (isArrayOfLambdaProps) {
|
|
28
|
-
const createdLambdas = lambdaConfigs.map((config: TsgLambdaProp) => {
|
|
29
|
-
|
|
30
|
-
return LambdaHelper.createLambda(config, role, layers, appConfig, scope);
|
|
31
|
-
});
|
|
32
|
-
return createdLambdas || [];
|
|
33
|
-
} else {
|
|
34
|
-
return LambdaHelper.createLambda(lambdaConfigs as TsgLambdaProp, role, layers, config, scope);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private static createLambda(config: TsgLambdaProp,
|
|
39
|
-
role: IRole | undefined,
|
|
40
|
-
layers: LayerVersion[] | undefined,
|
|
41
|
-
appConfig: AppConfig,
|
|
42
|
-
scope: Construct) {
|
|
43
|
-
|
|
44
|
-
let lambdaProps = this.createLambdaProps(config, role, layers, {
|
|
45
|
-
appConfig: appConfig,
|
|
46
|
-
role,
|
|
47
|
-
layers,
|
|
48
|
-
scope
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const lambdaId = this.getIdForLambda(config, appConfig);
|
|
52
|
-
let fctn = new NodejsFunction(scope, lambdaId, lambdaProps);
|
|
53
|
-
|
|
54
|
-
if (lambdaId !== fctn.node.id) {
|
|
55
|
-
console.error(`can not find Lambda for : ${fctn.node.id}`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return fctn;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
private static createLambdaProps(prop: TsgLambdaProp,
|
|
62
|
-
role?: IRole,
|
|
63
|
-
layers?: LayerVersion[],
|
|
64
|
-
props?: TsgLambdaProps) {
|
|
65
|
-
|
|
66
|
-
return this.createLambdaFunctionProps({
|
|
67
|
-
prop,
|
|
68
|
-
role,
|
|
69
|
-
layers,
|
|
70
|
-
props
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
private static createLambdaFunctionProps(props: CreateLambdaFunctionInput) {
|
|
75
|
-
const { prop, role, layers } = props;
|
|
76
|
-
|
|
77
|
-
const config = props.props?.appConfig;
|
|
78
|
-
|
|
79
|
-
const lambdaProp: NodejsFunctionProps = {
|
|
80
|
-
entry: path.join(prop.codePath),
|
|
81
|
-
functionName: `${config?.AppPrefix}-${prop.name}`,
|
|
82
|
-
handler: prop.handler,
|
|
83
|
-
logRetention: (!prop.logDuration) ? RetentionDays.FIVE_DAYS :
|
|
84
|
-
LambdaHelper.getDayToSaveLogs(prop.logDuration),
|
|
85
|
-
runtime: prop.runtime || config?.GLOBALS.stackRuntime,
|
|
86
|
-
timeout: prop.duration || Duration.minutes(2),
|
|
87
|
-
memorySize: prop.memory || 512,
|
|
88
|
-
environment: {
|
|
89
|
-
"VERBOSE_LOGGING": "true",
|
|
90
|
-
...prop.environment
|
|
91
|
-
},
|
|
92
|
-
bundling: {
|
|
93
|
-
minify: true,
|
|
94
|
-
target: "ESNext",
|
|
95
|
-
sourceMap: true,
|
|
96
|
-
sourceMapMode: SourceMapMode.EXTERNAL,
|
|
97
|
-
environment: prop.environment || prop.environment,
|
|
98
|
-
},
|
|
99
|
-
role,
|
|
100
|
-
layers
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
return lambdaProp;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
public static getDayToSaveLogs(saveLogDuration: LogDuration): RetentionDays {
|
|
107
|
-
|
|
108
|
-
switch (saveLogDuration) {
|
|
109
|
-
case LogDuration.ONE_DAY:
|
|
110
|
-
return RetentionDays.ONE_DAY;
|
|
111
|
-
|
|
112
|
-
case LogDuration.ONE_WEEK:
|
|
113
|
-
return RetentionDays.ONE_WEEK;
|
|
114
|
-
|
|
115
|
-
case LogDuration.ONE_MONTH:
|
|
116
|
-
return RetentionDays.ONE_MONTH;
|
|
117
|
-
|
|
118
|
-
case LogDuration.ONE_YEAR:
|
|
119
|
-
return RetentionDays.ONE_YEAR;
|
|
120
|
-
|
|
121
|
-
case LogDuration.FIVE_YEARS:
|
|
122
|
-
return RetentionDays.FIVE_YEARS;
|
|
123
|
-
|
|
124
|
-
case LogDuration.FOREVER:
|
|
125
|
-
return RetentionDays.INFINITE;
|
|
126
|
-
default:
|
|
127
|
-
return RetentionDays.FIVE_DAYS;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
public static getIdForLambda(lambdaProp: TsgLambdaProp, appConfig: AppConfig) {
|
|
132
|
-
return `${appConfig.AppPrefix}-${lambdaProp.name}`.toLowerCase();
|
|
133
|
-
}
|
|
1
|
+
import { IRole } from "aws-cdk-lib/aws-iam";
|
|
2
|
+
import { LayerVersion } from "aws-cdk-lib/aws-lambda";
|
|
3
|
+
import { Construct } from "constructs";
|
|
4
|
+
import { TsgLambdaProp } from "../../config/types";
|
|
5
|
+
import { NodejsFunction, NodejsFunctionProps, SourceMapMode } from "aws-cdk-lib/aws-lambda-nodejs";
|
|
6
|
+
import { TsgLambdaProps } from "../../config/types/TsgLambdaProps";
|
|
7
|
+
import { CreateLambdaFunctionInput } from "../../interfaces/CreateLambdaFunctionInput";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
import { AppConfig } from "../../config/AppConfig";
|
|
10
|
+
import { RetentionDays } from "aws-cdk-lib/aws-logs";
|
|
11
|
+
import { Duration } from "aws-cdk-lib";
|
|
12
|
+
import { LogDuration } from "../../config/types/LogDuration";
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export class LambdaHelper {
|
|
16
|
+
|
|
17
|
+
public static createLambdaFunctions(scope: Construct,
|
|
18
|
+
config: AppConfig,
|
|
19
|
+
lambdaConfigs: TsgLambdaProp | TsgLambdaProp[],
|
|
20
|
+
role?: IRole,
|
|
21
|
+
layers?: LayerVersion[]) {
|
|
22
|
+
|
|
23
|
+
const isArrayOfLambdaProps = Array.isArray(lambdaConfigs);
|
|
24
|
+
|
|
25
|
+
const appConfig = config;
|
|
26
|
+
|
|
27
|
+
if (isArrayOfLambdaProps) {
|
|
28
|
+
const createdLambdas = lambdaConfigs.map((config: TsgLambdaProp) => {
|
|
29
|
+
|
|
30
|
+
return LambdaHelper.createLambda(config, role, layers, appConfig, scope);
|
|
31
|
+
});
|
|
32
|
+
return createdLambdas || [];
|
|
33
|
+
} else {
|
|
34
|
+
return LambdaHelper.createLambda(lambdaConfigs as TsgLambdaProp, role, layers, config, scope);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private static createLambda(config: TsgLambdaProp,
|
|
39
|
+
role: IRole | undefined,
|
|
40
|
+
layers: LayerVersion[] | undefined,
|
|
41
|
+
appConfig: AppConfig,
|
|
42
|
+
scope: Construct) {
|
|
43
|
+
|
|
44
|
+
let lambdaProps = this.createLambdaProps(config, role, layers, {
|
|
45
|
+
appConfig: appConfig,
|
|
46
|
+
role,
|
|
47
|
+
layers,
|
|
48
|
+
scope
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const lambdaId = this.getIdForLambda(config, appConfig);
|
|
52
|
+
let fctn = new NodejsFunction(scope, lambdaId, lambdaProps);
|
|
53
|
+
|
|
54
|
+
if (lambdaId !== fctn.node.id) {
|
|
55
|
+
console.error(`can not find Lambda for : ${fctn.node.id}`);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return fctn;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private static createLambdaProps(prop: TsgLambdaProp,
|
|
62
|
+
role?: IRole,
|
|
63
|
+
layers?: LayerVersion[],
|
|
64
|
+
props?: TsgLambdaProps) {
|
|
65
|
+
|
|
66
|
+
return this.createLambdaFunctionProps({
|
|
67
|
+
prop,
|
|
68
|
+
role,
|
|
69
|
+
layers,
|
|
70
|
+
props
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private static createLambdaFunctionProps(props: CreateLambdaFunctionInput) {
|
|
75
|
+
const { prop, role, layers } = props;
|
|
76
|
+
|
|
77
|
+
const config = props.props?.appConfig;
|
|
78
|
+
|
|
79
|
+
const lambdaProp: NodejsFunctionProps = {
|
|
80
|
+
entry: path.join(prop.codePath),
|
|
81
|
+
functionName: `${config?.AppPrefix}-${prop.name}`,
|
|
82
|
+
handler: prop.handler,
|
|
83
|
+
logRetention: (!prop.logDuration) ? RetentionDays.FIVE_DAYS :
|
|
84
|
+
LambdaHelper.getDayToSaveLogs(prop.logDuration),
|
|
85
|
+
runtime: prop.runtime || config?.GLOBALS.stackRuntime,
|
|
86
|
+
timeout: prop.duration || Duration.minutes(2),
|
|
87
|
+
memorySize: prop.memory || 512,
|
|
88
|
+
environment: {
|
|
89
|
+
"VERBOSE_LOGGING": "true",
|
|
90
|
+
...prop.environment
|
|
91
|
+
},
|
|
92
|
+
bundling: {
|
|
93
|
+
minify: true,
|
|
94
|
+
target: "ESNext",
|
|
95
|
+
sourceMap: true,
|
|
96
|
+
sourceMapMode: SourceMapMode.EXTERNAL,
|
|
97
|
+
environment: prop.environment || prop.environment,
|
|
98
|
+
},
|
|
99
|
+
role,
|
|
100
|
+
layers
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
return lambdaProp;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
public static getDayToSaveLogs(saveLogDuration: LogDuration): RetentionDays {
|
|
107
|
+
|
|
108
|
+
switch (saveLogDuration) {
|
|
109
|
+
case LogDuration.ONE_DAY:
|
|
110
|
+
return RetentionDays.ONE_DAY;
|
|
111
|
+
|
|
112
|
+
case LogDuration.ONE_WEEK:
|
|
113
|
+
return RetentionDays.ONE_WEEK;
|
|
114
|
+
|
|
115
|
+
case LogDuration.ONE_MONTH:
|
|
116
|
+
return RetentionDays.ONE_MONTH;
|
|
117
|
+
|
|
118
|
+
case LogDuration.ONE_YEAR:
|
|
119
|
+
return RetentionDays.ONE_YEAR;
|
|
120
|
+
|
|
121
|
+
case LogDuration.FIVE_YEARS:
|
|
122
|
+
return RetentionDays.FIVE_YEARS;
|
|
123
|
+
|
|
124
|
+
case LogDuration.FOREVER:
|
|
125
|
+
return RetentionDays.INFINITE;
|
|
126
|
+
default:
|
|
127
|
+
return RetentionDays.FIVE_DAYS;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
public static getIdForLambda(lambdaProp: TsgLambdaProp, appConfig: AppConfig) {
|
|
132
|
+
return `${appConfig.AppPrefix}-${lambdaProp.name}`.toLowerCase();
|
|
133
|
+
}
|
|
134
134
|
}
|
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import { CfnOutput, Duration } from "aws-cdk-lib";
|
|
2
|
-
import { IdentitySource, TokenAuthorizer, TokenAuthorizerProps } from "aws-cdk-lib/aws-apigateway";
|
|
3
|
-
import { ManagedPolicy, ServicePrincipal } from "aws-cdk-lib/aws-iam";
|
|
4
|
-
import { NodejsFunction, NodejsFunctionProps, SourceMapMode } from "aws-cdk-lib/aws-lambda-nodejs";
|
|
5
|
-
import { Construct } from "constructs";
|
|
6
|
-
import * as path from 'path';
|
|
7
|
-
import { AppConfig } from "../../config/AppConfig";
|
|
8
|
-
|
|
9
|
-
import { TsgLambdaProp } from "../../config/types";
|
|
10
|
-
import { MicroserviceProps } from "../../interfaces/MicroserviceProps";
|
|
11
|
-
import { BaseResource } from "../base/baseResource";
|
|
12
|
-
import { CreateLambda } from "../lambda/createLambda";
|
|
13
|
-
|
|
14
|
-
export class TsgJwtTokenAuthorizer extends BaseResource<TokenAuthorizer> {
|
|
15
|
-
|
|
16
|
-
get JwtAuthorizer() {
|
|
17
|
-
return this.createdResources[0];
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
constructor(scope: Construct, props: AppConfig) {
|
|
21
|
-
|
|
22
|
-
super(scope, props);
|
|
23
|
-
|
|
24
|
-
this.createdResources = this.createResource(scope)!;
|
|
25
|
-
|
|
26
|
-
if (this.createdResources) {
|
|
27
|
-
this.createOutput<TokenAuthorizer>(scope, this.createdResources);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
protected createResource(scope: Construct): TokenAuthorizer[] | null {
|
|
33
|
-
return [this.createLambdaAuthorizer(scope, this.config.RESOURCES.AUTHORIZER!)];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private createLambdaAuthorizer(scope: Construct, lambdaConfig: TsgLambdaProp) {
|
|
37
|
-
//console.log("ENTER createLambdaAuthorizer");
|
|
38
|
-
|
|
39
|
-
const authorizerProps = this.createLambdaFunctionProps(lambdaConfig!);
|
|
40
|
-
|
|
41
|
-
const lambdaId = CreateLambda.getIdForLambda(lambdaConfig, this.config);
|
|
42
|
-
const lambda = new NodejsFunction(scope, lambdaId, authorizerProps);
|
|
43
|
-
|
|
44
|
-
lambda.grantInvoke(new ServicePrincipal('apigateway.amazonaws.com'));
|
|
45
|
-
|
|
46
|
-
if (lambdaConfig?.managedPolicies && lambdaConfig.managedPolicies.length > 0) {
|
|
47
|
-
this.assignManagedPolicies(lambda, lambdaConfig.managedPolicies);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const props: TokenAuthorizerProps = {
|
|
51
|
-
handler: lambda,
|
|
52
|
-
authorizerName: lambdaConfig.name,
|
|
53
|
-
resultsCacheTtl: Duration.seconds(0),
|
|
54
|
-
identitySource: IdentitySource.header('Authorization'),
|
|
55
|
-
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const lambdaAuthorizer = new TokenAuthorizer(scope, `${lambdaConfig.name}-authorizer`, props);
|
|
59
|
-
|
|
60
|
-
return lambdaAuthorizer;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
protected createOutput<T>(scope: Construct, createdAssets: T[]): void {
|
|
64
|
-
|
|
65
|
-
const entity = createdAssets[0];
|
|
66
|
-
|
|
67
|
-
// new CfnOutput(scope, `authorizer`, {
|
|
68
|
-
// value: (entity as TokenAuthorizer).authorizerArn
|
|
69
|
-
// });
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
private createLambdaFunctionProps(prop: TsgLambdaProp) {
|
|
74
|
-
|
|
75
|
-
const lambdaProp: NodejsFunctionProps = {
|
|
76
|
-
entry: path.join(prop.codePath),
|
|
77
|
-
functionName: prop.name,
|
|
78
|
-
handler: prop.handler,
|
|
79
|
-
runtime: prop.runtime || this.config.GLOBALS.stackRuntime,
|
|
80
|
-
timeout: prop.duration || Duration.minutes(2),
|
|
81
|
-
memorySize: prop.memory || 512,
|
|
82
|
-
environment: {
|
|
83
|
-
"VERBOSE_LOGGING": "true",
|
|
84
|
-
...prop.environment
|
|
85
|
-
},
|
|
86
|
-
bundling: {
|
|
87
|
-
minify: false,
|
|
88
|
-
target: 'es2020',
|
|
89
|
-
sourceMap: true,
|
|
90
|
-
sourceMapMode: SourceMapMode.INLINE,
|
|
91
|
-
environment: prop.environment || prop.environment,
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
return lambdaProp;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
private assignManagedPolicies(lambda: NodejsFunction, managedPolicyNames: string[]) {
|
|
98
|
-
|
|
99
|
-
managedPolicyNames.forEach((managedPolicyName: string) => {
|
|
100
|
-
|
|
101
|
-
let policy = ManagedPolicy.fromAwsManagedPolicyName(managedPolicyName);
|
|
102
|
-
|
|
103
|
-
lambda.role?.addManagedPolicy(policy);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
1
|
+
import { CfnOutput, Duration } from "aws-cdk-lib";
|
|
2
|
+
import { IdentitySource, TokenAuthorizer, TokenAuthorizerProps } from "aws-cdk-lib/aws-apigateway";
|
|
3
|
+
import { ManagedPolicy, ServicePrincipal } from "aws-cdk-lib/aws-iam";
|
|
4
|
+
import { NodejsFunction, NodejsFunctionProps, SourceMapMode } from "aws-cdk-lib/aws-lambda-nodejs";
|
|
5
|
+
import { Construct } from "constructs";
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { AppConfig } from "../../config/AppConfig";
|
|
8
|
+
|
|
9
|
+
import { TsgLambdaProp } from "../../config/types";
|
|
10
|
+
import { MicroserviceProps } from "../../interfaces/MicroserviceProps";
|
|
11
|
+
import { BaseResource } from "../base/baseResource";
|
|
12
|
+
import { CreateLambda } from "../lambda/createLambda";
|
|
13
|
+
|
|
14
|
+
export class TsgJwtTokenAuthorizer extends BaseResource<TokenAuthorizer> {
|
|
15
|
+
|
|
16
|
+
get JwtAuthorizer() {
|
|
17
|
+
return this.createdResources[0];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
constructor(scope: Construct, props: AppConfig) {
|
|
21
|
+
|
|
22
|
+
super(scope, props);
|
|
23
|
+
|
|
24
|
+
this.createdResources = this.createResource(scope)!;
|
|
25
|
+
|
|
26
|
+
if (this.createdResources) {
|
|
27
|
+
this.createOutput<TokenAuthorizer>(scope, this.createdResources);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
protected createResource(scope: Construct): TokenAuthorizer[] | null {
|
|
33
|
+
return [this.createLambdaAuthorizer(scope, this.config.RESOURCES.AUTHORIZER!)];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private createLambdaAuthorizer(scope: Construct, lambdaConfig: TsgLambdaProp) {
|
|
37
|
+
//console.log("ENTER createLambdaAuthorizer");
|
|
38
|
+
|
|
39
|
+
const authorizerProps = this.createLambdaFunctionProps(lambdaConfig!);
|
|
40
|
+
|
|
41
|
+
const lambdaId = CreateLambda.getIdForLambda(lambdaConfig, this.config);
|
|
42
|
+
const lambda = new NodejsFunction(scope, lambdaId, authorizerProps);
|
|
43
|
+
|
|
44
|
+
lambda.grantInvoke(new ServicePrincipal('apigateway.amazonaws.com'));
|
|
45
|
+
|
|
46
|
+
if (lambdaConfig?.managedPolicies && lambdaConfig.managedPolicies.length > 0) {
|
|
47
|
+
this.assignManagedPolicies(lambda, lambdaConfig.managedPolicies);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const props: TokenAuthorizerProps = {
|
|
51
|
+
handler: lambda,
|
|
52
|
+
authorizerName: lambdaConfig.name,
|
|
53
|
+
resultsCacheTtl: Duration.seconds(0),
|
|
54
|
+
identitySource: IdentitySource.header('Authorization'),
|
|
55
|
+
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const lambdaAuthorizer = new TokenAuthorizer(scope, `${lambdaConfig.name}-authorizer`, props);
|
|
59
|
+
|
|
60
|
+
return lambdaAuthorizer;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected createOutput<T>(scope: Construct, createdAssets: T[]): void {
|
|
64
|
+
|
|
65
|
+
const entity = createdAssets[0];
|
|
66
|
+
|
|
67
|
+
// new CfnOutput(scope, `authorizer`, {
|
|
68
|
+
// value: (entity as TokenAuthorizer).authorizerArn
|
|
69
|
+
// });
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
private createLambdaFunctionProps(prop: TsgLambdaProp) {
|
|
74
|
+
|
|
75
|
+
const lambdaProp: NodejsFunctionProps = {
|
|
76
|
+
entry: path.join(prop.codePath),
|
|
77
|
+
functionName: prop.name,
|
|
78
|
+
handler: prop.handler,
|
|
79
|
+
runtime: prop.runtime || this.config.GLOBALS.stackRuntime,
|
|
80
|
+
timeout: prop.duration || Duration.minutes(2),
|
|
81
|
+
memorySize: prop.memory || 512,
|
|
82
|
+
environment: {
|
|
83
|
+
"VERBOSE_LOGGING": "true",
|
|
84
|
+
...prop.environment
|
|
85
|
+
},
|
|
86
|
+
bundling: {
|
|
87
|
+
minify: false,
|
|
88
|
+
target: 'es2020',
|
|
89
|
+
sourceMap: true,
|
|
90
|
+
sourceMapMode: SourceMapMode.INLINE,
|
|
91
|
+
environment: prop.environment || prop.environment,
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
return lambdaProp;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
private assignManagedPolicies(lambda: NodejsFunction, managedPolicyNames: string[]) {
|
|
98
|
+
|
|
99
|
+
managedPolicyNames.forEach((managedPolicyName: string) => {
|
|
100
|
+
|
|
101
|
+
let policy = ManagedPolicy.fromAwsManagedPolicyName(managedPolicyName);
|
|
102
|
+
|
|
103
|
+
lambda.role?.addManagedPolicy(policy);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
108
|
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { RequestAuthorizer } from "aws-cdk-lib/aws-apigateway";
|
|
2
|
-
import { Construct } from "constructs";
|
|
3
|
-
import { AppConfig } from "../../config/AppConfig";
|
|
4
|
-
import { BaseResource } from "../base/baseResource";
|
|
5
|
-
|
|
6
|
-
import { CfnOutput } from "aws-cdk-lib";
|
|
7
|
-
import { createAuthorizer } from "./createAuthorizerHelpers";
|
|
8
|
-
import { LayerVersion } from "aws-cdk-lib/aws-lambda";
|
|
9
|
-
import { ITableV2 } from "aws-cdk-lib/aws-dynamodb";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export class TsgRequestAuthorizer extends BaseResource<RequestAuthorizer> {
|
|
13
|
-
|
|
14
|
-
get TsgRequestAuthorizer() {
|
|
15
|
-
return this.createdResources[0];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
constructor(scope: Construct,
|
|
19
|
-
config: AppConfig,
|
|
20
|
-
private layers?: LayerVersion[],
|
|
21
|
-
private tables?: ITableV2[]) {
|
|
22
|
-
super(scope, config);
|
|
23
|
-
|
|
24
|
-
this.createdResources = this.createResource(scope)!;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
protected createResource(scope: Construct): RequestAuthorizer[] | null {
|
|
28
|
-
|
|
29
|
-
const authorizer = createAuthorizer(scope, this.config, this.layers, this.tables);
|
|
30
|
-
|
|
31
|
-
return [authorizer];
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
protected createOutput<T>(scope: Construct, createdAssets: T[]): void {
|
|
36
|
-
createdAssets?.forEach((asset) => {
|
|
37
|
-
if (asset instanceof RequestAuthorizer) {
|
|
38
|
-
// Output the ARN of the authorizer
|
|
39
|
-
new CfnOutput(scope, "RequestAuthorizerArn", {
|
|
40
|
-
value: `${asset.authorizationType}:${asset.authorizerArn}`
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
1
|
+
import { RequestAuthorizer } from "aws-cdk-lib/aws-apigateway";
|
|
2
|
+
import { Construct } from "constructs";
|
|
3
|
+
import { AppConfig } from "../../config/AppConfig";
|
|
4
|
+
import { BaseResource } from "../base/baseResource";
|
|
5
|
+
|
|
6
|
+
import { CfnOutput } from "aws-cdk-lib";
|
|
7
|
+
import { createAuthorizer } from "./createAuthorizerHelpers";
|
|
8
|
+
import { LayerVersion } from "aws-cdk-lib/aws-lambda";
|
|
9
|
+
import { ITableV2 } from "aws-cdk-lib/aws-dynamodb";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
export class TsgRequestAuthorizer extends BaseResource<RequestAuthorizer> {
|
|
13
|
+
|
|
14
|
+
get TsgRequestAuthorizer() {
|
|
15
|
+
return this.createdResources[0];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
constructor(scope: Construct,
|
|
19
|
+
config: AppConfig,
|
|
20
|
+
private layers?: LayerVersion[],
|
|
21
|
+
private tables?: ITableV2[]) {
|
|
22
|
+
super(scope, config);
|
|
23
|
+
|
|
24
|
+
this.createdResources = this.createResource(scope)!;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected createResource(scope: Construct): RequestAuthorizer[] | null {
|
|
28
|
+
|
|
29
|
+
const authorizer = createAuthorizer(scope, this.config, this.layers, this.tables);
|
|
30
|
+
|
|
31
|
+
return [authorizer];
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
protected createOutput<T>(scope: Construct, createdAssets: T[]): void {
|
|
36
|
+
createdAssets?.forEach((asset) => {
|
|
37
|
+
if (asset instanceof RequestAuthorizer) {
|
|
38
|
+
// Output the ARN of the authorizer
|
|
39
|
+
new CfnOutput(scope, "RequestAuthorizerArn", {
|
|
40
|
+
value: `${asset.authorizationType}:${asset.authorizerArn}`
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
45
|
}
|