@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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { IUserPool } from "aws-cdk-lib/aws-cognito";
|
|
2
|
+
import { IRole } from "aws-cdk-lib/aws-iam";
|
|
3
|
+
import { LayerVersion } from "aws-cdk-lib/aws-lambda";
|
|
4
|
+
import { Construct } from "constructs";
|
|
5
|
+
import { MicroserviceProps } from "../../interfaces/MicroserviceProps";
|
|
6
|
+
import { TsgCognitoConfig } from "./TsgCognitoConfig";
|
|
7
|
+
import { AppConfig } from "../AppConfig";
|
|
8
|
+
|
|
9
|
+
export interface TsgLambdaProps {
|
|
10
|
+
|
|
11
|
+
scope: Construct;
|
|
12
|
+
prop: MicroserviceProps;
|
|
13
|
+
appConfig: AppConfig;
|
|
14
|
+
role?: IRole;
|
|
15
|
+
poolArn?: IUserPool;
|
|
16
|
+
layers?: LayerVersion[];
|
|
17
|
+
tsgCognito?: TsgCognitoConfig;
|
|
18
|
+
|
|
19
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./TsgLambdaProp";
|
|
2
|
+
export * from "./TsgCognitoConfig";
|
|
3
|
+
export * from "./TsgLambdaMap";
|
|
4
|
+
export * from "./TsgLambdaName";
|
|
5
|
+
export * from "./TsgLambdaNode";
|
|
6
|
+
export * from "./TsgDynamoProp";
|
|
7
|
+
export * from "./TsgDynamoTableRef";
|
|
8
|
+
export * from "./TsgDynamoDbProp";
|
|
9
|
+
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Table } from "aws-cdk-lib/aws-dynamodb";
|
|
2
|
+
import { Construct } from "constructs";
|
|
3
|
+
import { MicroserviceProps } from "../interfaces/MicroserviceProps";
|
|
4
|
+
import { CreateMicroServiceBundle } from "../resources/gateway/createMicroServiceBundle";
|
|
5
|
+
import { CreateDynamoDb } from "../resources/dynamodb/CreateDynamo";
|
|
6
|
+
import { Api } from "../resources/gateway/createApi";
|
|
7
|
+
import { getSecretManager } from "../resources/securityManager";
|
|
8
|
+
import { createCommonLayer } from "../resources/helpers/createCommonLayer";
|
|
9
|
+
import { AppConfig } from "../config/AppConfig";
|
|
10
|
+
import { Tags } from "aws-cdk-lib";
|
|
11
|
+
import { TsgLambdaProps } from "../config/types/TsgLambdaProps";
|
|
12
|
+
import { TsgLambdaProp } from "../config/types";
|
|
13
|
+
|
|
14
|
+
export class MicroService extends Construct {
|
|
15
|
+
|
|
16
|
+
protected readonly requireDynamoTables: boolean;
|
|
17
|
+
protected bundleByVersion: Record<string, CreateMicroServiceBundle> = {};
|
|
18
|
+
protected appConfig: AppConfig;
|
|
19
|
+
|
|
20
|
+
constructor(scope: Construct, id: string, props: MicroserviceProps) {
|
|
21
|
+
super(scope, id);
|
|
22
|
+
|
|
23
|
+
this.appConfig = new AppConfig(props);
|
|
24
|
+
|
|
25
|
+
this.requireDynamoTables = (props.RESOURCES.DYNAMO?.TABLES &&
|
|
26
|
+
props.RESOURCES.DYNAMO.TABLES.length > 0) ? true : false;
|
|
27
|
+
|
|
28
|
+
this.onInit(scope, this.appConfig);
|
|
29
|
+
|
|
30
|
+
this.createTag(scope)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
private onInit(scope: Construct, props: AppConfig) {
|
|
34
|
+
|
|
35
|
+
let tables: Table[] | undefined = undefined;
|
|
36
|
+
|
|
37
|
+
if (!process.env.SECRET_MANAGER_ARN) {
|
|
38
|
+
throw new Error(`You must provide the ARN for the your Configuration Secret
|
|
39
|
+
Manager`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const secretMgr = getSecretManager(scope, props, process.env.SECRET_MANAGER_ARN);
|
|
43
|
+
|
|
44
|
+
const commonLayer = createCommonLayer(scope, props);
|
|
45
|
+
|
|
46
|
+
const gateway = new Api(scope, this.appConfig).APIs;
|
|
47
|
+
|
|
48
|
+
const layers = [commonLayer];
|
|
49
|
+
|
|
50
|
+
// Creates DynamoDb Tables if required
|
|
51
|
+
if (this.requireDynamoTables) {
|
|
52
|
+
const dynamo = new CreateDynamoDb(scope, this.appConfig);
|
|
53
|
+
|
|
54
|
+
tables = dynamo.CreatedTables;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
props.RESOURCES.LAMBDA.forEach((bundleProps: TsgLambdaProp) => {
|
|
58
|
+
|
|
59
|
+
new CreateMicroServiceBundle(scope,
|
|
60
|
+
gateway[0], props, this.appConfig, tables, secretMgr, layers);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
protected createTag(scope: Construct) {
|
|
65
|
+
Tags.of(scope).add('App', this.appConfig.AppName);
|
|
66
|
+
Tags.of(scope).add('ResoucePrefix', this.appConfig.AppPrefix);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MicroService } from "./MicroService";
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IRole } from "aws-cdk-lib/aws-iam";
|
|
2
|
+
import { LayerVersion } from "aws-cdk-lib/aws-lambda";
|
|
3
|
+
import { TsgLambdaProp } from "../config/types";
|
|
4
|
+
import { TsgLambdaProps } from "../config/types/TsgLambdaProps";
|
|
5
|
+
|
|
6
|
+
export interface CreateLambdaFunctionInput {
|
|
7
|
+
prop: TsgLambdaProp;
|
|
8
|
+
role?: IRole;
|
|
9
|
+
layers?: LayerVersion[],
|
|
10
|
+
props?: TsgLambdaProps
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ApiAppConfig } from "../config/customConfigs/ApiAppConfig";
|
|
2
|
+
import { GlobalAppConfig } from "../config/customConfigs/GlobalAppConfig";
|
|
3
|
+
import { ResourceAppConfig } from "../config/customConfigs/ResourceAppConfig";
|
|
4
|
+
import { TsgDnsAppConfig } from "../config/types/TsgDnsConfig";
|
|
5
|
+
|
|
6
|
+
export interface MicroserviceProps {
|
|
7
|
+
API: ApiAppConfig;
|
|
8
|
+
GLOBALS: GlobalAppConfig;
|
|
9
|
+
RESOURCES: ResourceAppConfig;
|
|
10
|
+
DNS: TsgDnsAppConfig;
|
|
11
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Tags } from "aws-cdk-lib";
|
|
2
|
+
import { Construct } from "constructs";
|
|
3
|
+
import { AppConfig } from "../../config/AppConfig";
|
|
4
|
+
|
|
5
|
+
export abstract class BaseResource<T> {
|
|
6
|
+
|
|
7
|
+
protected createdResources: T[];
|
|
8
|
+
|
|
9
|
+
constructor(protected scope: Construct, protected config: AppConfig) { }
|
|
10
|
+
|
|
11
|
+
protected abstract createResource(scope: Construct): T[] | null;
|
|
12
|
+
|
|
13
|
+
protected abstract createOutput<T>(scope: Construct, createdAssets: T[]): void;
|
|
14
|
+
|
|
15
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RemovalPolicy } from "aws-cdk-lib";
|
|
2
|
+
import { Certificate, CertificateValidation, DnsValidatedCertificate, ICertificate } from "aws-cdk-lib/aws-certificatemanager";
|
|
3
|
+
import { IHostedZone } from "aws-cdk-lib/aws-route53";
|
|
4
|
+
import { Construct } from "constructs";
|
|
5
|
+
import { MicroserviceProps } from "../../interfaces/MicroserviceProps";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class CreateCertificate {
|
|
9
|
+
|
|
10
|
+
public certificate: ICertificate;
|
|
11
|
+
|
|
12
|
+
constructor(scope: Construct, props: MicroserviceProps, hostedZone: IHostedZone) {
|
|
13
|
+
|
|
14
|
+
this.certificate = this.generateCertificate(scope, props, hostedZone);
|
|
15
|
+
|
|
16
|
+
this.certificate.applyRemovalPolicy(RemovalPolicy.DESTROY);
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
generateCertificate(scope: Construct, props: MicroserviceProps, hostedZone: IHostedZone) {
|
|
21
|
+
|
|
22
|
+
// const cert = new DnsValidatedCertificate(scope, `${props.DNS.ZoneNameWithoutPeriod}-spa-app-certificate`, {
|
|
23
|
+
// domainName: `${props.API.DomainPrefix}.${props.DNS.ZoneName}`,
|
|
24
|
+
// hostedZone,
|
|
25
|
+
// region: props.GLOBALS.region || "us-east-1"
|
|
26
|
+
// });
|
|
27
|
+
|
|
28
|
+
const appType = "spa-app";
|
|
29
|
+
|
|
30
|
+
const cert = new Certificate(scope, `${props.DNS.ZoneNameWithoutPeriod}-${appType}-certificate`, {
|
|
31
|
+
domainName: `${props.API.DomainPrefix}.${props.DNS.ZoneName}`,
|
|
32
|
+
subjectAlternativeNames: [`${props.API.DomainPrefix}.${props.DNS.ZoneName}`],
|
|
33
|
+
validation: CertificateValidation.fromDnsMultiZone({
|
|
34
|
+
[`${props.API.DomainPrefix}.${props.DNS.ZoneName}`] : hostedZone ,
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return cert;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { IUserPool, UserPool, UserPoolClient, UserPoolClientProps, UserPoolIdentityProviderAmazon, UserPoolIdentityProviderAmazonProps, UserPoolIdentityProviderSaml, UserPoolIdentityProviderSamlMetadataType } from "aws-cdk-lib/aws-cognito";
|
|
2
|
+
import { Construct } from "constructs";
|
|
3
|
+
import { AppConfig } from "../../config/AppConfig";
|
|
4
|
+
import { createUserPoolProps } from "./createCognitoProps";
|
|
5
|
+
import { Duration } from "aws-cdk-lib";
|
|
6
|
+
import { ClientAppType } from "../../config/Environments";
|
|
7
|
+
|
|
8
|
+
export const createCognito = (scope: Construct, appConfig: AppConfig) => {
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
const userPool = createUserPool(scope, appConfig);
|
|
12
|
+
const clientPool = createUserPoolClient(scope, userPool, "mobile", appConfig);
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
userPool,
|
|
16
|
+
clientPool
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const createUserPool = (scope: Construct, appConfig: AppConfig, userPoolName?: string) => {
|
|
21
|
+
|
|
22
|
+
return new UserPool(scope, `${appConfig.AppName}-user-pool`,
|
|
23
|
+
createUserPoolProps(`${appConfig.AppName}-user-pool`));
|
|
24
|
+
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const createUserPoolClient = (scope: Construct, userPool: IUserPool, appType: ClientAppType,
|
|
28
|
+
appConfig: AppConfig) => {
|
|
29
|
+
|
|
30
|
+
const client = new UserPoolClient(scope, `${appConfig.AppName}-user-pool-client`,
|
|
31
|
+
createUserPoolClientProps(userPool, appConfig, appType));
|
|
32
|
+
|
|
33
|
+
return client;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const createUserPoolClientProps = (userpool: IUserPool, config: AppConfig, appType: ClientAppType): UserPoolClientProps => {
|
|
37
|
+
const props: UserPoolClientProps = {
|
|
38
|
+
userPool: userpool,
|
|
39
|
+
accessTokenValidity: Duration.hours(3),
|
|
40
|
+
refreshTokenValidity: Duration.days(3),
|
|
41
|
+
userPoolClientName: `${config.AppName}-${appType}`,
|
|
42
|
+
authFlows: {
|
|
43
|
+
userPassword: true,
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
return props;
|
|
47
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Duration, RemovalPolicy } from "aws-cdk-lib";
|
|
2
|
+
import { AccountRecovery, DateTimeAttribute, NumberAttribute, StringAttribute, UserPoolProps,
|
|
3
|
+
VerificationEmailStyle } from "aws-cdk-lib/aws-cognito";
|
|
4
|
+
|
|
5
|
+
export const createUserPoolProps = (securityUserPool: string) => {
|
|
6
|
+
|
|
7
|
+
const cognitoProps: UserPoolProps = {
|
|
8
|
+
userPoolName: securityUserPool.toLowerCase(),
|
|
9
|
+
selfSignUpEnabled: true,
|
|
10
|
+
userVerification: {
|
|
11
|
+
emailSubject: 'Verify your email for Bishop CDK Constructs!',
|
|
12
|
+
emailBody: 'Thanks for creating an account with Bishop CDK Constructs! Your verification code is {####}',
|
|
13
|
+
emailStyle: VerificationEmailStyle.CODE,
|
|
14
|
+
smsMessage: 'Thanks for signing up {username} with Bishop CDK Constructs! Your verification code is {####}',
|
|
15
|
+
},
|
|
16
|
+
userInvitation: {
|
|
17
|
+
emailSubject: 'Invite to join Bishop CDK Constructs!',
|
|
18
|
+
emailBody: 'Hello {username}, you have been invited to join Bishop CDK Constructs! Your temporary password is {####}',
|
|
19
|
+
smsMessage: 'Your temporary password for {username} with Bishop CDK Constructs is {####}'
|
|
20
|
+
},
|
|
21
|
+
signInAliases: {
|
|
22
|
+
username: true,
|
|
23
|
+
email: true,
|
|
24
|
+
phone: true
|
|
25
|
+
},
|
|
26
|
+
customAttributes: {
|
|
27
|
+
'firstName': new StringAttribute({ minLen: 3, maxLen: 30, mutable: true }),
|
|
28
|
+
'lastName': new StringAttribute({ minLen: 3, maxLen: 30, mutable: true }),
|
|
29
|
+
'phoneNumber': new StringAttribute({ minLen: 3, maxLen: 30, mutable: true }),
|
|
30
|
+
'acccountType': new NumberAttribute({ mutable: true }),
|
|
31
|
+
'joinedOn': new DateTimeAttribute(),
|
|
32
|
+
},
|
|
33
|
+
passwordPolicy: {
|
|
34
|
+
minLength: 8,
|
|
35
|
+
requireLowercase: true,
|
|
36
|
+
requireUppercase: true,
|
|
37
|
+
requireDigits: true,
|
|
38
|
+
requireSymbols: true,
|
|
39
|
+
tempPasswordValidity: Duration.days(1),
|
|
40
|
+
},
|
|
41
|
+
accountRecovery: AccountRecovery.PHONE_AND_EMAIL,
|
|
42
|
+
removalPolicy: RemovalPolicy.DESTROY,
|
|
43
|
+
}
|
|
44
|
+
return cognitoProps;
|
|
45
|
+
};
|
|
46
|
+
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { CfnOutput, RemovalPolicy } from "aws-cdk-lib";
|
|
2
|
+
import { GlobalSecondaryIndexProps,Table, TableProps } from "aws-cdk-lib/aws-dynamodb";
|
|
3
|
+
import { Construct } from "constructs";
|
|
4
|
+
import { AppConfig } from "../../config/AppConfig";
|
|
5
|
+
import { BaseResource } from "../base/baseResource";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export class CreateDynamoDb extends BaseResource<Table> {
|
|
9
|
+
|
|
10
|
+
static ReadWriteActions: string[] = [
|
|
11
|
+
"dynamodb:BatchGetItem",
|
|
12
|
+
"dynamodb:BatchWriteItem",
|
|
13
|
+
"dynamodb:ConditionCheckItem",
|
|
14
|
+
"dynamodb:DeleteItem",
|
|
15
|
+
"dynamodb:DescribeTable",
|
|
16
|
+
"dynamodb:GetItem",
|
|
17
|
+
"dynamodb:GetRecords",
|
|
18
|
+
"dynamodb:GetShardIterator",
|
|
19
|
+
"dynamodb:PutItem",
|
|
20
|
+
"dynamodb:Query",
|
|
21
|
+
"dynamodb:Scan",
|
|
22
|
+
"dynamodb:UpdateItem",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
get CreatedTables() {
|
|
26
|
+
return this.createdResources;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
constructor(protected scope: Construct, protected config: AppConfig) {
|
|
30
|
+
super(scope, config);
|
|
31
|
+
|
|
32
|
+
this.createdResources = this.createResource(scope);
|
|
33
|
+
|
|
34
|
+
if (this.createdResources) {
|
|
35
|
+
this.createOutput(scope, this.createdResources);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
protected createResource(scope: Construct): Table[] {
|
|
40
|
+
|
|
41
|
+
const props = this.createProps();
|
|
42
|
+
|
|
43
|
+
const tables = props?.map((prop: any, idx: number) => {
|
|
44
|
+
const dbTable = new Table(scope, `${prop.tableName}`, {
|
|
45
|
+
...prop,
|
|
46
|
+
removalPolicy: RemovalPolicy.DESTROY
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
this.config.RESOURCES.DYNAMO?.TABLES?.[idx].indexes.map((gsi) => {
|
|
50
|
+
|
|
51
|
+
const gsiProps: GlobalSecondaryIndexProps = {
|
|
52
|
+
indexName: this.generateDbName(gsi.indexName),
|
|
53
|
+
partitionKey: gsi.partitionKey,
|
|
54
|
+
sortKey: gsi.sortKey,
|
|
55
|
+
projectionType: gsi.projectionType
|
|
56
|
+
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
dbTable.addGlobalSecondaryIndex(gsiProps);
|
|
60
|
+
});
|
|
61
|
+
return dbTable;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return tables ?? [];
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
protected createOutput<T>(scope: Construct, createdAssets: T[]): void {
|
|
72
|
+
this.createdResources!.forEach((x, idx) => {
|
|
73
|
+
new CfnOutput(scope, `dynamoTable${idx}`, {
|
|
74
|
+
value: x.tableName
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private createProps() {
|
|
80
|
+
const props = this.config.RESOURCES?.DYNAMO?.TABLES?.map((x) => {
|
|
81
|
+
|
|
82
|
+
const prop: any = {};
|
|
83
|
+
|
|
84
|
+
prop.tableName = this.generateDbName(x.tableName);
|
|
85
|
+
|
|
86
|
+
prop.partitionKey = {
|
|
87
|
+
name: x.primaryKey.name,
|
|
88
|
+
type: x.primaryKey.type
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
prop.billingMode = x.billingMode;
|
|
92
|
+
|
|
93
|
+
if (x.sortKey) {
|
|
94
|
+
prop.sortKey = {
|
|
95
|
+
name: x.sortKey.name,
|
|
96
|
+
type: x.sortKey.type,
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return prop as TableProps;
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
return props;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private generateDbName(tableName: string) {
|
|
106
|
+
// TODO: Remove this later table names should have appPrefix
|
|
107
|
+
return `${tableName}`;
|
|
108
|
+
|
|
109
|
+
// return `${this.config.AppPrefix}-${tableName}`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { CfnOutput, Tag } from "aws-cdk-lib";
|
|
2
|
+
import { BasePathMapping, Cors, CorsOptions, DomainName, EndpointType, IDomainName, IRestApi, MethodOptions, RestApi, RestApiProps, SecurityPolicy } from "aws-cdk-lib/aws-apigateway";
|
|
3
|
+
import { ARecord, HostedZone, IHostedZone, RecordTarget } from "aws-cdk-lib/aws-route53";
|
|
4
|
+
import { ApiGateway, ApiGatewayDomain } from "aws-cdk-lib/aws-route53-targets";
|
|
5
|
+
import { Construct } from "constructs";
|
|
6
|
+
import { AppConfig } from "../../config/AppConfig";
|
|
7
|
+
import { MicroserviceProps } from "../../interfaces/MicroserviceProps";
|
|
8
|
+
|
|
9
|
+
import { BaseResource } from "../base/baseResource";
|
|
10
|
+
import { CreateCertificate } from "../certificate/createCertificate";
|
|
11
|
+
|
|
12
|
+
export class Api extends BaseResource<IRestApi> {
|
|
13
|
+
|
|
14
|
+
private corsOptions: CorsOptions;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
get APIs() {
|
|
18
|
+
return this.createdResources;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(scope: Construct, config: AppConfig) {
|
|
22
|
+
super(scope, config);
|
|
23
|
+
|
|
24
|
+
this.corsOptions = this.createDefaultCorsOptions();
|
|
25
|
+
|
|
26
|
+
this.createdResources = this.createResource(scope);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private createApi(scope: Construct) {
|
|
30
|
+
const zone = this.getZone(this.scope, this.config);
|
|
31
|
+
|
|
32
|
+
const api = new RestApi(this.scope, `${this.config.AppPrefix}-rest-api`, this.createApiProps(zone));
|
|
33
|
+
|
|
34
|
+
this.createARecord(scope, zone, api);
|
|
35
|
+
|
|
36
|
+
return api;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private createApiProps(zone: IHostedZone): RestApiProps {
|
|
40
|
+
|
|
41
|
+
const cert = this.createCertificate(this.scope, zone, this.config);
|
|
42
|
+
|
|
43
|
+
const props: RestApiProps = {
|
|
44
|
+
restApiName: `gs-api-${this.config.AppPrefix}-${this.config.API.Name}`,
|
|
45
|
+
description: this.config.API.Description,
|
|
46
|
+
domainName: {
|
|
47
|
+
domainName: `${this.config.API.DomainPrefix}.${this.config.DNS.ZoneName}`,
|
|
48
|
+
certificate: cert.certificate,
|
|
49
|
+
endpointType: EndpointType.EDGE,
|
|
50
|
+
securityPolicy: SecurityPolicy.TLS_1_2
|
|
51
|
+
},
|
|
52
|
+
// TODO: ADD CUSTOM DOMAIN HERE
|
|
53
|
+
// defaultDomainMapping: {
|
|
54
|
+
// domainName: domain,
|
|
55
|
+
// },
|
|
56
|
+
// domainName: '',
|
|
57
|
+
defaultCorsPreflightOptions: this.corsOptions
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
return props;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private createDefaultCorsOptions() {
|
|
64
|
+
|
|
65
|
+
const corsOptions: CorsOptions = {
|
|
66
|
+
allowHeaders: [
|
|
67
|
+
'*',
|
|
68
|
+
],
|
|
69
|
+
allowMethods: Cors.ALL_METHODS,
|
|
70
|
+
allowCredentials: true,
|
|
71
|
+
allowOrigins: Cors.ALL_ORIGINS,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
return corsOptions;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private createCustomDomain(scope: Construct, config: MicroserviceProps) {
|
|
78
|
+
const domainName = DomainName.fromDomainNameAttributes(scope, `${config.API.Name}-custom-domain`, {
|
|
79
|
+
domainName: config.DNS.ZoneName,
|
|
80
|
+
domainNameAliasHostedZoneId: config.DNS.ZoneId!,
|
|
81
|
+
domainNameAliasTarget: config.API.DomainPrefix!,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return domainName
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private attachDomainToApi(scope: Construct, api: IRestApi, domain: IDomainName, config: MicroserviceProps) {
|
|
88
|
+
return new BasePathMapping(scope, `${config.API.Name}-basePathMapping`, {
|
|
89
|
+
domainName: domain,
|
|
90
|
+
restApi: api,
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private getZone(scope: Construct, config: MicroserviceProps) {
|
|
95
|
+
return HostedZone.fromHostedZoneAttributes(scope, `${config.DNS.ZoneName}-zone`, {
|
|
96
|
+
zoneName: config.DNS.ZoneName,
|
|
97
|
+
hostedZoneId: config.DNS.ZoneId!
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private createCertificate(scope: Construct, zone: IHostedZone, config: MicroserviceProps) {
|
|
102
|
+
const cert = new CreateCertificate(scope, config, zone);
|
|
103
|
+
return cert;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private createARecord(scope: Construct, zone: IHostedZone, api: RestApi) {
|
|
107
|
+
return new ARecord(scope, "ApiRecord", {
|
|
108
|
+
zone,
|
|
109
|
+
target: RecordTarget.fromAlias(new ApiGateway(api)),
|
|
110
|
+
recordName: this.config.API.DomainPrefix
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
protected createResource(scope: Construct) {
|
|
116
|
+
|
|
117
|
+
const api = this.createApi(scope);
|
|
118
|
+
// TODO: ONLY IF CUSTOM MAPPING IS REQUIRED
|
|
119
|
+
// const domain = this.createCustomDomain(scope, this.config);
|
|
120
|
+
|
|
121
|
+
// const mapping = this.attachDomainToApi(scope, api, domain, this.config);
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
return [api];
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
protected createOutput<T>(scope: Construct, createdAssets: T[]): void {
|
|
129
|
+
createdAssets.forEach((api, idx) => {
|
|
130
|
+
|
|
131
|
+
new CfnOutput(scope, `api${idx}`, {
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
value: api.url
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
}
|