@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
package/readme.md
CHANGED
|
@@ -1,148 +1,148 @@
|
|
|
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
|
-
|
|
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
|
+
|
|
148
148
|
Release Version : `1.0.28`
|
package/src/config/AppConfig.ts
CHANGED
|
@@ -1,107 +1,107 @@
|
|
|
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
|
-
if (config.DNS) {
|
|
65
|
-
this.DNS = {
|
|
66
|
-
...config.DNS!
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (config.RESOURCES.AUTHORIZER) {
|
|
71
|
-
this.RESOURCES.AUTHORIZER = {
|
|
72
|
-
...config.RESOURCES.AUTHORIZER
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (config.RESOURCES.EC2) {
|
|
77
|
-
this.RESOURCES.EC2 = {
|
|
78
|
-
...config.RESOURCES.EC2
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
// this.lambdaConfigs = this.expandProps<TsgLambdaName, TsgLambdaProp>(this.RESOURCES.LAMBDA!);
|
|
84
|
-
// this.dynamoConfigs = this.expandProps<TsgTableName, TsgDynamoProp>(this.RESOURCES.DYNAMO?.TABLES!);
|
|
85
|
-
// }
|
|
86
|
-
|
|
87
|
-
private populateConfigs<T, R>(result: R[], record?: Record<string, R>) {
|
|
88
|
-
|
|
89
|
-
if (!record) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
result = this.expandProps<T, R>(record);
|
|
94
|
-
return result;
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private expandProps<T, R>(data: Record<string, R>) {
|
|
99
|
-
|
|
100
|
-
const result = [];
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
for (const [key, value] of Object.entries(data)) {
|
|
103
|
-
result.push(value);
|
|
104
|
-
}
|
|
105
|
-
return result as R[];
|
|
106
|
-
}
|
|
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
|
+
if (config.DNS) {
|
|
65
|
+
this.DNS = {
|
|
66
|
+
...config.DNS!
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (config.RESOURCES.AUTHORIZER) {
|
|
71
|
+
this.RESOURCES.AUTHORIZER = {
|
|
72
|
+
...config.RESOURCES.AUTHORIZER
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (config.RESOURCES.EC2) {
|
|
77
|
+
this.RESOURCES.EC2 = {
|
|
78
|
+
...config.RESOURCES.EC2
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
// this.lambdaConfigs = this.expandProps<TsgLambdaName, TsgLambdaProp>(this.RESOURCES.LAMBDA!);
|
|
84
|
+
// this.dynamoConfigs = this.expandProps<TsgTableName, TsgDynamoProp>(this.RESOURCES.DYNAMO?.TABLES!);
|
|
85
|
+
// }
|
|
86
|
+
|
|
87
|
+
private populateConfigs<T, R>(result: R[], record?: Record<string, R>) {
|
|
88
|
+
|
|
89
|
+
if (!record) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
result = this.expandProps<T, R>(record);
|
|
94
|
+
return result;
|
|
95
|
+
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private expandProps<T, R>(data: Record<string, R>) {
|
|
99
|
+
|
|
100
|
+
const result = [];
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
for (const [key, value] of Object.entries(data)) {
|
|
103
|
+
result.push(value);
|
|
104
|
+
}
|
|
105
|
+
return result as R[];
|
|
106
|
+
}
|
|
107
107
|
}
|
package/src/config/Constants.ts
CHANGED
|
@@ -1,27 +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
|
-
}
|
|
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
27
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type Environment = "dev" | "qa" | "prod";
|
|
1
|
+
export type Environment = "dev" | "qa" | "prod";
|
|
2
2
|
export type ClientAppType = "mobile" | "web";
|
|
@@ -1,9 +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
|
-
}
|
|
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
9
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { IRestApi } from "aws-cdk-lib/aws-apigateway";
|
|
2
|
-
import { Construct } from "constructs";
|
|
3
|
-
import { MicroserviceProps } from "../interfaces/MicroserviceProps";
|
|
4
|
-
import { AppConfig } from "./AppConfig";
|
|
5
|
-
import { Table } from "aws-cdk-lib/aws-dynamodb";
|
|
6
|
-
import { ISecret } from "aws-cdk-lib/aws-secretsmanager";
|
|
7
|
-
import { LayerVersion } from "aws-cdk-lib/aws-lambda";
|
|
8
|
-
|
|
9
|
-
export interface ServiceBundleConfig {
|
|
10
|
-
scope: Construct,
|
|
11
|
-
readonly gatewayApi: IRestApi,
|
|
12
|
-
readonly props: MicroserviceProps,
|
|
13
|
-
readonly appConfig: AppConfig,
|
|
14
|
-
readonly tables?: Table[],
|
|
15
|
-
readonly secretMgr?: ISecret,
|
|
16
|
-
readonly layers?: LayerVersion[]
|
|
17
|
-
|
|
1
|
+
import { IRestApi } from "aws-cdk-lib/aws-apigateway";
|
|
2
|
+
import { Construct } from "constructs";
|
|
3
|
+
import { MicroserviceProps } from "../interfaces/MicroserviceProps";
|
|
4
|
+
import { AppConfig } from "./AppConfig";
|
|
5
|
+
import { Table } from "aws-cdk-lib/aws-dynamodb";
|
|
6
|
+
import { ISecret } from "aws-cdk-lib/aws-secretsmanager";
|
|
7
|
+
import { LayerVersion } from "aws-cdk-lib/aws-lambda";
|
|
8
|
+
|
|
9
|
+
export interface ServiceBundleConfig {
|
|
10
|
+
scope: Construct,
|
|
11
|
+
readonly gatewayApi: IRestApi,
|
|
12
|
+
readonly props: MicroserviceProps,
|
|
13
|
+
readonly appConfig: AppConfig,
|
|
14
|
+
readonly tables?: Table[],
|
|
15
|
+
readonly secretMgr?: ISecret,
|
|
16
|
+
readonly layers?: LayerVersion[]
|
|
17
|
+
|
|
18
18
|
}
|