@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.
- package/.github/workflows/publish.yml +36 -0
- package/dist/config/AppConfig.d.ts +24 -0
- package/dist/config/AppConfig.js +62 -0
- package/dist/config/Constants.d.ts +26 -0
- package/dist/config/Constants.js +30 -0
- package/dist/config/Environments.d.ts +2 -0
- package/dist/config/Environments.js +3 -0
- package/dist/config/MicroserviceAppConfig.d.ts +5 -0
- package/dist/config/MicroserviceAppConfig.js +11 -0
- package/dist/config/bishopConfig.d.ts +2 -0
- package/dist/config/bishopConfig.js +81 -0
- package/dist/config/customConfigs/ApiAppConfig.d.ts +5 -0
- package/dist/config/customConfigs/ApiAppConfig.js +4 -0
- package/dist/config/customConfigs/GlobalAppConfig.d.ts +8 -0
- package/dist/config/customConfigs/GlobalAppConfig.js +3 -0
- package/dist/config/customConfigs/IAppConfig.d.ts +10 -0
- package/dist/config/customConfigs/IAppConfig.js +3 -0
- package/dist/config/customConfigs/ResourceAppConfig.d.ts +8 -0
- package/dist/config/customConfigs/ResourceAppConfig.js +3 -0
- package/dist/config/microServiceConfig.d.ts +2 -0
- package/dist/config/microServiceConfig.js +82 -0
- package/dist/config/types/TsgCdkConfigType.d.ts +3 -0
- package/dist/config/types/TsgCdkConfigType.js +3 -0
- package/dist/config/types/TsgCognitoConfig.d.ts +5 -0
- package/dist/config/types/TsgCognitoConfig.js +3 -0
- package/dist/config/types/TsgDnsConfig.d.ts +9 -0
- package/dist/config/types/TsgDnsConfig.js +3 -0
- package/dist/config/types/TsgDynamoDbProp.d.ts +6 -0
- package/dist/config/types/TsgDynamoDbProp.js +3 -0
- package/dist/config/types/TsgDynamoIndex.d.ts +13 -0
- package/dist/config/types/TsgDynamoIndex.js +3 -0
- package/dist/config/types/TsgDynamoProp.d.ts +15 -0
- package/dist/config/types/TsgDynamoProp.js +3 -0
- package/dist/config/types/TsgDynamoTable.d.ts +4 -0
- package/dist/config/types/TsgDynamoTable.js +3 -0
- package/dist/config/types/TsgDynamoTableRef.d.ts +4 -0
- package/dist/config/types/TsgDynamoTableRef.js +3 -0
- package/dist/config/types/TsgLambda.d.ts +4 -0
- package/dist/config/types/TsgLambda.js +3 -0
- package/dist/config/types/TsgLambdaLayerProp.d.ts +5 -0
- package/dist/config/types/TsgLambdaLayerProp.js +3 -0
- package/dist/config/types/TsgLambdaMap.d.ts +3 -0
- package/dist/config/types/TsgLambdaMap.js +3 -0
- package/dist/config/types/TsgLambdaName.d.ts +1 -0
- package/dist/config/types/TsgLambdaName.js +3 -0
- package/dist/config/types/TsgLambdaNode.d.ts +3 -0
- package/dist/config/types/TsgLambdaNode.js +3 -0
- package/dist/config/types/TsgLambdaProp.d.ts +16 -0
- package/dist/config/types/TsgLambdaProp.js +3 -0
- package/dist/config/types/TsgLambdaProps.d.ts +16 -0
- package/dist/config/types/TsgLambdaProps.js +3 -0
- package/dist/config/types/TsgLambdaRoutable.d.ts +6 -0
- package/dist/config/types/TsgLambdaRoutable.js +3 -0
- package/dist/config/types/index.d.ts +8 -0
- package/dist/config/types/index.js +25 -0
- package/dist/constructs/MicroService.d.ts +12 -0
- package/dist/constructs/MicroService.js +47 -0
- package/dist/constructs/index.d.ts +1 -0
- package/dist/constructs/index.js +6 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -0
- package/dist/interfaces/CreateLambdaFunctionInput.d.ts +10 -0
- package/dist/interfaces/CreateLambdaFunctionInput.js +3 -0
- package/dist/interfaces/MicroserviceProps.d.ts +10 -0
- package/dist/interfaces/MicroserviceProps.js +3 -0
- package/dist/resources/base/baseResource.d.ts +10 -0
- package/dist/resources/base/baseResource.js +11 -0
- package/dist/resources/certificate/createCertificate.d.ts +9 -0
- package/dist/resources/certificate/createCertificate.js +29 -0
- package/dist/resources/cognito/createCognito.d.ts +7 -0
- package/dist/resources/cognito/createCognito.js +35 -0
- package/dist/resources/cognito/createCognitoProps.d.ts +2 -0
- package/dist/resources/cognito/createCognitoProps.js +47 -0
- package/dist/resources/dynamodb/CreateDynamo.d.ts +15 -0
- package/dist/resources/dynamodb/CreateDynamo.js +87 -0
- package/dist/resources/gateway/createApi.d.ts +19 -0
- package/dist/resources/gateway/createApi.js +104 -0
- package/dist/resources/gateway/createMicroServiceBundle.d.ts +25 -0
- package/dist/resources/gateway/createMicroServiceBundle.js +126 -0
- package/dist/resources/helpers/createAuthorizer.d.ts +15 -0
- package/dist/resources/helpers/createAuthorizer.js +80 -0
- package/dist/resources/helpers/createCommonLayer.d.ts +3 -0
- package/dist/resources/helpers/createCommonLayer.js +15 -0
- package/dist/resources/helpers/createRoutes.d.ts +8 -0
- package/dist/resources/helpers/createRoutes.js +30 -0
- package/dist/resources/lambda/createLambda.d.ts +20 -0
- package/dist/resources/lambda/createLambda.js +135 -0
- package/dist/resources/lambda-layer/createLambdaLayer.d.ts +5 -0
- package/dist/resources/lambda-layer/createLambdaLayer.js +31 -0
- package/dist/resources/layers/common/src/nodejs/api-response/index.d.ts +1 -0
- package/dist/resources/layers/common/src/nodejs/api-response/index.js +18 -0
- package/dist/resources/layers/common/src/nodejs/api-response/responses.d.ts +24 -0
- package/dist/resources/layers/common/src/nodejs/api-response/responses.js +43 -0
- package/dist/resources/layers/common/src/nodejs/index.d.ts +2 -0
- package/dist/resources/layers/common/src/nodejs/index.js +19 -0
- package/dist/resources/layers/common/src/nodejs/logger/IContext.d.ts +5 -0
- package/dist/resources/layers/common/src/nodejs/logger/IContext.js +3 -0
- package/dist/resources/layers/common/src/nodejs/logger/index.d.ts +2 -0
- package/dist/resources/layers/common/src/nodejs/logger/index.js +19 -0
- package/dist/resources/layers/common/src/nodejs/logger/logger.d.ts +2 -0
- package/dist/resources/layers/common/src/nodejs/logger/logger.js +12 -0
- package/dist/resources/resources/iam/policyDocuments/cognitoPolicy.d.ts +4 -0
- package/dist/resources/resources/iam/policyDocuments/cognitoPolicy.js +52 -0
- package/dist/resources/resources/iam/roles/createRole.d.ts +4 -0
- package/dist/resources/resources/iam/roles/createRole.js +22 -0
- package/dist/resources/route53/CreateZone.d.ts +0 -0
- package/dist/resources/route53/CreateZone.js +47 -0
- package/dist/resources/route53/create-zones.d.ts +0 -0
- package/dist/resources/route53/create-zones.js +30 -0
- package/dist/resources/securityManager/index.d.ts +4 -0
- package/dist/resources/securityManager/index.js +18 -0
- package/docs/lambda-config.md +1 -0
- package/package.json +48 -0
- package/readme.md +147 -0
- package/src/config/AppConfig.ts +93 -0
- package/src/config/Constants.ts +27 -0
- package/src/config/Environments.ts +2 -0
- package/src/config/MicroserviceAppConfig.ts +9 -0
- package/src/config/bishopConfig.ts +83 -0
- package/src/config/customConfigs/ApiAppConfig.ts +6 -0
- package/src/config/customConfigs/GlobalAppConfig.ts +11 -0
- package/src/config/customConfigs/IAppConfig.ts +13 -0
- package/src/config/customConfigs/ResourceAppConfig.ts +12 -0
- package/src/config/microServiceConfig.ts +85 -0
- package/src/config/types/TsgCdkConfigType.ts +3 -0
- package/src/config/types/TsgCognitoConfig.ts +6 -0
- package/src/config/types/TsgDnsConfig.ts +9 -0
- package/src/config/types/TsgDynamoDbProp.ts +7 -0
- package/src/config/types/TsgDynamoIndex.ts +16 -0
- package/src/config/types/TsgDynamoProp.ts +17 -0
- package/src/config/types/TsgDynamoTable.ts +5 -0
- package/src/config/types/TsgDynamoTableRef.ts +4 -0
- package/src/config/types/TsgLambda.ts +6 -0
- package/src/config/types/TsgLambdaLayerProp.ts +5 -0
- package/src/config/types/TsgLambdaMap.ts +4 -0
- package/src/config/types/TsgLambdaName.ts +4 -0
- package/src/config/types/TsgLambdaNode.ts +4 -0
- package/src/config/types/TsgLambdaProp.ts +16 -0
- package/src/config/types/TsgLambdaProps.ts +19 -0
- package/src/config/types/TsgLambdaRoutable.ts +6 -0
- package/src/config/types/index.ts +9 -0
- package/src/constructs/MicroService.ts +68 -0
- package/src/constructs/index.ts +1 -0
- package/src/index.ts +4 -0
- package/src/interfaces/CreateLambdaFunctionInput.ts +11 -0
- package/src/interfaces/MicroserviceProps.ts +11 -0
- package/src/resources/.gitkeep +0 -0
- package/src/resources/base/baseResource.ts +15 -0
- package/src/resources/certificate/createCertificate.ts +40 -0
- package/src/resources/cicd/.gitkeep +0 -0
- package/src/resources/cognito/.gitkeep +0 -0
- package/src/resources/cognito/createCognito.ts +47 -0
- package/src/resources/cognito/createCognitoProps.ts +46 -0
- package/src/resources/dynamodb/CreateDynamo.ts +111 -0
- package/src/resources/gateway/createApi.ts +138 -0
- package/src/resources/gateway/createMicroServiceBundle.ts +183 -0
- package/src/resources/helpers/createAuthorizer.ts +106 -0
- package/src/resources/helpers/createCommonLayer.ts +18 -0
- package/src/resources/helpers/createRoutes.ts +43 -0
- package/src/resources/lambda/createLambda.ts +184 -0
- package/src/resources/lambda-layer/createLambdaLayer.ts +40 -0
- package/src/resources/layers/common/package.json +22 -0
- package/src/resources/layers/common/src/nodejs/api-response/index.ts +1 -0
- package/src/resources/layers/common/src/nodejs/api-response/responses.ts +41 -0
- package/src/resources/layers/common/src/nodejs/index.ts +3 -0
- package/src/resources/layers/common/src/nodejs/logger/IContext.ts +7 -0
- package/src/resources/layers/common/src/nodejs/logger/index.ts +2 -0
- package/src/resources/layers/common/src/nodejs/logger/logger.ts +11 -0
- package/src/resources/layers/common/tsconfig.json +7 -0
- package/src/resources/resources/iam/policyDocuments/cognitoPolicy.ts +55 -0
- package/src/resources/resources/iam/roles/createRole.ts +30 -0
- package/src/resources/route53/CreateZone.ts +62 -0
- package/src/resources/route53/create-zones.ts +41 -0
- package/src/resources/securityManager/index.ts +24 -0
- 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
|
+
[](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,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,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,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,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
|
+
}
|