@sylvesterllc/aws-constructs 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 (175) hide show
  1. package/.github/workflows/publish.yml +36 -0
  2. package/dist/config/AppConfig.d.ts +24 -0
  3. package/dist/config/AppConfig.js +62 -0
  4. package/dist/config/Constants.d.ts +26 -0
  5. package/dist/config/Constants.js +30 -0
  6. package/dist/config/Environments.d.ts +2 -0
  7. package/dist/config/Environments.js +3 -0
  8. package/dist/config/MicroserviceAppConfig.d.ts +5 -0
  9. package/dist/config/MicroserviceAppConfig.js +11 -0
  10. package/dist/config/bishopConfig.d.ts +2 -0
  11. package/dist/config/bishopConfig.js +81 -0
  12. package/dist/config/customConfigs/ApiAppConfig.d.ts +5 -0
  13. package/dist/config/customConfigs/ApiAppConfig.js +4 -0
  14. package/dist/config/customConfigs/GlobalAppConfig.d.ts +8 -0
  15. package/dist/config/customConfigs/GlobalAppConfig.js +3 -0
  16. package/dist/config/customConfigs/IAppConfig.d.ts +10 -0
  17. package/dist/config/customConfigs/IAppConfig.js +3 -0
  18. package/dist/config/customConfigs/ResourceAppConfig.d.ts +8 -0
  19. package/dist/config/customConfigs/ResourceAppConfig.js +3 -0
  20. package/dist/config/microServiceConfig.d.ts +2 -0
  21. package/dist/config/microServiceConfig.js +82 -0
  22. package/dist/config/types/TsgCdkConfigType.d.ts +3 -0
  23. package/dist/config/types/TsgCdkConfigType.js +3 -0
  24. package/dist/config/types/TsgCognitoConfig.d.ts +5 -0
  25. package/dist/config/types/TsgCognitoConfig.js +3 -0
  26. package/dist/config/types/TsgDnsConfig.d.ts +9 -0
  27. package/dist/config/types/TsgDnsConfig.js +3 -0
  28. package/dist/config/types/TsgDynamoDbProp.d.ts +6 -0
  29. package/dist/config/types/TsgDynamoDbProp.js +3 -0
  30. package/dist/config/types/TsgDynamoIndex.d.ts +13 -0
  31. package/dist/config/types/TsgDynamoIndex.js +3 -0
  32. package/dist/config/types/TsgDynamoProp.d.ts +15 -0
  33. package/dist/config/types/TsgDynamoProp.js +3 -0
  34. package/dist/config/types/TsgDynamoTable.d.ts +4 -0
  35. package/dist/config/types/TsgDynamoTable.js +3 -0
  36. package/dist/config/types/TsgDynamoTableRef.d.ts +4 -0
  37. package/dist/config/types/TsgDynamoTableRef.js +3 -0
  38. package/dist/config/types/TsgLambda.d.ts +4 -0
  39. package/dist/config/types/TsgLambda.js +3 -0
  40. package/dist/config/types/TsgLambdaLayerProp.d.ts +5 -0
  41. package/dist/config/types/TsgLambdaLayerProp.js +3 -0
  42. package/dist/config/types/TsgLambdaMap.d.ts +3 -0
  43. package/dist/config/types/TsgLambdaMap.js +3 -0
  44. package/dist/config/types/TsgLambdaName.d.ts +1 -0
  45. package/dist/config/types/TsgLambdaName.js +3 -0
  46. package/dist/config/types/TsgLambdaNode.d.ts +3 -0
  47. package/dist/config/types/TsgLambdaNode.js +3 -0
  48. package/dist/config/types/TsgLambdaProp.d.ts +16 -0
  49. package/dist/config/types/TsgLambdaProp.js +3 -0
  50. package/dist/config/types/TsgLambdaProps.d.ts +16 -0
  51. package/dist/config/types/TsgLambdaProps.js +3 -0
  52. package/dist/config/types/TsgLambdaRoutable.d.ts +6 -0
  53. package/dist/config/types/TsgLambdaRoutable.js +3 -0
  54. package/dist/config/types/index.d.ts +8 -0
  55. package/dist/config/types/index.js +25 -0
  56. package/dist/constructs/MicroService.d.ts +12 -0
  57. package/dist/constructs/MicroService.js +47 -0
  58. package/dist/constructs/index.d.ts +1 -0
  59. package/dist/constructs/index.js +6 -0
  60. package/dist/index.d.ts +4 -0
  61. package/dist/index.js +8 -0
  62. package/dist/interfaces/CreateLambdaFunctionInput.d.ts +10 -0
  63. package/dist/interfaces/CreateLambdaFunctionInput.js +3 -0
  64. package/dist/interfaces/MicroserviceProps.d.ts +10 -0
  65. package/dist/interfaces/MicroserviceProps.js +3 -0
  66. package/dist/resources/base/baseResource.d.ts +10 -0
  67. package/dist/resources/base/baseResource.js +11 -0
  68. package/dist/resources/certificate/createCertificate.d.ts +9 -0
  69. package/dist/resources/certificate/createCertificate.js +29 -0
  70. package/dist/resources/cognito/createCognito.d.ts +7 -0
  71. package/dist/resources/cognito/createCognito.js +35 -0
  72. package/dist/resources/cognito/createCognitoProps.d.ts +2 -0
  73. package/dist/resources/cognito/createCognitoProps.js +47 -0
  74. package/dist/resources/dynamodb/CreateDynamo.d.ts +15 -0
  75. package/dist/resources/dynamodb/CreateDynamo.js +87 -0
  76. package/dist/resources/gateway/createApi.d.ts +19 -0
  77. package/dist/resources/gateway/createApi.js +104 -0
  78. package/dist/resources/gateway/createMicroServiceBundle.d.ts +25 -0
  79. package/dist/resources/gateway/createMicroServiceBundle.js +126 -0
  80. package/dist/resources/helpers/createAuthorizer.d.ts +15 -0
  81. package/dist/resources/helpers/createAuthorizer.js +80 -0
  82. package/dist/resources/helpers/createCommonLayer.d.ts +3 -0
  83. package/dist/resources/helpers/createCommonLayer.js +15 -0
  84. package/dist/resources/helpers/createRoutes.d.ts +8 -0
  85. package/dist/resources/helpers/createRoutes.js +30 -0
  86. package/dist/resources/lambda/createLambda.d.ts +20 -0
  87. package/dist/resources/lambda/createLambda.js +135 -0
  88. package/dist/resources/lambda-layer/createLambdaLayer.d.ts +5 -0
  89. package/dist/resources/lambda-layer/createLambdaLayer.js +31 -0
  90. package/dist/resources/layers/common/src/nodejs/api-response/index.d.ts +1 -0
  91. package/dist/resources/layers/common/src/nodejs/api-response/index.js +18 -0
  92. package/dist/resources/layers/common/src/nodejs/api-response/responses.d.ts +24 -0
  93. package/dist/resources/layers/common/src/nodejs/api-response/responses.js +43 -0
  94. package/dist/resources/layers/common/src/nodejs/index.d.ts +2 -0
  95. package/dist/resources/layers/common/src/nodejs/index.js +19 -0
  96. package/dist/resources/layers/common/src/nodejs/logger/IContext.d.ts +5 -0
  97. package/dist/resources/layers/common/src/nodejs/logger/IContext.js +3 -0
  98. package/dist/resources/layers/common/src/nodejs/logger/index.d.ts +2 -0
  99. package/dist/resources/layers/common/src/nodejs/logger/index.js +19 -0
  100. package/dist/resources/layers/common/src/nodejs/logger/logger.d.ts +2 -0
  101. package/dist/resources/layers/common/src/nodejs/logger/logger.js +12 -0
  102. package/dist/resources/resources/iam/policyDocuments/cognitoPolicy.d.ts +4 -0
  103. package/dist/resources/resources/iam/policyDocuments/cognitoPolicy.js +52 -0
  104. package/dist/resources/resources/iam/roles/createRole.d.ts +4 -0
  105. package/dist/resources/resources/iam/roles/createRole.js +22 -0
  106. package/dist/resources/route53/CreateZone.d.ts +0 -0
  107. package/dist/resources/route53/CreateZone.js +47 -0
  108. package/dist/resources/route53/create-zones.d.ts +0 -0
  109. package/dist/resources/route53/create-zones.js +30 -0
  110. package/dist/resources/securityManager/index.d.ts +4 -0
  111. package/dist/resources/securityManager/index.js +18 -0
  112. package/docs/lambda-config.md +1 -0
  113. package/package.json +48 -0
  114. package/readme.md +147 -0
  115. package/src/config/AppConfig.ts +93 -0
  116. package/src/config/Constants.ts +27 -0
  117. package/src/config/Environments.ts +2 -0
  118. package/src/config/MicroserviceAppConfig.ts +9 -0
  119. package/src/config/bishopConfig.ts +83 -0
  120. package/src/config/customConfigs/ApiAppConfig.ts +6 -0
  121. package/src/config/customConfigs/GlobalAppConfig.ts +11 -0
  122. package/src/config/customConfigs/IAppConfig.ts +13 -0
  123. package/src/config/customConfigs/ResourceAppConfig.ts +12 -0
  124. package/src/config/microServiceConfig.ts +85 -0
  125. package/src/config/types/TsgCdkConfigType.ts +3 -0
  126. package/src/config/types/TsgCognitoConfig.ts +6 -0
  127. package/src/config/types/TsgDnsConfig.ts +9 -0
  128. package/src/config/types/TsgDynamoDbProp.ts +7 -0
  129. package/src/config/types/TsgDynamoIndex.ts +16 -0
  130. package/src/config/types/TsgDynamoProp.ts +17 -0
  131. package/src/config/types/TsgDynamoTable.ts +5 -0
  132. package/src/config/types/TsgDynamoTableRef.ts +4 -0
  133. package/src/config/types/TsgLambda.ts +6 -0
  134. package/src/config/types/TsgLambdaLayerProp.ts +5 -0
  135. package/src/config/types/TsgLambdaMap.ts +4 -0
  136. package/src/config/types/TsgLambdaName.ts +4 -0
  137. package/src/config/types/TsgLambdaNode.ts +4 -0
  138. package/src/config/types/TsgLambdaProp.ts +16 -0
  139. package/src/config/types/TsgLambdaProps.ts +19 -0
  140. package/src/config/types/TsgLambdaRoutable.ts +6 -0
  141. package/src/config/types/index.ts +9 -0
  142. package/src/constructs/MicroService.ts +68 -0
  143. package/src/constructs/index.ts +1 -0
  144. package/src/index.ts +4 -0
  145. package/src/interfaces/CreateLambdaFunctionInput.ts +11 -0
  146. package/src/interfaces/MicroserviceProps.ts +11 -0
  147. package/src/resources/.gitkeep +0 -0
  148. package/src/resources/base/baseResource.ts +15 -0
  149. package/src/resources/certificate/createCertificate.ts +40 -0
  150. package/src/resources/cicd/.gitkeep +0 -0
  151. package/src/resources/cognito/.gitkeep +0 -0
  152. package/src/resources/cognito/createCognito.ts +47 -0
  153. package/src/resources/cognito/createCognitoProps.ts +46 -0
  154. package/src/resources/dynamodb/CreateDynamo.ts +111 -0
  155. package/src/resources/gateway/createApi.ts +138 -0
  156. package/src/resources/gateway/createMicroServiceBundle.ts +183 -0
  157. package/src/resources/helpers/createAuthorizer.ts +106 -0
  158. package/src/resources/helpers/createCommonLayer.ts +18 -0
  159. package/src/resources/helpers/createRoutes.ts +43 -0
  160. package/src/resources/lambda/createLambda.ts +184 -0
  161. package/src/resources/lambda-layer/createLambdaLayer.ts +40 -0
  162. package/src/resources/layers/common/package.json +22 -0
  163. package/src/resources/layers/common/src/nodejs/api-response/index.ts +1 -0
  164. package/src/resources/layers/common/src/nodejs/api-response/responses.ts +41 -0
  165. package/src/resources/layers/common/src/nodejs/index.ts +3 -0
  166. package/src/resources/layers/common/src/nodejs/logger/IContext.ts +7 -0
  167. package/src/resources/layers/common/src/nodejs/logger/index.ts +2 -0
  168. package/src/resources/layers/common/src/nodejs/logger/logger.ts +11 -0
  169. package/src/resources/layers/common/tsconfig.json +7 -0
  170. package/src/resources/resources/iam/policyDocuments/cognitoPolicy.ts +55 -0
  171. package/src/resources/resources/iam/roles/createRole.ts +30 -0
  172. package/src/resources/route53/CreateZone.ts +62 -0
  173. package/src/resources/route53/create-zones.ts +41 -0
  174. package/src/resources/securityManager/index.ts +24 -0
  175. package/tsconfig.json +40 -0
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@sylvesterllc/aws-constructs",
3
+ "version": "1.0.0",
4
+ "description": "AWS Constructs",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "build": "npm run clean && tsc",
8
+ "build:layers": "cd ./src/resources/layers/common && pnpm i && tsc",
9
+ "watch": "tsc -w",
10
+ "test": "jest",
11
+ "cdk": "cdk",
12
+ "clean": "rm -rf dist",
13
+ "clean:layers": "rm -rf ./src/resources/layers/common/dist",
14
+ "publish:lib": "npm run build && npm publish",
15
+ "preinstall": "npx only-allow pnpm"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/DavisSylvester/aws-constructs.git"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "author": "Davis Sylvester <davis@sylvesterllc.com>",
25
+ "license": "ISC",
26
+ "bugs": {
27
+ "url": "https://github.com/DavisSylvester/aws-constructs/issues"
28
+ },
29
+ "homepage": "https://github.com/DavisSylvester/aws-constructs#readme",
30
+ "devDependencies": {
31
+ "@types/jest": "^29.5.0",
32
+ "@types/luxon": "^3.2.0",
33
+ "@types/node": "^18.15.3",
34
+ "jest": "^29.5.0",
35
+ "ts-jest": "^29.0.5",
36
+ "ts-node": "^10.9.1",
37
+ "typescript": "^5.0.2"
38
+ },
39
+ "dependencies": {
40
+
41
+ "aws-cdk-lib": "^2.69.0",
42
+ "constructs": "^10.1.280",
43
+ "dotenv": "^16.0.3",
44
+ "fsbin": "^1.0.11",
45
+ "luxon": "^3.3.0",
46
+ "source-map-support": "^0.5.21"
47
+ }
48
+ }
package/readme.md ADDED
@@ -0,0 +1,147 @@
1
+ # Bishop CDK Construct Library
2
+
3
+ ## Bishop Constructs <a name="Constructs" id="Constructs"></a>
4
+
5
+ Bishop Constructs is a construct library for creating new AWS Infrastructure in a standardize
6
+ reusable manner.
7
+
8
+ [![Publish package to GitHub Packages](https://github.com/DavisSylvester/aws-constructs/actions/workflows/publish.yaml/badge.svg?branch=main)](https://github.com/DavisSylvester/aws-constructs/actions/workflows/publish.yaml)
9
+
10
+ ### Available Constructors
11
+
12
+ - [Microservice](#microservice-construct)
13
+
14
+ And more...
15
+
16
+ ## Installation
17
+
18
+ 1. Install the npm package:
19
+
20
+ `npm install @davissylvester/bishop-cdk-constructs --save`
21
+ - *ensure you have a `.npmrc` that uses the @sylvesterllc npm registry*
22
+
23
+
24
+
25
+ # Microservice Construct
26
+ The Microservice construct provides and easy way to get started with a basic Microservice.
27
+
28
+ #### Infrastructure
29
+ - API Gateway (Rest API)
30
+ - Lambda
31
+ - Dynamodb
32
+ - Lambda Authorizer
33
+ - TokenAuthorizer
34
+
35
+ #### Access
36
+ *All lambdas are created with Read/Write Access to DynamoDB tables*
37
+
38
+ ### Usage
39
+ ```typescript
40
+ import { MicroService, MicroserviceProps } from '@davissylvester/bishop-cdk-constructs';
41
+
42
+ new MicroService(this, 'microservice-test', microServiceProps);
43
+ ```
44
+
45
+ ## MicroserviceProps
46
+
47
+ ```json
48
+ const microServiceProps: MicroserviceProps = {
49
+ GLOBALS: {
50
+ name: `sample-test-app`,
51
+ environments: "dev",
52
+ stackRuntime: Runtime.NODEJS_18_X,
53
+ },
54
+ API: {
55
+ Name: `sample-test-app`,
56
+ Description: 'This is my new API'
57
+ },
58
+ RESOURCES: {
59
+ AUTHORIZER: {
60
+ name: `jwt-authorizer`,
61
+ codePath: './lambda-functions/authorizer/index.ts',
62
+ handler: 'handler',
63
+ apiPathRoot: '',
64
+ route: '',
65
+ },
66
+ LAMBDA: [
67
+ {
68
+ name: `hello-world`,
69
+ codePath: './lambda-functions/hello-world/index.ts',
70
+ handler: 'main',
71
+ method: 'get',
72
+ apiPathRoot: 'hello-world',
73
+ route: '/hello-world'
74
+ },
75
+ {
76
+ name: `hellow-world2`,
77
+ codePath: './lambda-functions/hello-world/index.ts',
78
+ handler: 'main',
79
+ method: 'get',
80
+ apiPathRoot: '/hello-world/2',
81
+ route: '/hello-world/2'
82
+ },
83
+ {
84
+ name: `hello-world3`,
85
+ codePath: './lambda-functions/hello-world/index.ts',
86
+ handler: 'main',
87
+ method: 'get',
88
+ apiPathRoot: '/hello-world/2',
89
+ route: '/hello-world/2/{id}',
90
+ secure: true
91
+ },
92
+ ],
93
+ DYNAMO: {
94
+ TABLES: [
95
+ {
96
+ tableName: `sample-audit-history`,
97
+ primaryKey: {
98
+ name: 'id',
99
+ type: AttributeType.STRING,
100
+ },
101
+ billingMode: BillingMode.PAY_PER_REQUEST,
102
+ indexes: [
103
+ {
104
+ indexName: 'createdTS',
105
+ partitionKey: {
106
+ name: 'createdTS',
107
+ type: AttributeType.NUMBER
108
+ },
109
+ projectionType: ProjectionType.ALL
110
+ },
111
+ {
112
+ indexName: 'username',
113
+ partitionKey: {
114
+ name: 'username',
115
+ type: AttributeType.STRING
116
+ },
117
+ projectionType: ProjectionType.ALL
118
+ },
119
+ ]
120
+ },
121
+ ],
122
+ },
123
+
124
+ }
125
+ };
126
+ ```
127
+
128
+
129
+ ## Best Practice
130
+ When using this library it is a good practice to start with a new CDK project
131
+
132
+ - `npm install -g typescript aws-cdk`
133
+ - `mkdir my-new-project`
134
+ - `cd my-new-project`
135
+ - `cdk init app --language typescript`
136
+ - `npm i @davissylvester/bishop-cdk-constructs`
137
+ - `mkdir lambda-functions` (*holds all your lambda code*)
138
+
139
+ # [Demo Project](https://github.com/davissylvester/bishop-cdk-constructs-demo.git)
140
+
141
+ - Clone the repository
142
+ - `git clone https://github.com/davissylvester/bishop-cdk-constructs-demo.git`
143
+ - `npm i`
144
+ - `cdk bootstrap`
145
+ - `cdk deploy`
146
+
147
+
@@ -0,0 +1,93 @@
1
+ import { config } from "process";
2
+ import { ApiAppConfig } from "./customConfigs/ApiAppConfig";
3
+ import { GlobalAppConfig } from "./customConfigs/GlobalAppConfig";
4
+ import { IAppConfig } from "./customConfigs/IAppConfig";
5
+ import { ResourceAppConfig } from "./customConfigs/ResourceAppConfig";
6
+ import { TsgDynamoProp } from "./types";
7
+ import { TsgDnsAppConfig } from "./types/TsgDnsConfig";
8
+ import { TsgLambdaName } from "./types/TsgLambdaName";
9
+ import { TsgLambdaProp } from "./types/TsgLambdaProp";
10
+
11
+ export class AppConfig implements IAppConfig {
12
+
13
+ public API: ApiAppConfig;
14
+ public GLOBALS: GlobalAppConfig;
15
+ public RESOURCES: ResourceAppConfig;
16
+ public DNS: TsgDnsAppConfig;
17
+
18
+
19
+ public lambdaConfigs: TsgLambdaProp[];
20
+ public dynamoConfigs: TsgDynamoProp[];
21
+
22
+ get AppName() {
23
+ return this.GLOBALS.name;
24
+ }
25
+
26
+ get AppPrefix() {
27
+ return (this.GLOBALS.prefix) ? this.GLOBALS.prefix : this.GLOBALS.name;
28
+ }
29
+
30
+ constructor(config: IAppConfig) {
31
+ this.populate(config);
32
+ }
33
+
34
+ private populate(config: IAppConfig) {
35
+ this.populateGlobalConfig(config);
36
+ this.populateApiConfig(config);
37
+ this.populateResources(config);
38
+
39
+
40
+ }
41
+
42
+ private populateGlobalConfig(config: IAppConfig) {
43
+ this.GLOBALS = {
44
+ ...config.GLOBALS
45
+ };
46
+ }
47
+
48
+ private populateApiConfig(config: IAppConfig) {
49
+
50
+ if (config.API)
51
+ this.API = {
52
+ ...config.API
53
+ };
54
+ }
55
+
56
+ private populateResources(config: IAppConfig) {
57
+ this.RESOURCES = {
58
+ ...config.RESOURCES
59
+ };
60
+ this.RESOURCES.DYNAMO = {
61
+ ...config.RESOURCES.DYNAMO
62
+ };
63
+
64
+ this.DNS = {
65
+ ...config.DNS
66
+ };
67
+ }
68
+ // this.lambdaConfigs = this.expandProps<TsgLambdaName, TsgLambdaProp>(this.RESOURCES.LAMBDA!);
69
+ // this.dynamoConfigs = this.expandProps<TsgTableName, TsgDynamoProp>(this.RESOURCES.DYNAMO?.TABLES!);
70
+ // }
71
+
72
+ private populateConfigs<T, R>(result: R[], record?: Record<string, R>) {
73
+
74
+ if (!record) {
75
+ return null;
76
+ }
77
+
78
+ result = this.expandProps<T, R>(record);
79
+ return result;
80
+
81
+ }
82
+
83
+ private expandProps<T, R>(data: Record<string, R>) {
84
+
85
+ console.log('data', data);
86
+ const result = [];
87
+ // @ts-ignore
88
+ for (const [key, value] of Object.entries(data)) {
89
+ result.push(value);
90
+ }
91
+ return result as R[];
92
+ }
93
+ }
@@ -0,0 +1,27 @@
1
+ export const CONSTANTS = {
2
+
3
+ DYNAMODB: {
4
+ TABLES: {
5
+ AUTH_HISTORY_TABLE: {
6
+ name: 'auth-history',
7
+ indexes: {
8
+ AuthHistoryTS: {
9
+ name: 'auth-history-ts'
10
+ },
11
+ Username: {
12
+ name: 'username',
13
+ }
14
+ }
15
+ }
16
+ },
17
+ },
18
+ WEB: {
19
+ ADMIN_PORTAL_BUCKET: 'bishop.davissylvester.net',
20
+ },
21
+ AUTH:{
22
+ OAUTH: {
23
+ CLIENT_ID: process.env.AMAZON_OAUTH_CLIENT_ID,
24
+ CLIENT_SECRET: process.env.AMAZON_OAUTH_CLIENT_SECRET
25
+ }
26
+ }
27
+ };
@@ -0,0 +1,2 @@
1
+ export type Environment = "dev" | "qa" | "prod";
2
+ export type ClientAppType = "mobile" | "web";
@@ -0,0 +1,9 @@
1
+ import { MicroserviceProps } from "../interfaces/MicroserviceProps";
2
+ import { AppConfig } from "./AppConfig";
3
+
4
+ export class MicroServiceAppConfig extends AppConfig {
5
+
6
+ constructor(config: MicroserviceProps) {
7
+ super(config);
8
+ }
9
+ }
@@ -0,0 +1,83 @@
1
+ import { AttributeType, BillingMode, ProjectionType } from "aws-cdk-lib/aws-dynamodb";
2
+ import { Runtime } from "aws-cdk-lib/aws-lambda";
3
+ import { CONSTANTS } from "./Constants";
4
+ import { IAppConfig } from "./customConfigs/IAppConfig";
5
+
6
+ export const config: IAppConfig = {
7
+ GLOBALS: {
8
+ name: `${process.env.APP_NAME}`,
9
+ accountNumber: process.env.CDK_DEFAULT_ACCOUNT || "",
10
+ region: process.env.CDK_DEFAULT_REGION || "us-east-1",
11
+ stackRuntime: Runtime.NODEJS_18_X,
12
+ },
13
+ API: {
14
+ Name: `${process.env.APP_NAME}-auth-api`,
15
+ Description: 'This is my new API',
16
+ DomainPrefix: 'my-custom-api'
17
+ },
18
+ RESOURCES: {
19
+ LAMBDA: [
20
+ {
21
+ name: `create-account`,
22
+ codePath: './lambda-functions/auth/createAccount.ts',
23
+ handler: 'main',
24
+ apiGateway: {
25
+ route: '/account/create-account',
26
+ method: 'post',
27
+ },
28
+
29
+ },
30
+ {
31
+ name: `change-password`,
32
+ codePath: './lambda-functions/auth/changePassword.ts',
33
+ handler: 'main',
34
+ apiGateway: {
35
+ route: '/account/change-password',
36
+ method: 'post',
37
+ }
38
+ },
39
+ ],
40
+
41
+ DYNAMO: {
42
+ TABLES: [
43
+ {
44
+ tableName: `${CONSTANTS.DYNAMODB.TABLES.AUTH_HISTORY_TABLE.name}`,
45
+ primaryKey: {
46
+ name: 'id',
47
+ type: AttributeType.STRING,
48
+ },
49
+ billingMode: BillingMode.PAY_PER_REQUEST,
50
+ indexes: [
51
+ {
52
+ indexName: CONSTANTS.DYNAMODB.TABLES.AUTH_HISTORY_TABLE.indexes.AuthHistoryTS.name,
53
+ partitionKey: {
54
+ name: 'createdTS',
55
+ type: AttributeType.NUMBER
56
+ },
57
+ projectionType: ProjectionType.ALL
58
+ },
59
+ {
60
+ indexName: CONSTANTS.DYNAMODB.TABLES.AUTH_HISTORY_TABLE.indexes.Username.name,
61
+ partitionKey: {
62
+ name: 'username',
63
+ type: AttributeType.STRING
64
+ },
65
+ projectionType: ProjectionType.ALL
66
+ },
67
+ ]
68
+ },
69
+ ],
70
+ },
71
+
72
+ },
73
+ DNS: {
74
+ ZoneName: '',
75
+ ZoneId: '',
76
+ ZoneNameWithoutPeriod: 'not-used',
77
+ ZoneNameWithoutSuffix: 'not-used',
78
+ ZoneExist: true,
79
+ HostName: '',
80
+ FQDN: ''
81
+
82
+ }
83
+ };
@@ -0,0 +1,6 @@
1
+ export interface ApiAppConfig {
2
+
3
+ Name: string;
4
+ Description: string;
5
+ DomainPrefix?: string;
6
+ };
@@ -0,0 +1,11 @@
1
+ import { Runtime } from "aws-cdk-lib/aws-lambda";
2
+ import { Environment } from "../Environments";
3
+ export interface GlobalAppConfig {
4
+
5
+
6
+ name: string;
7
+ accountNumber: string;
8
+ region: string;
9
+ stackRuntime: Runtime;
10
+ prefix?: string;
11
+ }
@@ -0,0 +1,13 @@
1
+ import { Environment } from "../Environments";
2
+ import { TsgDnsAppConfig } from "../types/TsgDnsConfig";
3
+ import { ApiAppConfig } from "./ApiAppConfig";
4
+ import { GlobalAppConfig } from "./GlobalAppConfig";
5
+ import { ResourceAppConfig } from "./ResourceAppConfig";
6
+
7
+ export interface IAppConfig {
8
+
9
+ GLOBALS: GlobalAppConfig;
10
+ API?: ApiAppConfig;
11
+ RESOURCES: ResourceAppConfig;
12
+ DNS: TsgDnsAppConfig;
13
+ }
@@ -0,0 +1,12 @@
1
+ import {
2
+ TsgDynamoDbProp,
3
+ TsgLambdaProp,
4
+ } from "../types";
5
+ import { TsgLambdaLayerProp } from "../types/TsgLambdaLayerProp";
6
+
7
+ export interface ResourceAppConfig {
8
+ DYNAMO?: TsgDynamoDbProp;
9
+ LAMBDA_LAYERS?: TsgLambdaLayerProp[];
10
+ AUTHORIZER?: TsgLambdaProp;
11
+ LAMBDA: TsgLambdaProp[];
12
+ }
@@ -0,0 +1,85 @@
1
+ import { AttributeType, BillingMode, ProjectionType } from "aws-cdk-lib/aws-dynamodb";
2
+ import { Runtime } from "aws-cdk-lib/aws-lambda";
3
+ import { CONSTANTS } from "./Constants";
4
+ import { IAppConfig } from "./customConfigs/IAppConfig";
5
+
6
+ export const config: IAppConfig = {
7
+ GLOBALS: {
8
+ name: `${process.env.APP_NAME}`,
9
+ accountNumber: process.env.CDK_DEFAULT_ACCOUNT || "",
10
+ region: process.env.CDK_DEFAULT_REGION || "us-east-1",
11
+ stackRuntime: Runtime.NODEJS_18_X,
12
+ },
13
+ API: {
14
+ Name: `${process.env.APP_NAME}-auth-api`,
15
+ Description: 'This is my new API',
16
+ DomainPrefix: 'my-custom-api'
17
+ },
18
+ RESOURCES: {
19
+ LAMBDA: [
20
+ {
21
+ name: `create-account`,
22
+ codePath: './lambda-functions/auth/createAccount.ts',
23
+ handler: 'main',
24
+ apiGateway: {
25
+ route: '/account/create-account',
26
+ method: 'post',
27
+ },
28
+
29
+ },
30
+ {
31
+ name: `change-password`,
32
+ codePath: './lambda-functions/auth/changePassword.ts',
33
+ handler: 'main',
34
+ apiGateway: {
35
+ route: '/account/change-password',
36
+ method: 'post',
37
+ version: 2
38
+ }
39
+ },
40
+ ],
41
+
42
+
43
+ DYNAMO: {
44
+ TABLES: [
45
+ {
46
+ tableName: `${CONSTANTS.DYNAMODB.TABLES.AUTH_HISTORY_TABLE.name}`,
47
+ primaryKey: {
48
+ name: 'id',
49
+ type: AttributeType.STRING,
50
+ },
51
+ billingMode: BillingMode.PAY_PER_REQUEST,
52
+ indexes: [
53
+ {
54
+ indexName: CONSTANTS.DYNAMODB.TABLES.AUTH_HISTORY_TABLE.indexes.AuthHistoryTS.name,
55
+ partitionKey: {
56
+ name: 'createdTS',
57
+ type: AttributeType.NUMBER
58
+ },
59
+ projectionType: ProjectionType.ALL
60
+ },
61
+ {
62
+ indexName: CONSTANTS.DYNAMODB.TABLES.AUTH_HISTORY_TABLE.indexes.Username.name,
63
+ partitionKey: {
64
+ name: 'username',
65
+ type: AttributeType.STRING
66
+ },
67
+ projectionType: ProjectionType.ALL
68
+ },
69
+ ]
70
+ },
71
+ ],
72
+ },
73
+
74
+ },
75
+ DNS: {
76
+ ZoneName: '',
77
+ ZoneId: '',
78
+ ZoneNameWithoutPeriod: 'not-used',
79
+ ZoneNameWithoutSuffix: 'not-used',
80
+ ZoneExist: true,
81
+ HostName: '',
82
+ FQDN: ''
83
+
84
+ }
85
+ };
@@ -0,0 +1,3 @@
1
+ export type TsgCdkConfigType<T> = {
2
+ [name: string]: T;
3
+ }
@@ -0,0 +1,6 @@
1
+ export interface TsgCognitoConfig {
2
+
3
+ USER_POOL_ID: string;
4
+ CLIENT_ID: string;
5
+ POOL_ARN: string;
6
+ }
@@ -0,0 +1,9 @@
1
+ export interface TsgDnsAppConfig {
2
+ ZoneName: string;
3
+ ZoneNameWithoutSuffix: string;
4
+ ZoneNameWithoutPeriod: string;
5
+ HostName: string;
6
+ FQDN: string;
7
+ ZoneExist: boolean;
8
+ ZoneId?: string;
9
+ }
@@ -0,0 +1,7 @@
1
+ import { TsgDynamoProp } from "./TsgDynamoProp";
2
+ import { TsgDynamoTableRef } from "./TsgDynamoTableRef";
3
+
4
+ export interface TsgDynamoDbProp {
5
+ TABLE_REFS?: TsgDynamoTableRef[];
6
+ TABLES?: TsgDynamoProp[];
7
+ }
@@ -0,0 +1,16 @@
1
+ import { AttributeType, ProjectionType } from "aws-cdk-lib/aws-dynamodb";
2
+
3
+ export interface TsgDynamoIndex {
4
+
5
+ indexName: string;
6
+ partitionKey: {
7
+ name: string;
8
+ type: AttributeType
9
+ },
10
+ sortKey?: {
11
+ name: string;
12
+ type: AttributeType
13
+ }
14
+ projectionType: ProjectionType;
15
+
16
+ }
@@ -0,0 +1,17 @@
1
+ import { AttributeType, BillingMode } from "aws-cdk-lib/aws-dynamodb";
2
+ import { TsgDynamoIndex } from "./TsgDynamoIndex";
3
+
4
+ export interface TsgDynamoProp {
5
+
6
+ tableName: string;
7
+ primaryKey: {
8
+ name: string;
9
+ type: AttributeType;
10
+ },
11
+ sortKey?: {
12
+ name: string;
13
+ type: AttributeType;
14
+ },
15
+ billingMode: BillingMode;
16
+ indexes: TsgDynamoIndex[],
17
+ }
@@ -0,0 +1,5 @@
1
+ import { TsgDynamoProp } from "./TsgDynamoProp";
2
+
3
+ export type TsgDynamoTable = {
4
+ [name: string]: TsgDynamoProp;
5
+ }
@@ -0,0 +1,4 @@
1
+ export type TsgDynamoTableRef = {
2
+ tableName: string;
3
+ region?: string;
4
+ }
@@ -0,0 +1,6 @@
1
+ import { TsgLambdaProp } from "./TsgLambdaProp";
2
+
3
+ export type TsgLambda = {
4
+ [name: string]: TsgLambdaProp;
5
+
6
+ }
@@ -0,0 +1,5 @@
1
+ export interface TsgLambdaLayerProp {
2
+ name: string;
3
+ codePath: string;
4
+ description: string;
5
+ }
@@ -0,0 +1,4 @@
1
+ import { NodejsFunction } from "aws-cdk-lib/aws-lambda-nodejs";
2
+ import { TsgLambdaNode } from "./TsgLambdaNode";
3
+
4
+ export type TsgLambdaMap = [NodejsFunction[], Map<string, TsgLambdaNode>]
@@ -0,0 +1,4 @@
1
+ // DO NOT FORGET TO UPDATE TsgLambdaNameHelper
2
+ // WITH NEW LAMBDA NAMES
3
+ export type TsgLambdaName = 'create-account' | 'verify-code' | 'change-password' | 'check-login' |
4
+ 'get-users' | 'resend-confirmation-code';
@@ -0,0 +1,4 @@
1
+ import { NodejsFunction, NodejsFunctionProps } from "aws-cdk-lib/aws-lambda-nodejs";
2
+ import { TsgLambdaProp } from "./TsgLambdaProp";
3
+
4
+ export type TsgLambdaNode = [TsgLambdaProp, NodejsFunction, NodejsFunctionProps];
@@ -0,0 +1,16 @@
1
+ import { Duration } from "aws-cdk-lib";
2
+ import { Runtime } from "aws-cdk-lib/aws-lambda";
3
+ import { TsgLambdaRoutable } from "./TsgLambdaRoutable";
4
+
5
+ export interface TsgLambdaProp {
6
+
7
+ name: string;
8
+ codePath: string;
9
+ handler: string;
10
+ duration?: Duration;
11
+ environment?: { [name: string]: string };
12
+ runtime?: Runtime;
13
+ memory?: number;
14
+ apiGateway?: TsgLambdaRoutable;
15
+ managedPolicies?: string[];
16
+ }