@sylvesterllc/aws-constructs 1.1.11 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +58 -38
- package/__tests__/app-config.test.ts +32 -32
- package/__tests__/data/testConfig.ts +146 -146
- package/__tests__/mocks/ResourceMock.ts +9 -9
- package/__tests__/router.test.ts +194 -194
- package/dist/config/AppConfig.js +1 -1
- package/dist/config/Constants.js +1 -1
- package/dist/config/Environments.js +1 -1
- package/dist/config/MicroserviceAppConfig.js +1 -1
- package/dist/config/ServiceBundleConfig.js +1 -1
- package/dist/config/bishopConfig.js +1 -1
- package/dist/config/customConfigs/ApiAppConfig.js +1 -1
- package/dist/config/customConfigs/GlobalAppConfig.js +1 -1
- package/dist/config/customConfigs/IAppConfig.js +1 -1
- package/dist/config/customConfigs/ResourceAppConfig.js +1 -1
- package/dist/config/microServiceConfig.js +1 -1
- package/dist/config/types/LogDuration.js +1 -1
- package/dist/config/types/TsgAuthorizerProp.js +1 -1
- package/dist/config/types/TsgAuthorizerType.js +1 -1
- package/dist/config/types/TsgCdkConfigType.js +1 -1
- package/dist/config/types/TsgCognitoConfig.js +1 -1
- package/dist/config/types/TsgDnsConfig.js +1 -1
- package/dist/config/types/TsgDynamoDbProp.js +1 -1
- package/dist/config/types/TsgDynamoIndex.js +1 -1
- package/dist/config/types/TsgDynamoProp.js +1 -1
- package/dist/config/types/TsgDynamoTable.js +1 -1
- package/dist/config/types/TsgDynamoTableRef.js +1 -1
- package/dist/config/types/TsgEc2Prop.js +1 -1
- package/dist/config/types/TsgKeyPair.js +1 -1
- package/dist/config/types/TsgLambda.js +1 -1
- package/dist/config/types/TsgLambdaLayerProp.js +1 -1
- package/dist/config/types/TsgLambdaMap.js +1 -1
- package/dist/config/types/TsgLambdaName.js +1 -1
- package/dist/config/types/TsgLambdaNode.js +1 -1
- package/dist/config/types/TsgLambdaProp.js +1 -1
- package/dist/config/types/TsgLambdaProps.js +1 -1
- package/dist/config/types/TsgLambdaRoutable.js +1 -1
- package/dist/config/types/index.js +1 -1
- package/dist/constants/aws-service-principal-constants.d.ts +3 -0
- package/dist/constants/aws-service-principal-constants.js +7 -0
- package/dist/constructs/DynamoDbSingleTable.js +1 -1
- package/dist/constructs/MicroService.js +1 -1
- package/dist/constructs/index.d.ts +1 -0
- package/dist/constructs/index.js +4 -2
- package/dist/constructs/timer-job.d.ts +6 -0
- package/dist/constructs/timer-job.js +15 -0
- package/dist/helpers/logger.js +1 -1
- package/dist/helpers/util-helper.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +18 -4
- package/dist/interfaces/ApiLambdaResult.js +1 -1
- package/dist/interfaces/BaseResourceProps.js +1 -1
- package/dist/interfaces/CreateLambdaFunctionInput.js +1 -1
- package/dist/interfaces/MicroserviceProps.js +1 -1
- package/dist/interfaces/timer-job/index.d.ts +1 -0
- package/dist/interfaces/timer-job/index.js +18 -0
- package/dist/interfaces/timer-job/timer-job-props.d.ts +14 -0
- package/dist/interfaces/timer-job/timer-job-props.js +3 -0
- package/dist/resources/base/baseResource.js +1 -1
- package/dist/resources/base/tsgBaseResource.js +1 -1
- package/dist/resources/certificate/createCertificate.js +1 -1
- package/dist/resources/cognito/createCognito.js +1 -1
- package/dist/resources/cognito/createCognitoProps.js +1 -1
- package/dist/resources/customResource/createSeedDatabaseCustomResource.js +1 -1
- package/dist/resources/dynamodb/CreateDynamo.js +1 -1
- package/dist/resources/dynamodb/CreateDynamoSingleTableDesign.js +1 -1
- package/dist/resources/ec2/create-ec2-instance.js +3 -3
- package/dist/resources/ecr/CreateEcr.js +2 -2
- package/dist/resources/gateway/CreateApiAndAttachLambdas.js +1 -1
- package/dist/resources/gateway/createApi.js +1 -1
- package/dist/resources/gateway/createApiKey.js +1 -1
- package/dist/resources/helpers/createCommonLayer.js +1 -1
- package/dist/resources/helpers/createRoutes.js +1 -1
- package/dist/resources/index.js +1 -1
- package/dist/resources/lambda/create-basic-lambda.d.ts +3 -0
- package/dist/resources/lambda/create-basic-lambda.js +77 -0
- package/dist/resources/lambda/createLambda.js +1 -1
- package/dist/resources/lambda/lambdaHelper.js +1 -1
- package/dist/resources/lambda-authorizer/TsgJwtTokenAuthorizer.js +1 -1
- package/dist/resources/lambda-authorizer/TsgRequestAuthorizer.js +1 -1
- package/dist/resources/lambda-authorizer/createAuthorizerHelpers.js +1 -1
- package/dist/resources/lambda-layer/createLambdaLayer.js +1 -1
- package/dist/resources/layers/common/src/nodejs/api-response/responses.js +1 -1
- package/dist/resources/layers/common/src/nodejs/index.js +1 -1
- package/dist/resources/layers/common/src/nodejs/logger/IContext.js +1 -1
- package/dist/resources/layers/common/src/nodejs/logger/index.js +1 -1
- package/dist/resources/layers/common/src/nodejs/logger/logger.js +1 -1
- package/dist/resources/resources/iam/policyDocuments/cognitoPolicy.js +1 -1
- package/dist/resources/resources/iam/roles/createRole.js +1 -1
- package/dist/resources/route53/CreateZone.js +1 -1
- package/dist/resources/route53/create-zones.js +1 -1
- package/dist/resources/securityManager/index.js +1 -1
- package/jest.config.js +8 -8
- package/jest.config.ts.old +20 -20
- package/package.json +55 -56
- package/readme.md +147 -147
- package/src/config/AppConfig.ts +106 -106
- package/src/config/Constants.ts +26 -26
- package/src/config/Environments.ts +1 -1
- package/src/config/MicroserviceAppConfig.ts +8 -8
- package/src/config/ServiceBundleConfig.ts +17 -17
- package/src/config/bishopConfig.ts +82 -82
- package/src/config/customConfigs/ApiAppConfig.ts +5 -5
- package/src/config/customConfigs/GlobalAppConfig.ts +10 -10
- package/src/config/customConfigs/IAppConfig.ts +12 -12
- package/src/config/customConfigs/ResourceAppConfig.ts +15 -15
- package/src/config/microServiceConfig.ts +83 -83
- package/src/config/types/LogDuration.ts +7 -7
- package/src/config/types/TsgAuthorizerProp.ts +8 -8
- package/src/config/types/TsgAuthorizerType.ts +4 -4
- package/src/config/types/TsgCdkConfigType.ts +2 -2
- package/src/config/types/TsgCognitoConfig.ts +5 -5
- package/src/config/types/TsgDnsConfig.ts +10 -10
- package/src/config/types/TsgDynamoDbProp.ts +9 -9
- package/src/config/types/TsgDynamoIndex.ts +15 -15
- package/src/config/types/TsgDynamoProp.ts +16 -16
- package/src/config/types/TsgDynamoTable.ts +4 -4
- package/src/config/types/TsgDynamoTableRef.ts +3 -3
- package/src/config/types/TsgEc2Prop.ts +8 -8
- package/src/config/types/TsgKeyPair.ts +5 -5
- package/src/config/types/TsgLambda.ts +5 -5
- package/src/config/types/TsgLambdaLayerProp.ts +4 -4
- package/src/config/types/TsgLambdaMap.ts +3 -3
- package/src/config/types/TsgLambdaName.ts +3 -3
- package/src/config/types/TsgLambdaNode.ts +3 -3
- package/src/config/types/TsgLambdaProp.ts +19 -19
- package/src/config/types/TsgLambdaProps.ts +17 -17
- package/src/config/types/TsgLambdaRoutable.ts +8 -8
- package/src/config/types/index.ts +11 -11
- package/src/constants/aws-service-principal-constants.ts +3 -0
- package/src/constructs/DynamoDbSingleTable.ts +12 -12
- package/src/constructs/MicroService.ts +131 -132
- package/src/constructs/index.ts +4 -3
- package/src/constructs/timer-job.ts +17 -0
- package/src/helpers/logger.ts +12 -12
- package/src/helpers/util-helper.ts +19 -19
- package/src/index.ts +6 -5
- package/src/interfaces/ApiLambdaResult.ts +6 -6
- package/src/interfaces/BaseResourceProps.ts +6 -6
- package/src/interfaces/CreateLambdaFunctionInput.ts +10 -10
- package/src/interfaces/MicroserviceProps.ts +10 -10
- package/src/interfaces/timer-job/index.ts +1 -0
- package/src/interfaces/timer-job/timer-job-props.ts +17 -0
- package/src/resources/base/baseResource.ts +14 -14
- package/src/resources/base/tsgBaseResource.ts +21 -21
- package/src/resources/certificate/createCertificate.ts +57 -57
- package/src/resources/cognito/createCognito.ts +47 -47
- package/src/resources/cognito/createCognitoProps.ts +46 -46
- package/src/resources/customResource/createSeedDatabaseCustomResource.ts +36 -36
- package/src/resources/dynamodb/CreateDynamo.ts +110 -110
- package/src/resources/dynamodb/CreateDynamoSingleTableDesign.ts +111 -111
- package/src/resources/ec2/create-ec2-instance.ts +52 -52
- package/src/resources/ecr/CreateEcr.ts +57 -57
- package/src/resources/gateway/CreateApiAndAttachLambdas.ts +161 -161
- package/src/resources/gateway/createApi.ts +173 -173
- package/src/resources/gateway/createApiKey.ts +88 -88
- package/src/resources/helpers/createCommonLayer.ts +18 -18
- package/src/resources/helpers/createRoutes.ts +74 -74
- package/src/resources/index.ts +1 -1
- package/src/resources/lambda/create-basic-lambda.ts +104 -0
- package/src/resources/lambda/createLambda.ts +203 -200
- package/src/resources/lambda/lambdaHelper.ts +133 -133
- package/src/resources/lambda-authorizer/TsgJwtTokenAuthorizer.ts +107 -107
- package/src/resources/lambda-authorizer/TsgRequestAuthorizer.ts +44 -44
- package/src/resources/lambda-authorizer/createAuthorizerHelpers.ts +76 -76
- package/src/resources/lambda-layer/createLambdaLayer.ts +39 -39
- package/src/resources/layers/common/package.json +22 -22
- package/src/resources/layers/common/src/nodejs/api-response/responses.ts +41 -41
- package/src/resources/layers/common/src/nodejs/index.ts +3 -3
- package/src/resources/layers/common/src/nodejs/logger/IContext.ts +6 -6
- package/src/resources/layers/common/src/nodejs/logger/index.ts +1 -1
- package/src/resources/layers/common/src/nodejs/logger/logger.ts +10 -10
- package/src/resources/layers/common/tsconfig.json +7 -7
- package/src/resources/resources/iam/policyDocuments/cognitoPolicy.ts +54 -54
- package/src/resources/resources/iam/roles/createRole.ts +29 -29
- package/src/resources/route53/CreateZone.ts +61 -61
- package/src/resources/route53/create-zones.ts +40 -40
- package/src/resources/securityManager/index.ts +23 -23
- package/tsconfig.json +44 -42
|
@@ -1,111 +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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.config.RESOURCES.DYNAMO?.TABLES?.[idx].indexes.map((gsi) => {
|
|
53
|
-
|
|
54
|
-
const gsiProps: GlobalSecondaryIndexProps = {
|
|
55
|
-
indexName: gsi.indexName,
|
|
56
|
-
partitionKey: gsi.partitionKey,
|
|
57
|
-
sortKey: gsi.sortKey,
|
|
58
|
-
projectionType: gsi.projectionType
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
dbTable.addGlobalSecondaryIndex(gsiProps);
|
|
63
|
-
});
|
|
64
|
-
return dbTable;
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
return tables ?? [];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
protected createOutput<T>(scope: Construct, createdAssets: T[]): void {
|
|
75
|
-
this.createdResources!.forEach((x, idx) => {
|
|
76
|
-
new CfnOutput(scope, `dynamoTable${idx}`, {
|
|
77
|
-
value: x.tableName
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
private createProps() {
|
|
83
|
-
const props = this.config.RESOURCES?.DYNAMO?.TABLES?.map((x) => {
|
|
84
|
-
|
|
85
|
-
const prop: any = {};
|
|
86
|
-
|
|
87
|
-
prop.tableName = this.generateDbName(x.tableName);
|
|
88
|
-
|
|
89
|
-
prop.partitionKey = {
|
|
90
|
-
name: x.primaryKey.name,
|
|
91
|
-
type: x.primaryKey.type
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
prop.billingMode = x.billingMode;
|
|
95
|
-
|
|
96
|
-
if (x.sortKey) {
|
|
97
|
-
prop.sortKey = {
|
|
98
|
-
name: x.sortKey.name,
|
|
99
|
-
type: x.sortKey.type,
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return prop as TableProps;
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
return props;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
private generateDbName(tableName: string) {
|
|
109
|
-
return `${this.config.AppPrefix}-${tableName}`;
|
|
110
|
-
}
|
|
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
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
this.config.RESOURCES.DYNAMO?.TABLES?.[idx].indexes.map((gsi) => {
|
|
53
|
+
|
|
54
|
+
const gsiProps: GlobalSecondaryIndexProps = {
|
|
55
|
+
indexName: gsi.indexName,
|
|
56
|
+
partitionKey: gsi.partitionKey,
|
|
57
|
+
sortKey: gsi.sortKey,
|
|
58
|
+
projectionType: gsi.projectionType
|
|
59
|
+
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
dbTable.addGlobalSecondaryIndex(gsiProps);
|
|
63
|
+
});
|
|
64
|
+
return dbTable;
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
return tables ?? [];
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
protected createOutput<T>(scope: Construct, createdAssets: T[]): void {
|
|
75
|
+
this.createdResources!.forEach((x, idx) => {
|
|
76
|
+
new CfnOutput(scope, `dynamoTable${idx}`, {
|
|
77
|
+
value: x.tableName
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private createProps() {
|
|
83
|
+
const props = this.config.RESOURCES?.DYNAMO?.TABLES?.map((x) => {
|
|
84
|
+
|
|
85
|
+
const prop: any = {};
|
|
86
|
+
|
|
87
|
+
prop.tableName = this.generateDbName(x.tableName);
|
|
88
|
+
|
|
89
|
+
prop.partitionKey = {
|
|
90
|
+
name: x.primaryKey.name,
|
|
91
|
+
type: x.primaryKey.type
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
prop.billingMode = x.billingMode;
|
|
95
|
+
|
|
96
|
+
if (x.sortKey) {
|
|
97
|
+
prop.sortKey = {
|
|
98
|
+
name: x.sortKey.name,
|
|
99
|
+
type: x.sortKey.type,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return prop as TableProps;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return props;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private generateDbName(tableName: string) {
|
|
109
|
+
return `${this.config.AppPrefix}-${tableName}`;
|
|
110
|
+
}
|
|
111
111
|
}
|
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import { CfnOutput, RemovalPolicy } from "aws-cdk-lib";
|
|
2
|
-
import { AttributeType, BillingMode, GlobalSecondaryIndexProps, ProjectionType, Table, TableProps } from "aws-cdk-lib/aws-dynamodb";
|
|
3
|
-
import { Construct } from "constructs";
|
|
4
|
-
import { TsgBaseResource } from "../base/tsgBaseResource";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export class CreateDynamoSingleTableDesign extends TsgBaseResource<Table, string> {
|
|
8
|
-
|
|
9
|
-
static ReadWriteActions: string[] = [
|
|
10
|
-
"dynamodb:BatchGetItem",
|
|
11
|
-
"dynamodb:BatchWriteItem",
|
|
12
|
-
"dynamodb:ConditionCheckItem",
|
|
13
|
-
"dynamodb:DeleteItem",
|
|
14
|
-
"dynamodb:DescribeTable",
|
|
15
|
-
"dynamodb:GetItem",
|
|
16
|
-
"dynamodb:GetRecords",
|
|
17
|
-
"dynamodb:GetShardIterator",
|
|
18
|
-
"dynamodb:PutItem",
|
|
19
|
-
"dynamodb:Query",
|
|
20
|
-
"dynamodb:Scan",
|
|
21
|
-
"dynamodb:UpdateItem",
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
get CreatedTable() {
|
|
25
|
-
return this.createdResource;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
constructor(protected scope: Construct, protected tableName: string) {
|
|
29
|
-
super(scope, tableName);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
protected createResource(scope: Construct): Table {
|
|
33
|
-
|
|
34
|
-
const dbTable = new Table(scope, `${this.tableName}`, {
|
|
35
|
-
tableName: this.tableName,
|
|
36
|
-
removalPolicy: RemovalPolicy.DESTROY,
|
|
37
|
-
|
|
38
|
-
partitionKey: {
|
|
39
|
-
name: 'pk',
|
|
40
|
-
type: AttributeType.STRING,
|
|
41
|
-
},
|
|
42
|
-
sortKey: {
|
|
43
|
-
name: 'sk',
|
|
44
|
-
type: AttributeType.STRING,
|
|
45
|
-
},
|
|
46
|
-
billingMode: BillingMode.PAY_PER_REQUEST,
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const gsiIndexes = [
|
|
50
|
-
{
|
|
51
|
-
indexName: 'gsi1Index',
|
|
52
|
-
partitionKey: {
|
|
53
|
-
name: 'gsi1pk',
|
|
54
|
-
type: AttributeType.STRING
|
|
55
|
-
},
|
|
56
|
-
sortKey: {
|
|
57
|
-
name: 'gsi1sk',
|
|
58
|
-
type: AttributeType.STRING
|
|
59
|
-
},
|
|
60
|
-
projectionType: ProjectionType.ALL
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
indexName: 'gsi2Index',
|
|
64
|
-
partitionKey: {
|
|
65
|
-
name: 'gsi2pk',
|
|
66
|
-
type: AttributeType.STRING
|
|
67
|
-
},
|
|
68
|
-
sortKey: {
|
|
69
|
-
name: 'gsi2sk',
|
|
70
|
-
type: AttributeType.STRING
|
|
71
|
-
},
|
|
72
|
-
projectionType: ProjectionType.ALL
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
indexName: 'gsi3Index',
|
|
76
|
-
partitionKey: {
|
|
77
|
-
name: 'gsi3pk',
|
|
78
|
-
type: AttributeType.STRING
|
|
79
|
-
},
|
|
80
|
-
sortKey: {
|
|
81
|
-
name: 'gsi3sk',
|
|
82
|
-
type: AttributeType.STRING
|
|
83
|
-
},
|
|
84
|
-
projectionType: ProjectionType.ALL
|
|
85
|
-
},
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
gsiIndexes.map((gsi) => {
|
|
89
|
-
|
|
90
|
-
const gsiProps: GlobalSecondaryIndexProps = {
|
|
91
|
-
indexName: gsi.indexName,
|
|
92
|
-
partitionKey: gsi.partitionKey,
|
|
93
|
-
sortKey: gsi.sortKey,
|
|
94
|
-
projectionType: gsi.projectionType
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
dbTable.addGlobalSecondaryIndex(gsiProps);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
return dbTable;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
protected createOutput<T>(scope: Construct): void {
|
|
106
|
-
|
|
107
|
-
new CfnOutput(scope, `dynamoTable-${this.CreatedTable?.tableName}`, {
|
|
108
|
-
value: `Table Name: ${this.createdResource?.tableName}\t Table Arn: ${this.createdResource?.tableArn}`
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
}
|
|
1
|
+
import { CfnOutput, RemovalPolicy } from "aws-cdk-lib";
|
|
2
|
+
import { AttributeType, BillingMode, GlobalSecondaryIndexProps, ProjectionType, Table, TableProps } from "aws-cdk-lib/aws-dynamodb";
|
|
3
|
+
import { Construct } from "constructs";
|
|
4
|
+
import { TsgBaseResource } from "../base/tsgBaseResource";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export class CreateDynamoSingleTableDesign extends TsgBaseResource<Table, string> {
|
|
8
|
+
|
|
9
|
+
static ReadWriteActions: string[] = [
|
|
10
|
+
"dynamodb:BatchGetItem",
|
|
11
|
+
"dynamodb:BatchWriteItem",
|
|
12
|
+
"dynamodb:ConditionCheckItem",
|
|
13
|
+
"dynamodb:DeleteItem",
|
|
14
|
+
"dynamodb:DescribeTable",
|
|
15
|
+
"dynamodb:GetItem",
|
|
16
|
+
"dynamodb:GetRecords",
|
|
17
|
+
"dynamodb:GetShardIterator",
|
|
18
|
+
"dynamodb:PutItem",
|
|
19
|
+
"dynamodb:Query",
|
|
20
|
+
"dynamodb:Scan",
|
|
21
|
+
"dynamodb:UpdateItem",
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
get CreatedTable() {
|
|
25
|
+
return this.createdResource;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor(protected scope: Construct, protected tableName: string) {
|
|
29
|
+
super(scope, tableName);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
protected createResource(scope: Construct): Table {
|
|
33
|
+
|
|
34
|
+
const dbTable = new Table(scope, `${this.tableName}`, {
|
|
35
|
+
tableName: this.tableName,
|
|
36
|
+
removalPolicy: RemovalPolicy.DESTROY,
|
|
37
|
+
|
|
38
|
+
partitionKey: {
|
|
39
|
+
name: 'pk',
|
|
40
|
+
type: AttributeType.STRING,
|
|
41
|
+
},
|
|
42
|
+
sortKey: {
|
|
43
|
+
name: 'sk',
|
|
44
|
+
type: AttributeType.STRING,
|
|
45
|
+
},
|
|
46
|
+
billingMode: BillingMode.PAY_PER_REQUEST,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const gsiIndexes = [
|
|
50
|
+
{
|
|
51
|
+
indexName: 'gsi1Index',
|
|
52
|
+
partitionKey: {
|
|
53
|
+
name: 'gsi1pk',
|
|
54
|
+
type: AttributeType.STRING
|
|
55
|
+
},
|
|
56
|
+
sortKey: {
|
|
57
|
+
name: 'gsi1sk',
|
|
58
|
+
type: AttributeType.STRING
|
|
59
|
+
},
|
|
60
|
+
projectionType: ProjectionType.ALL
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
indexName: 'gsi2Index',
|
|
64
|
+
partitionKey: {
|
|
65
|
+
name: 'gsi2pk',
|
|
66
|
+
type: AttributeType.STRING
|
|
67
|
+
},
|
|
68
|
+
sortKey: {
|
|
69
|
+
name: 'gsi2sk',
|
|
70
|
+
type: AttributeType.STRING
|
|
71
|
+
},
|
|
72
|
+
projectionType: ProjectionType.ALL
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
indexName: 'gsi3Index',
|
|
76
|
+
partitionKey: {
|
|
77
|
+
name: 'gsi3pk',
|
|
78
|
+
type: AttributeType.STRING
|
|
79
|
+
},
|
|
80
|
+
sortKey: {
|
|
81
|
+
name: 'gsi3sk',
|
|
82
|
+
type: AttributeType.STRING
|
|
83
|
+
},
|
|
84
|
+
projectionType: ProjectionType.ALL
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
gsiIndexes.map((gsi) => {
|
|
89
|
+
|
|
90
|
+
const gsiProps: GlobalSecondaryIndexProps = {
|
|
91
|
+
indexName: gsi.indexName,
|
|
92
|
+
partitionKey: gsi.partitionKey,
|
|
93
|
+
sortKey: gsi.sortKey,
|
|
94
|
+
projectionType: gsi.projectionType
|
|
95
|
+
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
dbTable.addGlobalSecondaryIndex(gsiProps);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return dbTable;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
protected createOutput<T>(scope: Construct): void {
|
|
106
|
+
|
|
107
|
+
new CfnOutput(scope, `dynamoTable-${this.CreatedTable?.tableName}`, {
|
|
108
|
+
value: `Table Name: ${this.createdResource?.tableName}\t Table Arn: ${this.createdResource?.tableArn}`
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
}
|
|
112
112
|
}
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { Instance, InstanceType, InstanceClass, InstanceSize, MachineImage, Vpc, CfnKeyPair } from "aws-cdk-lib/aws-ec2";
|
|
2
|
-
import { BaseResource } from "../base/baseResource";
|
|
3
|
-
import { Construct } from "constructs";
|
|
4
|
-
import { AppConfig } from "../../config/AppConfig";
|
|
5
|
-
import { CfnOutput } from "aws-cdk-lib";
|
|
6
|
-
|
|
7
|
-
export class Ec2Instance extends BaseResource<Instance> {
|
|
8
|
-
|
|
9
|
-
constructor(scope: Construct, config: AppConfig) {
|
|
10
|
-
super(scope, config);
|
|
11
|
-
|
|
12
|
-
const createdAssets = this.createResource(scope);
|
|
13
|
-
|
|
14
|
-
this.createOutput<Instance>(scope, createdAssets!);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
protected createResource(scope: Construct): Instance[] | null {
|
|
18
|
-
|
|
19
|
-
const keyPair = new CfnKeyPair(scope, 'my-key-pair', {
|
|
20
|
-
keyName: 'davis-dsylv-amazon-com',
|
|
21
|
-
publicKeyMaterial: process.env.KEY_PAIR
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const server = new Instance(scope, `my-ec2`, {
|
|
25
|
-
vpc: Vpc.fromLookup(scope, 'VPC', {
|
|
26
|
-
vpcId: process.env.VPC_PRIMARY_ID,
|
|
27
|
-
isDefault: true
|
|
28
|
-
}),
|
|
29
|
-
instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.SMALL),
|
|
30
|
-
machineImage: MachineImage.genericLinux({
|
|
31
|
-
'us-east-1': 'ami-010e83f579f15bba0'
|
|
32
|
-
}),
|
|
33
|
-
keyName: keyPair.keyName
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return [server];
|
|
38
|
-
}
|
|
39
|
-
protected createOutput<T>(scope: Construct, createdAssets: T[]): void {
|
|
40
|
-
|
|
41
|
-
createdAssets.forEach((asset, index) => {
|
|
42
|
-
new CfnOutput(scope, `my-ec2-instance-${index}`, {
|
|
43
|
-
value: `Server Name: ${(asset as Instance).instancePrivateDnsName} \n
|
|
44
|
-
Private: ${(asset as Instance).instancePrivateIp} \n
|
|
45
|
-
Public: ${(asset as Instance).instancePublicIp}`
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
import { Instance, InstanceType, InstanceClass, InstanceSize, MachineImage, Vpc, CfnKeyPair } from "aws-cdk-lib/aws-ec2";
|
|
2
|
+
import { BaseResource } from "../base/baseResource";
|
|
3
|
+
import { Construct } from "constructs";
|
|
4
|
+
import { AppConfig } from "../../config/AppConfig";
|
|
5
|
+
import { CfnOutput } from "aws-cdk-lib";
|
|
6
|
+
|
|
7
|
+
export class Ec2Instance extends BaseResource<Instance> {
|
|
8
|
+
|
|
9
|
+
constructor(scope: Construct, config: AppConfig) {
|
|
10
|
+
super(scope, config);
|
|
11
|
+
|
|
12
|
+
const createdAssets = this.createResource(scope);
|
|
13
|
+
|
|
14
|
+
this.createOutput<Instance>(scope, createdAssets!);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
protected createResource(scope: Construct): Instance[] | null {
|
|
18
|
+
|
|
19
|
+
const keyPair = new CfnKeyPair(scope, 'my-key-pair', {
|
|
20
|
+
keyName: 'davis-dsylv-amazon-com',
|
|
21
|
+
publicKeyMaterial: process.env.KEY_PAIR
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const server = new Instance(scope, `my-ec2`, {
|
|
25
|
+
vpc: Vpc.fromLookup(scope, 'VPC', {
|
|
26
|
+
vpcId: process.env.VPC_PRIMARY_ID,
|
|
27
|
+
isDefault: true
|
|
28
|
+
}),
|
|
29
|
+
instanceType: InstanceType.of(InstanceClass.T3, InstanceSize.SMALL),
|
|
30
|
+
machineImage: MachineImage.genericLinux({
|
|
31
|
+
'us-east-1': 'ami-010e83f579f15bba0'
|
|
32
|
+
}),
|
|
33
|
+
keyName: keyPair.keyName
|
|
34
|
+
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return [server];
|
|
38
|
+
}
|
|
39
|
+
protected createOutput<T>(scope: Construct, createdAssets: T[]): void {
|
|
40
|
+
|
|
41
|
+
createdAssets.forEach((asset, index) => {
|
|
42
|
+
new CfnOutput(scope, `my-ec2-instance-${index}`, {
|
|
43
|
+
value: `Server Name: ${(asset as Instance).instancePrivateDnsName} \n
|
|
44
|
+
Private: ${(asset as Instance).instancePrivateIp} \n
|
|
45
|
+
Public: ${(asset as Instance).instancePublicIp}`
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
53
|
}
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import * as ecr from "aws-cdk-lib/aws-ecr";
|
|
2
|
-
import { BaseResource } from "../base/baseResource";
|
|
3
|
-
import { Construct } from "constructs";
|
|
4
|
-
import { CfnOutput, RemovalPolicy } from "aws-cdk-lib";
|
|
5
|
-
import { BaseResourceProps } from "../../interfaces/BaseResourceProps";
|
|
6
|
-
|
|
7
|
-
export class TsgECR extends BaseResource<ecr.Repository> {
|
|
8
|
-
|
|
9
|
-
constructor(props: BaseResourceProps) {
|
|
10
|
-
|
|
11
|
-
super(props.scope, props.config);
|
|
12
|
-
|
|
13
|
-
const repos = this.createResource(props.scope);
|
|
14
|
-
|
|
15
|
-
this.createdResources = [...repos as []];
|
|
16
|
-
|
|
17
|
-
this.createOutput(props.scope, this.createdResources);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
protected createResource(scope: Construct): ecr.Repository[] | null {
|
|
21
|
-
|
|
22
|
-
const ecrRepo = new ecr.Repository(scope,
|
|
23
|
-
`${this.config.AppName}-repository`,
|
|
24
|
-
{
|
|
25
|
-
repositoryName: `${this.config.AppName}-repository`,
|
|
26
|
-
removalPolicy: RemovalPolicy.DESTROY,
|
|
27
|
-
autoDeleteImages: true,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const rule: ecr.LifecycleRule = {
|
|
31
|
-
description: 'Image Rentention',
|
|
32
|
-
maxImageCount: 20
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
ecrRepo.addLifecycleRule(rule);
|
|
36
|
-
|
|
37
|
-
if (ecrRepo instanceof ecr.Repository) {
|
|
38
|
-
return [ecrRepo];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected createOutput<Repository>(scope: Construct, createdAssets: Repository[]): void {
|
|
45
|
-
|
|
46
|
-
createdAssets.forEach((x, idx) => {
|
|
47
|
-
|
|
48
|
-
new CfnOutput(scope, `respository-${idx}`, {
|
|
49
|
-
value: `Name: ${(x as ecr.Repository).repositoryName}\n
|
|
50
|
-
Url: ${(x as ecr.Repository).repositoryUri}`
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
import * as ecr from "aws-cdk-lib/aws-ecr";
|
|
2
|
+
import { BaseResource } from "../base/baseResource";
|
|
3
|
+
import { Construct } from "constructs";
|
|
4
|
+
import { CfnOutput, RemovalPolicy } from "aws-cdk-lib";
|
|
5
|
+
import { BaseResourceProps } from "../../interfaces/BaseResourceProps";
|
|
6
|
+
|
|
7
|
+
export class TsgECR extends BaseResource<ecr.Repository> {
|
|
8
|
+
|
|
9
|
+
constructor(props: BaseResourceProps) {
|
|
10
|
+
|
|
11
|
+
super(props.scope, props.config);
|
|
12
|
+
|
|
13
|
+
const repos = this.createResource(props.scope);
|
|
14
|
+
|
|
15
|
+
this.createdResources = [...repos as []];
|
|
16
|
+
|
|
17
|
+
this.createOutput(props.scope, this.createdResources);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
protected createResource(scope: Construct): ecr.Repository[] | null {
|
|
21
|
+
|
|
22
|
+
const ecrRepo = new ecr.Repository(scope,
|
|
23
|
+
`${this.config.AppName}-repository`,
|
|
24
|
+
{
|
|
25
|
+
repositoryName: `${this.config.AppName}-repository`,
|
|
26
|
+
removalPolicy: RemovalPolicy.DESTROY,
|
|
27
|
+
autoDeleteImages: true,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const rule: ecr.LifecycleRule = {
|
|
31
|
+
description: 'Image Rentention',
|
|
32
|
+
maxImageCount: 20
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
ecrRepo.addLifecycleRule(rule);
|
|
36
|
+
|
|
37
|
+
if (ecrRepo instanceof ecr.Repository) {
|
|
38
|
+
return [ecrRepo];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
protected createOutput<Repository>(scope: Construct, createdAssets: Repository[]): void {
|
|
45
|
+
|
|
46
|
+
createdAssets.forEach((x, idx) => {
|
|
47
|
+
|
|
48
|
+
new CfnOutput(scope, `respository-${idx}`, {
|
|
49
|
+
value: `Name: ${(x as ecr.Repository).repositoryName}\n
|
|
50
|
+
Url: ${(x as ecr.Repository).repositoryUri}`
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
58
|
}
|