@dga-itc/aws-cdk-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/README.md +219 -0
- package/dist/aws-cdk/constructs/acm.d.ts +28 -0
- package/dist/aws-cdk/constructs/acm.js +239 -0
- package/dist/aws-cdk/constructs/alb.d.ts +28 -0
- package/dist/aws-cdk/constructs/alb.js +304 -0
- package/dist/aws-cdk/constructs/bastion.d.ts +46 -0
- package/dist/aws-cdk/constructs/bastion.js +332 -0
- package/dist/aws-cdk/constructs/cloudfront.d.ts +45 -0
- package/dist/aws-cdk/constructs/cloudfront.js +261 -0
- package/dist/aws-cdk/constructs/ecr.d.ts +17 -0
- package/dist/aws-cdk/constructs/ecr.js +143 -0
- package/dist/aws-cdk/constructs/ecs-cluster.d.ts +21 -0
- package/dist/aws-cdk/constructs/ecs-cluster.js +124 -0
- package/dist/aws-cdk/constructs/ecs-service.d.ts +72 -0
- package/dist/aws-cdk/constructs/ecs-service.js +682 -0
- package/dist/aws-cdk/constructs/efs.d.ts +31 -0
- package/dist/aws-cdk/constructs/efs.js +241 -0
- package/dist/aws-cdk/constructs/elasticache.d.ts +35 -0
- package/dist/aws-cdk/constructs/elasticache.js +210 -0
- package/dist/aws-cdk/constructs/nacl.d.ts +37 -0
- package/dist/aws-cdk/constructs/nacl.js +88 -0
- package/dist/aws-cdk/constructs/nlb.d.ts +39 -0
- package/dist/aws-cdk/constructs/nlb.js +276 -0
- package/dist/aws-cdk/constructs/rds.d.ts +40 -0
- package/dist/aws-cdk/constructs/rds.js +320 -0
- package/dist/aws-cdk/constructs/self-signed-cert.d.ts +83 -0
- package/dist/aws-cdk/constructs/self-signed-cert.js +215 -0
- package/dist/aws-cdk/constructs/sqs.d.ts +30 -0
- package/dist/aws-cdk/constructs/sqs.js +268 -0
- package/dist/aws-cdk/constructs/vpc.d.ts +30 -0
- package/dist/aws-cdk/constructs/vpc.js +423 -0
- package/dist/aws-cdk/constructs/waf.d.ts +37 -0
- package/dist/aws-cdk/constructs/waf.js +350 -0
- package/dist/aws-cdk/interfaces/account-config.d.ts +18 -0
- package/dist/aws-cdk/interfaces/account-config.js +2 -0
- package/dist/aws-cdk/interfaces/acm-config.d.ts +94 -0
- package/dist/aws-cdk/interfaces/acm-config.js +14 -0
- package/dist/aws-cdk/interfaces/alb-config.d.ts +72 -0
- package/dist/aws-cdk/interfaces/alb-config.js +2 -0
- package/dist/aws-cdk/interfaces/bastion-config.d.ts +77 -0
- package/dist/aws-cdk/interfaces/bastion-config.js +10 -0
- package/dist/aws-cdk/interfaces/cloudfront-config.d.ts +154 -0
- package/dist/aws-cdk/interfaces/cloudfront-config.js +15 -0
- package/dist/aws-cdk/interfaces/ecr-config.d.ts +40 -0
- package/dist/aws-cdk/interfaces/ecr-config.js +2 -0
- package/dist/aws-cdk/interfaces/ecs-cluster-config.d.ts +30 -0
- package/dist/aws-cdk/interfaces/ecs-cluster-config.js +2 -0
- package/dist/aws-cdk/interfaces/ecs-service-config.d.ts +237 -0
- package/dist/aws-cdk/interfaces/ecs-service-config.js +2 -0
- package/dist/aws-cdk/interfaces/efs-config.d.ts +56 -0
- package/dist/aws-cdk/interfaces/efs-config.js +7 -0
- package/dist/aws-cdk/interfaces/elasticache-config.d.ts +56 -0
- package/dist/aws-cdk/interfaces/elasticache-config.js +7 -0
- package/dist/aws-cdk/interfaces/nacl-config.d.ts +1 -0
- package/dist/aws-cdk/interfaces/nacl-config.js +3 -0
- package/dist/aws-cdk/interfaces/nlb-config.d.ts +69 -0
- package/dist/aws-cdk/interfaces/nlb-config.js +2 -0
- package/dist/aws-cdk/interfaces/rds-config.d.ts +84 -0
- package/dist/aws-cdk/interfaces/rds-config.js +7 -0
- package/dist/aws-cdk/interfaces/sqs-config.d.ts +145 -0
- package/dist/aws-cdk/interfaces/sqs-config.js +12 -0
- package/dist/aws-cdk/interfaces/tag-config.d.ts +18 -0
- package/dist/aws-cdk/interfaces/tag-config.js +2 -0
- package/dist/aws-cdk/interfaces/vpc-config.d.ts +72 -0
- package/dist/aws-cdk/interfaces/vpc-config.js +2 -0
- package/dist/aws-cdk/interfaces/waf-config.d.ts +180 -0
- package/dist/aws-cdk/interfaces/waf-config.js +2 -0
- package/dist/aws-cdk/utils/priority-tracker.d.ts +60 -0
- package/dist/aws-cdk/utils/priority-tracker.js +131 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +55 -0
- package/dist/terraform-cdk/constructs/alb-listener-rule.d.ts +33 -0
- package/dist/terraform-cdk/constructs/alb-listener-rule.js +81 -0
- package/dist/terraform-cdk/constructs/ecs-service.d.ts +29 -0
- package/dist/terraform-cdk/constructs/ecs-service.js +238 -0
- package/dist/terraform-cdk/interfaces/ecs-service-config.d.ts +53 -0
- package/dist/terraform-cdk/interfaces/ecs-service-config.js +25 -0
- package/dist/terraform-cdk/interfaces/infrastructure-refs.d.ts +16 -0
- package/dist/terraform-cdk/interfaces/infrastructure-refs.js +8 -0
- package/dist/terraform-cdk/utils/priority-tracker.d.ts +60 -0
- package/dist/terraform-cdk/utils/priority-tracker.js +131 -0
- package/package.json +46 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CloudFront + VPC Origin Config Interface
|
|
3
|
+
*
|
|
4
|
+
* ใช้สำหรับสร้าง CloudFront Distribution ที่ชี้ไปยัง Private ALB
|
|
5
|
+
* ผ่าน VPC Origin — ไม่ต้องเปิด ALB เป็น internet-facing
|
|
6
|
+
*
|
|
7
|
+
* Architecture:
|
|
8
|
+
* Client → CloudFront (edge) → VPC Origin → Private ALB → ECS Fargate
|
|
9
|
+
*
|
|
10
|
+
* VPC Origin:
|
|
11
|
+
* CloudFront จะเชื่อมต่อ ALB ผ่าน AWS backbone โดยตรง
|
|
12
|
+
* ไม่ต้อง expose ALB ออก internet
|
|
13
|
+
*/
|
|
14
|
+
export interface CloudFrontVpcOriginConfig {
|
|
15
|
+
/** ชื่อ VPC Origin (display name) */
|
|
16
|
+
name: string;
|
|
17
|
+
/** HTTP port ฝั่ง origin (default: 80) */
|
|
18
|
+
httpPort?: number;
|
|
19
|
+
/** HTTPS port ฝั่ง origin (default: 443) */
|
|
20
|
+
httpsPort?: number;
|
|
21
|
+
/**
|
|
22
|
+
* Protocol policy ไป origin
|
|
23
|
+
* - 'https-only' → ส่ง HTTPS เท่านั้น (recommended)
|
|
24
|
+
* - 'http-only' → ส่ง HTTP เท่านั้น
|
|
25
|
+
* - 'match-viewer' → ส่งตาม protocol ที่ viewer ใช้
|
|
26
|
+
* (default: 'https-only')
|
|
27
|
+
*/
|
|
28
|
+
originProtocolPolicy?: 'http-only' | 'https-only' | 'match-viewer';
|
|
29
|
+
/** Origin read timeout ในวินาที (default: 30) */
|
|
30
|
+
originReadTimeout?: number;
|
|
31
|
+
/** Origin keep-alive timeout ในวินาที (default: 5) */
|
|
32
|
+
originKeepaliveTimeout?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface CloudFrontCacheBehaviorConfig {
|
|
35
|
+
/**
|
|
36
|
+
* Viewer protocol policy
|
|
37
|
+
* - 'redirect-to-https' → redirect HTTP → HTTPS (recommended)
|
|
38
|
+
* - 'https-only' → HTTPS only, reject HTTP
|
|
39
|
+
* - 'allow-all' → allow both
|
|
40
|
+
* (default: 'redirect-to-https')
|
|
41
|
+
*/
|
|
42
|
+
viewerProtocolPolicy?: 'allow-all' | 'https-only' | 'redirect-to-https';
|
|
43
|
+
/** Allowed HTTP methods (default: all methods) */
|
|
44
|
+
allowedMethods?: string[];
|
|
45
|
+
/** Cached HTTP methods (default: ['GET', 'HEAD']) */
|
|
46
|
+
cachedMethods?: string[];
|
|
47
|
+
/**
|
|
48
|
+
* Cache Policy ID (AWS Managed Policies):
|
|
49
|
+
* - '658327ea-f89d-4fab-a63d-7e88639e58f6' = CachingOptimized
|
|
50
|
+
* - '4135ea2d-6df8-44a3-9df3-4b5a84be39ad' = CachingDisabled
|
|
51
|
+
* - 'b2884449-e4de-46a7-ac36-70bc7f1ddd6d' = CachingOptimizedForUncompressedObjects
|
|
52
|
+
* (default: CachingDisabled — เหมาะกับ dynamic content)
|
|
53
|
+
*/
|
|
54
|
+
cachePolicyId?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Origin Request Policy ID (AWS Managed Policies):
|
|
57
|
+
* - '216adef6-5c7f-47e4-b989-5492eafa07d3' = AllViewer
|
|
58
|
+
* - '33f36d7e-f396-46d9-90e0-52428a34d9dc' = AllViewerAndCloudFrontHeaders-2022-06
|
|
59
|
+
* (default: AllViewer — forward ทุก header/cookie/querystring ไป origin)
|
|
60
|
+
*/
|
|
61
|
+
originRequestPolicyId?: string;
|
|
62
|
+
/** Response Headers Policy ID */
|
|
63
|
+
responseHeadersPolicyId?: string;
|
|
64
|
+
/** Compress objects automatically (default: true) */
|
|
65
|
+
compress?: boolean;
|
|
66
|
+
}
|
|
67
|
+
export interface CloudFrontAdditionalBehavior {
|
|
68
|
+
/** Path pattern (e.g., '/api/*', '/static/*', '*.jpg') */
|
|
69
|
+
pathPattern: string;
|
|
70
|
+
/** Cache behavior config for this path */
|
|
71
|
+
behavior: CloudFrontCacheBehaviorConfig;
|
|
72
|
+
}
|
|
73
|
+
export interface CloudFrontCustomErrorResponseConfig {
|
|
74
|
+
/** HTTP error code to intercept (e.g., 403, 404, 500, 502, 503, 504) */
|
|
75
|
+
errorCode: number;
|
|
76
|
+
/** Response HTTP code to return (e.g., 200 for SPA fallback) */
|
|
77
|
+
responseCode?: number;
|
|
78
|
+
/** Custom error page path (e.g., '/index.html' for SPA) */
|
|
79
|
+
responsePagePath?: string;
|
|
80
|
+
/** Error caching TTL in seconds (default: 300) */
|
|
81
|
+
errorCachingMinTtl?: number;
|
|
82
|
+
}
|
|
83
|
+
export interface CloudFrontConfig {
|
|
84
|
+
stackName: string;
|
|
85
|
+
/** Comment / description สำหรับ distribution */
|
|
86
|
+
distributionComment?: string;
|
|
87
|
+
/** Account config reference (ดู configs/accounts/) */
|
|
88
|
+
accountConfigName?: string;
|
|
89
|
+
account?: string;
|
|
90
|
+
region?: string;
|
|
91
|
+
/** Source references — อ้างอิง VPC + ALB stacks */
|
|
92
|
+
source: {
|
|
93
|
+
/** VPC stack name — ใช้ดึง VPC ID */
|
|
94
|
+
vpcStackName: string;
|
|
95
|
+
/** ALB stack name — ใช้ดึง ALB ARN + DNS Name */
|
|
96
|
+
albStackName: string;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* ACM stack name สำหรับ CloudFront
|
|
100
|
+
* ⚠️ ต้องเป็น ACM certificate ใน us-east-1 เท่านั้น
|
|
101
|
+
* อ้างอิงจาก AcmStack (e.g., 'demo-dev-acm-request-use1')
|
|
102
|
+
*/
|
|
103
|
+
acmStackName?: string;
|
|
104
|
+
/** ACM certificate ARN ตรงๆ (ต้องเป็น us-east-1) */
|
|
105
|
+
certificateArn?: string;
|
|
106
|
+
/** Minimum SSL/TLS protocol version (default: 'TLSv1.2_2021') */
|
|
107
|
+
minimumProtocolVersion?: string;
|
|
108
|
+
/** Domain aliases (e.g., ['app.example.com', 'www.example.com']) */
|
|
109
|
+
domainNames?: string[];
|
|
110
|
+
/** VPC Origin configuration */
|
|
111
|
+
vpcOrigin: CloudFrontVpcOriginConfig;
|
|
112
|
+
/** Default cache behavior (applies to all paths unless overridden) */
|
|
113
|
+
defaultCacheBehavior?: CloudFrontCacheBehaviorConfig;
|
|
114
|
+
/** Additional path-based cache behaviors */
|
|
115
|
+
additionalBehaviors?: CloudFrontAdditionalBehavior[];
|
|
116
|
+
/**
|
|
117
|
+
* WAF stack name — อ้างอิง WafStack เพื่อดึง WebACL ARN อัตโนมัติ
|
|
118
|
+
* ⚠️ WAF scope ต้องเป็น CLOUDFRONT และ deploy ใน us-east-1
|
|
119
|
+
* ถ้าระบุ wafStackName จะ override webAclId
|
|
120
|
+
*/
|
|
121
|
+
wafStackName?: string;
|
|
122
|
+
/** WAF Web ACL ARN ตรงๆ (ต้องเป็น WAF v2 ใน us-east-1) */
|
|
123
|
+
webAclId?: string;
|
|
124
|
+
/**
|
|
125
|
+
* อัปเดต ALB Security Group อัตโนมัติ
|
|
126
|
+
* เพิ่ม rule allow HTTPS จาก CloudFront VPC Origin
|
|
127
|
+
* (default: true)
|
|
128
|
+
*
|
|
129
|
+
* ⚠️ สำหรับ production ควรใช้ cloudFrontPrefixListId แทน 0.0.0.0/0
|
|
130
|
+
*/
|
|
131
|
+
updateAlbSecurityGroup?: boolean;
|
|
132
|
+
/**
|
|
133
|
+
* CloudFront Origin-Facing Managed Prefix List ID
|
|
134
|
+
* ใช้แทน 0.0.0.0/0 สำหรับ ALB SG rule (แนะนำสำหรับ production)
|
|
135
|
+
*
|
|
136
|
+
* ดู prefix list ID ได้จาก VPC Console → Managed Prefix Lists
|
|
137
|
+
* ชื่อ: com.amazonaws.global.cloudfront.origin-facing
|
|
138
|
+
*/
|
|
139
|
+
cloudFrontPrefixListId?: string;
|
|
140
|
+
/** Price class (default: 'PriceClass_200') */
|
|
141
|
+
priceClass?: 'PriceClass_100' | 'PriceClass_200' | 'PriceClass_All';
|
|
142
|
+
/** HTTP version (default: 'http2and3') */
|
|
143
|
+
httpVersion?: 'http1.1' | 'http2' | 'http2and3' | 'http3';
|
|
144
|
+
/** Enable/disable distribution (default: true) */
|
|
145
|
+
enabled?: boolean;
|
|
146
|
+
/** Custom error responses (e.g., SPA fallback) */
|
|
147
|
+
customErrorResponses?: CloudFrontCustomErrorResponseConfig[];
|
|
148
|
+
/** Removal policy (default: 'destroy') */
|
|
149
|
+
removalPolicy?: 'destroy' | 'retain';
|
|
150
|
+
/** Tag config name (ดู configs/tags/) */
|
|
151
|
+
tagConfigName?: string;
|
|
152
|
+
/** Additional tags */
|
|
153
|
+
tags?: Record<string, string>;
|
|
154
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CloudFront + VPC Origin Config Interface
|
|
4
|
+
*
|
|
5
|
+
* ใช้สำหรับสร้าง CloudFront Distribution ที่ชี้ไปยัง Private ALB
|
|
6
|
+
* ผ่าน VPC Origin — ไม่ต้องเปิด ALB เป็น internet-facing
|
|
7
|
+
*
|
|
8
|
+
* Architecture:
|
|
9
|
+
* Client → CloudFront (edge) → VPC Origin → Private ALB → ECS Fargate
|
|
10
|
+
*
|
|
11
|
+
* VPC Origin:
|
|
12
|
+
* CloudFront จะเชื่อมต่อ ALB ผ่าน AWS backbone โดยตรง
|
|
13
|
+
* ไม่ต้อง expose ALB ออก internet
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface EcrLifecycleRule {
|
|
2
|
+
/** Rule priority (lower = higher priority) */
|
|
3
|
+
rulePriority: number;
|
|
4
|
+
/** Rule description */
|
|
5
|
+
description: string;
|
|
6
|
+
/** Tag status: 'tagged' | 'untagged' | 'any' */
|
|
7
|
+
tagStatus: 'tagged' | 'untagged' | 'any';
|
|
8
|
+
/** Tag prefix list (required if tagStatus = 'tagged') */
|
|
9
|
+
tagPrefixList?: string[];
|
|
10
|
+
/** Maximum number of images to keep */
|
|
11
|
+
maxImageCount?: number;
|
|
12
|
+
/** Maximum age of images in days */
|
|
13
|
+
maxImageAgeDays?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface EcrConfig {
|
|
16
|
+
stackName: string;
|
|
17
|
+
repositoryName: string;
|
|
18
|
+
region?: string;
|
|
19
|
+
account?: string;
|
|
20
|
+
/** อ้างอิง Account Config name (ดู configs/accounts/) */
|
|
21
|
+
accountConfigName?: string;
|
|
22
|
+
/** Image tag mutability (default: 'MUTABLE') */
|
|
23
|
+
imageTagMutability?: 'MUTABLE' | 'IMMUTABLE';
|
|
24
|
+
/** Enable image scan on push (default: true) */
|
|
25
|
+
scanOnPush?: boolean;
|
|
26
|
+
/** Empty the repository on delete (default: true when removalPolicy = 'destroy') */
|
|
27
|
+
emptyOnDelete?: boolean;
|
|
28
|
+
/** Lifecycle rules */
|
|
29
|
+
lifecycleRules?: EcrLifecycleRule[];
|
|
30
|
+
/** Shorthand: keep last N tagged images (used if lifecycleRules not specified) */
|
|
31
|
+
lifecycleMaxImages?: number;
|
|
32
|
+
/** Shorthand: delete untagged images older than N days (used if lifecycleRules not specified) */
|
|
33
|
+
lifecycleDaysUntagged?: number;
|
|
34
|
+
/** Removal policy (default: 'destroy') */
|
|
35
|
+
removalPolicy?: 'destroy' | 'retain';
|
|
36
|
+
/** อ้างอิง Tag Config name (ดู configs/tags/) */
|
|
37
|
+
tagConfigName?: string;
|
|
38
|
+
/** Tags เสริม — merge กับ tagConfigName (override ถ้า key ซ้ำ) */
|
|
39
|
+
tags?: Record<string, string>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface EcsClusterConfig {
|
|
2
|
+
stackName: string;
|
|
3
|
+
clusterName: string;
|
|
4
|
+
region?: string;
|
|
5
|
+
account?: string;
|
|
6
|
+
/** อ้างอิง Account Config name (ดู configs/accounts/) */
|
|
7
|
+
accountConfigName?: string;
|
|
8
|
+
/** VPC stack name ที่จะสร้าง ECS Cluster */
|
|
9
|
+
source: {
|
|
10
|
+
vpcStackName: string;
|
|
11
|
+
};
|
|
12
|
+
/** Container Insights (default: true) */
|
|
13
|
+
containerInsightsEnabled?: boolean;
|
|
14
|
+
/** Enable execute command for debugging (default: false) */
|
|
15
|
+
enableExecuteCommand?: boolean;
|
|
16
|
+
/** Default capacity provider strategy */
|
|
17
|
+
capacityProviders?: ('FARGATE' | 'FARGATE_SPOT')[];
|
|
18
|
+
/** Default capacity provider strategy weights */
|
|
19
|
+
defaultCapacityProviderStrategy?: {
|
|
20
|
+
capacityProvider: 'FARGATE' | 'FARGATE_SPOT';
|
|
21
|
+
weight: number;
|
|
22
|
+
base?: number;
|
|
23
|
+
}[];
|
|
24
|
+
/** Removal policy (default: 'destroy') */
|
|
25
|
+
removalPolicy?: 'destroy' | 'retain';
|
|
26
|
+
/** อ้างอิง Tag Config name (ดู configs/tags/) */
|
|
27
|
+
tagConfigName?: string;
|
|
28
|
+
/** Tags เสริม — merge กับ tagConfigName (override ถ้า key ซ้ำ) */
|
|
29
|
+
tags?: Record<string, string>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import * as logs from 'aws-cdk-lib/aws-logs';
|
|
2
|
+
/**
|
|
3
|
+
* ECS Service Mode:
|
|
4
|
+
* - 'web': HTTP service ที่มี ALB + TargetGroup + ListenerRule
|
|
5
|
+
* - 'worker': Background service ไม่ต้อง ALB (queue processors, cron jobs)
|
|
6
|
+
*/
|
|
7
|
+
export type EcsServiceMode = 'web' | 'worker';
|
|
8
|
+
/**
|
|
9
|
+
* Custom naming for ECS resources
|
|
10
|
+
* ใช้กำหนดชื่อ resources ให้อ่านง่าย แทน auto-generated names จาก CDK
|
|
11
|
+
*/
|
|
12
|
+
export interface EcsServiceNamingConfig {
|
|
13
|
+
/** Custom Target Group name (max 32 chars, web mode only) */
|
|
14
|
+
targetGroupName?: string;
|
|
15
|
+
/** Custom Task Definition family name */
|
|
16
|
+
taskDefinitionFamily?: string;
|
|
17
|
+
/** Custom Task Role name (ignored if taskRoleArn provided) */
|
|
18
|
+
taskRoleName?: string;
|
|
19
|
+
/** Custom Execution Role name (ignored if executionRoleArn provided) */
|
|
20
|
+
executionRoleName?: string;
|
|
21
|
+
/** Custom Security Group name */
|
|
22
|
+
securityGroupName?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface EcsServiceContainerConfig {
|
|
25
|
+
/** Container / service name */
|
|
26
|
+
name: string;
|
|
27
|
+
/**
|
|
28
|
+
* Container image
|
|
29
|
+
* - ECR URI: 958563415684.dkr.ecr.ap-southeast-7.amazonaws.com/repo:tag
|
|
30
|
+
* - Docker Hub: nginx:latest
|
|
31
|
+
*/
|
|
32
|
+
image: string;
|
|
33
|
+
/** Container port (default: 80) */
|
|
34
|
+
port: number;
|
|
35
|
+
/** CPU units (256 = 0.25 vCPU) */
|
|
36
|
+
cpu: number;
|
|
37
|
+
/** Memory in MiB */
|
|
38
|
+
memory: number;
|
|
39
|
+
/** Desired task count */
|
|
40
|
+
desiredCount: number;
|
|
41
|
+
/** Ephemeral storage in GiB (default: 20, range: 21-200) */
|
|
42
|
+
ephemeralStorageGiB?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Enable init process (PID 1) inside the container.
|
|
45
|
+
* Required for ECS Exec to work properly on Fargate.
|
|
46
|
+
* Uses tini as init process for signal handling and zombie reaping.
|
|
47
|
+
* Default: true (when enableExecuteCommand is true)
|
|
48
|
+
*/
|
|
49
|
+
initProcessEnabled?: boolean;
|
|
50
|
+
/** Command override for the container entrypoint */
|
|
51
|
+
command?: string[];
|
|
52
|
+
/** Environment variables */
|
|
53
|
+
environmentVariables?: Record<string, string>;
|
|
54
|
+
/**
|
|
55
|
+
* Secrets from AWS Secrets Manager
|
|
56
|
+
* Key = env var name in container
|
|
57
|
+
* Value = full ARN of the secret, optionally with JSON field:
|
|
58
|
+
* - Plain secret: 'arn:aws:secretsmanager:region:account:secret:name-suffix'
|
|
59
|
+
* - JSON field: 'arn:aws:secretsmanager:region:account:secret:name-suffix:fieldName'
|
|
60
|
+
*
|
|
61
|
+
* Example:
|
|
62
|
+
* ```
|
|
63
|
+
* secrets: {
|
|
64
|
+
* DB_PASSWORD: 'arn:aws:secretsmanager:ap-southeast-7:123456:secret:db-creds-AbCdEf:password',
|
|
65
|
+
* API_KEY: 'arn:aws:secretsmanager:ap-southeast-7:123456:secret:api-key-XyZwVu',
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
secrets?: Record<string, string>;
|
|
70
|
+
}
|
|
71
|
+
export interface EcsServiceRoutingConfig {
|
|
72
|
+
/** Host header condition (e.g., 'app.example.com', ไม่ใส่ = match ทุก domain) */
|
|
73
|
+
domainName?: string;
|
|
74
|
+
/** Path pattern (e.g., '/api/*') */
|
|
75
|
+
pathPattern: string;
|
|
76
|
+
/** Listener rule priority (ต้อง unique ต่อ listener) */
|
|
77
|
+
priority: number;
|
|
78
|
+
/** Health check path */
|
|
79
|
+
healthCheckPath: string;
|
|
80
|
+
/** Health check interval in seconds (default: 30) */
|
|
81
|
+
healthCheckInterval?: number;
|
|
82
|
+
/** Health check timeout in seconds (default: 5) */
|
|
83
|
+
healthCheckTimeout?: number;
|
|
84
|
+
/** Healthy threshold count (default: 2) */
|
|
85
|
+
healthyThresholdCount?: number;
|
|
86
|
+
/** Unhealthy threshold count (default: 3) */
|
|
87
|
+
unhealthyThresholdCount?: number;
|
|
88
|
+
/** Deregistration delay in seconds (default: 30) */
|
|
89
|
+
deregistrationDelay?: number;
|
|
90
|
+
}
|
|
91
|
+
export interface EcsServiceLogConfig {
|
|
92
|
+
/** Log retention (default: ONE_WEEK) */
|
|
93
|
+
retention?: logs.RetentionDays;
|
|
94
|
+
/** Log group removal policy (default: DESTROY) */
|
|
95
|
+
removalPolicy?: 'destroy' | 'retain';
|
|
96
|
+
}
|
|
97
|
+
export interface EcsServiceSecurityGroupConfig {
|
|
98
|
+
/** Allow all TCP ports from ALB SG (default: true, ignored for worker) */
|
|
99
|
+
allowAllFromAlb?: boolean;
|
|
100
|
+
/** Additional Security Group IDs to allow all TCP from */
|
|
101
|
+
additionalSourceSgIds?: string[];
|
|
102
|
+
/** Additional CIDRs to allow inbound traffic */
|
|
103
|
+
allowFromCidrs?: string[];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* IAM policy statement สำหรับ Task Role
|
|
107
|
+
* ใช้กรณีต้องการสร้าง inline policy ให้ Task Role อัตโนมัติ
|
|
108
|
+
*/
|
|
109
|
+
export interface EcsServicePolicyStatement {
|
|
110
|
+
/** Policy effect (default: 'Allow') */
|
|
111
|
+
effect?: 'Allow' | 'Deny';
|
|
112
|
+
/** Actions e.g., ['s3:GetObject', 'sqs:SendMessage'] */
|
|
113
|
+
actions: string[];
|
|
114
|
+
/** Resources e.g., ['arn:aws:s3:::my-bucket/*'] ใช้ ['*'] สำหรับ all resources */
|
|
115
|
+
resources: string[];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Preset policy names สำหรับ Task Role
|
|
119
|
+
* ใช้ AWS Managed Policies เป็นหลัก, fallback เป็น inline สำหรับ services ที่ไม่มี managed policy
|
|
120
|
+
*
|
|
121
|
+
* Task Role Presets (AWS Managed Policies):
|
|
122
|
+
* - 'ssm-parameters' : AmazonSSMReadOnlyAccess
|
|
123
|
+
* - 'sqs' : AmazonSQSFullAccess
|
|
124
|
+
* - 'sns' : AmazonSNSFullAccess
|
|
125
|
+
* - 's3-read' : AmazonS3ReadOnlyAccess
|
|
126
|
+
* - 's3-full' : AmazonS3FullAccess
|
|
127
|
+
* - 'dynamodb' : AmazonDynamoDBFullAccess
|
|
128
|
+
* - 'ses' : AmazonSESFullAccess
|
|
129
|
+
* - 'xray' : AWSXRayDaemonWriteAccess
|
|
130
|
+
* - 'cloudwatch-metrics' : CloudWatchAgentServerPolicy
|
|
131
|
+
* - 'bedrock' : AmazonBedrockFullAccess
|
|
132
|
+
*
|
|
133
|
+
* Task Role Presets (Inline Policies):
|
|
134
|
+
* - 'secrets-manager' : GetSecretValue, DescribeSecret (read-only)
|
|
135
|
+
* - 'rds-connect' : rds-db:connect (IAM authentication)
|
|
136
|
+
* - 'elasticache' : elasticache:Connect, Describe* (IAM auth + discovery)
|
|
137
|
+
* - 'ecs-exec' : ssmmessages:* (ECS Exec debugging)
|
|
138
|
+
* - 'kms' : Decrypt, GenerateDataKey (encryption)
|
|
139
|
+
*
|
|
140
|
+
* Execution Role Presets (Inline Policies):
|
|
141
|
+
* - 'exec-secrets-injection' : secretsmanager:GetSecretValue (inject secrets ตอน container start)
|
|
142
|
+
* - 'exec-ssm-injection' : ssm:GetParameters (inject SSM params ตอน container start)
|
|
143
|
+
* - 'exec-kms' : kms:Decrypt (decrypt secrets/params ที่เข้ารหัสด้วย KMS)
|
|
144
|
+
*/
|
|
145
|
+
export type TaskRolePresetPolicy = 'secrets-manager' | 'ssm-parameters' | 'sqs' | 'sns' | 's3-read' | 's3-full' | 'dynamodb' | 'rds-connect' | 'ses' | 'xray' | 'ecs-exec' | 'cloudwatch-metrics' | 'bedrock' | 'kms' | 'efs' | 'elasticache';
|
|
146
|
+
export type ExecutionRolePresetPolicy = 'exec-secrets-injection' | 'exec-ssm-injection' | 'exec-kms';
|
|
147
|
+
export interface EcsServiceIamConfig {
|
|
148
|
+
/**
|
|
149
|
+
* Task Role - role ที่ container ใช้ขณะ runtime
|
|
150
|
+
* - ไม่ระบุ: CDK auto-create empty role
|
|
151
|
+
* - ระบุ ARN: import existing role (ไม่สร้างใหม่)
|
|
152
|
+
*/
|
|
153
|
+
taskRoleArn?: string;
|
|
154
|
+
/**
|
|
155
|
+
* Task Execution Role - role ที่ ECS agent ใช้ (pull image, write logs)
|
|
156
|
+
* - ไม่ระบุ: CDK auto-create with AmazonECSTaskExecutionRolePolicy
|
|
157
|
+
* - ระบุ ARN: import existing role (ไม่สร้างใหม่)
|
|
158
|
+
*/
|
|
159
|
+
executionRoleArn?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Preset policies สำหรับ Task Role
|
|
162
|
+
* เลือก preset ที่ต้องการ CDK จะสร้าง role + policies ให้อัตโนมัติ
|
|
163
|
+
* (ถูก ignore ถ้าระบุ taskRoleArn)
|
|
164
|
+
*/
|
|
165
|
+
taskRolePresets?: TaskRolePresetPolicy[];
|
|
166
|
+
/**
|
|
167
|
+
* Preset policies สำหรับ Execution Role
|
|
168
|
+
* เพิ่มเติมจาก AmazonECSTaskExecutionRolePolicy ที่ CDK ให้มาแล้ว
|
|
169
|
+
* (ถูก ignore ถ้าระบุ executionRoleArn)
|
|
170
|
+
*/
|
|
171
|
+
executionRolePresets?: ExecutionRolePresetPolicy[];
|
|
172
|
+
/**
|
|
173
|
+
* Inline policies สำหรับ Task Role (ใช้เมื่อไม่ได้ระบุ taskRoleArn)
|
|
174
|
+
* ใช้ร่วมกับ presets ได้ — CDK จะรวม policies ทั้งหมด
|
|
175
|
+
*/
|
|
176
|
+
taskRolePolicies?: EcsServicePolicyStatement[];
|
|
177
|
+
/**
|
|
178
|
+
* AWS Managed Policy ARNs สำหรับ Task Role
|
|
179
|
+
* e.g., ['arn:aws:iam::aws:policy/AmazonS3ReadOnlyAccess']
|
|
180
|
+
*/
|
|
181
|
+
taskRoleManagedPolicyArns?: string[];
|
|
182
|
+
}
|
|
183
|
+
export interface EcsServiceSource {
|
|
184
|
+
/** VPC stack name */
|
|
185
|
+
vpcStackName: string;
|
|
186
|
+
/** Subnet name for service tasks (default: 'private') */
|
|
187
|
+
subnetName?: string;
|
|
188
|
+
/** ECS Cluster stack name */
|
|
189
|
+
ecsClusterStackName: string;
|
|
190
|
+
/** ALB stack name (required for web mode, omit for worker) */
|
|
191
|
+
albStackName?: string;
|
|
192
|
+
/** EFS stack name - เปิด NFS ingress ที่ EFS SG ให้ ECS SG เข้าถึง (optional) */
|
|
193
|
+
efsStackName?: string;
|
|
194
|
+
/** RDS stack name - เปิด DB ingress ที่ RDS SG ให้ ECS SG เข้าถึง (optional) */
|
|
195
|
+
rdsStackName?: string;
|
|
196
|
+
/** ElastiCache stack name - เปิด Redis ingress ที่ Redis SG ให้ ECS SG เข้าถึง (optional) */
|
|
197
|
+
elastiCacheStackName?: string;
|
|
198
|
+
}
|
|
199
|
+
export interface EcsServiceConfig {
|
|
200
|
+
stackName: string;
|
|
201
|
+
region?: string;
|
|
202
|
+
account?: string;
|
|
203
|
+
/** อ้างอิง Account Config name (ดู configs/accounts/) */
|
|
204
|
+
accountConfigName?: string;
|
|
205
|
+
/** Service mode: 'web' or 'worker' (default: 'web') */
|
|
206
|
+
serviceMode?: EcsServiceMode;
|
|
207
|
+
/** Source stack references (vpcRef mode) */
|
|
208
|
+
source: EcsServiceSource;
|
|
209
|
+
/** Custom naming for resources (optional) */
|
|
210
|
+
naming?: EcsServiceNamingConfig;
|
|
211
|
+
/** Container configuration */
|
|
212
|
+
container: EcsServiceContainerConfig;
|
|
213
|
+
/** Routing configuration (required for web mode) */
|
|
214
|
+
routing?: EcsServiceRoutingConfig;
|
|
215
|
+
/** Logging configuration */
|
|
216
|
+
logging?: EcsServiceLogConfig;
|
|
217
|
+
/** Security group configuration */
|
|
218
|
+
securityGroup?: EcsServiceSecurityGroupConfig;
|
|
219
|
+
/** IAM role configuration (optional, CDK auto-create if not specified) */
|
|
220
|
+
iam?: EcsServiceIamConfig;
|
|
221
|
+
/** Enable ECS Exec for debugging (default: true) */
|
|
222
|
+
enableExecuteCommand?: boolean;
|
|
223
|
+
/** Circuit breaker with rollback (default: true) */
|
|
224
|
+
circuitBreakerEnabled?: boolean;
|
|
225
|
+
/** Min healthy percent during deployment (default: 50) */
|
|
226
|
+
minHealthyPercent?: number;
|
|
227
|
+
/** Max healthy percent during deployment (default: 200) */
|
|
228
|
+
maxHealthyPercent?: number;
|
|
229
|
+
/** Assign public IP to tasks (default: false) */
|
|
230
|
+
assignPublicIp?: boolean;
|
|
231
|
+
/** Removal policy (default: 'destroy') */
|
|
232
|
+
removalPolicy?: 'destroy' | 'retain';
|
|
233
|
+
/** อ้างอิง Tag Config name (ดู configs/tags/) */
|
|
234
|
+
tagConfigName?: string;
|
|
235
|
+
/** Tags เสริม — merge กับ tagConfigName (override ถ้า key ซ้ำ) */
|
|
236
|
+
tags?: Record<string, string>;
|
|
237
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EFS Configuration Interface
|
|
3
|
+
*
|
|
4
|
+
* สำหรับสร้าง Elastic File System สำหรับ ECS Fargate
|
|
5
|
+
*/
|
|
6
|
+
export interface EfsAccessPointConfig {
|
|
7
|
+
/** Access Point name */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Path in EFS */
|
|
10
|
+
path: string;
|
|
11
|
+
/** POSIX User ID (default: 33 for www-data) */
|
|
12
|
+
posixUid?: number;
|
|
13
|
+
/** POSIX Group ID (default: 33 for www-data) */
|
|
14
|
+
posixGid?: number;
|
|
15
|
+
/** Directory permissions (default: '755') */
|
|
16
|
+
permissions?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface EfsVpcRefSource {
|
|
19
|
+
vpcStackName: string;
|
|
20
|
+
/** ใช้ subnet ชื่ออะไรสำหรับ mount targets (default: 'private-ecs') */
|
|
21
|
+
subnetName?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface EfsConfig {
|
|
24
|
+
stackName: string;
|
|
25
|
+
fileSystemName: string;
|
|
26
|
+
region?: string;
|
|
27
|
+
account?: string;
|
|
28
|
+
/** อ้างอิง Account Config name (ดู configs/accounts/) */
|
|
29
|
+
accountConfigName?: string;
|
|
30
|
+
/** VPC source - อ้างอิง VPC stack */
|
|
31
|
+
source: EfsVpcRefSource;
|
|
32
|
+
/** Custom Security Group name (optional) */
|
|
33
|
+
securityGroupName?: string;
|
|
34
|
+
/** Performance mode (default: 'generalPurpose') */
|
|
35
|
+
performanceMode?: 'generalPurpose' | 'maxIO';
|
|
36
|
+
/** Throughput mode (default: 'bursting') */
|
|
37
|
+
throughputMode?: 'bursting' | 'provisioned' | 'elastic';
|
|
38
|
+
/** Provisioned throughput in MiB/s (required if throughputMode is 'provisioned') */
|
|
39
|
+
provisionedThroughput?: number;
|
|
40
|
+
/** Enable encryption at rest (default: true) */
|
|
41
|
+
encrypted?: boolean;
|
|
42
|
+
/** KMS key ARN for encryption (optional, uses AWS managed key if not specified) */
|
|
43
|
+
kmsKeyArn?: string;
|
|
44
|
+
/** Lifecycle policy - transition to IA after N days (default: 30) */
|
|
45
|
+
transitionToIaAfterDays?: number;
|
|
46
|
+
/** Lifecycle policy - transition to primary storage after N accesses (optional) */
|
|
47
|
+
transitionToPrimaryStorageAfterAccesses?: number;
|
|
48
|
+
/** Access points to create */
|
|
49
|
+
accessPoints?: EfsAccessPointConfig[];
|
|
50
|
+
/** Removal policy (default: 'retain' for data safety) */
|
|
51
|
+
removalPolicy?: 'destroy' | 'retain';
|
|
52
|
+
/** อ้างอิง Tag Config name (ดู configs/tags/) */
|
|
53
|
+
tagConfigName?: string;
|
|
54
|
+
/** Tags เสริม — merge กับ tagConfigName (override ถ้า key ซ้ำ) */
|
|
55
|
+
tags?: Record<string, string>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ElastiCache Redis Configuration Interface
|
|
3
|
+
*
|
|
4
|
+
* สำหรับสร้าง ElastiCache Redis Replication Group
|
|
5
|
+
*/
|
|
6
|
+
export interface ElastiCacheVpcRefSource {
|
|
7
|
+
vpcStackName: string;
|
|
8
|
+
/** ใช้ subnet ชื่ออะไร (default: 'cache') */
|
|
9
|
+
subnetName?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ElastiCacheConfig {
|
|
12
|
+
stackName: string;
|
|
13
|
+
clusterName: string;
|
|
14
|
+
region?: string;
|
|
15
|
+
account?: string;
|
|
16
|
+
/** อ้างอิง Account Config name (ดู configs/accounts/) */
|
|
17
|
+
accountConfigName?: string;
|
|
18
|
+
/** VPC source - อ้างอิง VPC stack */
|
|
19
|
+
source: ElastiCacheVpcRefSource;
|
|
20
|
+
/** Custom Security Group name (optional) */
|
|
21
|
+
securityGroupName?: string;
|
|
22
|
+
/** Redis engine version (default: '7.0') */
|
|
23
|
+
engineVersion?: string;
|
|
24
|
+
/** Node type (default: 'cache.t3.micro') */
|
|
25
|
+
nodeType?: string;
|
|
26
|
+
/** Number of cache clusters/nodes (default: 2 for Multi-AZ) */
|
|
27
|
+
numCacheClusters?: number;
|
|
28
|
+
/** Enable Multi-AZ (default: true) */
|
|
29
|
+
multiAzEnabled?: boolean;
|
|
30
|
+
/** Enable automatic failover (default: true) */
|
|
31
|
+
automaticFailoverEnabled?: boolean;
|
|
32
|
+
/** Enable encryption at rest (default: true) */
|
|
33
|
+
atRestEncryptionEnabled?: boolean;
|
|
34
|
+
/** Enable encryption in transit (default: true) */
|
|
35
|
+
transitEncryptionEnabled?: boolean;
|
|
36
|
+
/** Auth token from Secrets Manager ARN (optional) */
|
|
37
|
+
authTokenSecretArn?: string;
|
|
38
|
+
/** Snapshot retention limit in days (default: 5) */
|
|
39
|
+
snapshotRetentionLimit?: number;
|
|
40
|
+
/** Snapshot window (default: '03:00-05:00') */
|
|
41
|
+
snapshotWindow?: string;
|
|
42
|
+
/** Maintenance window (default: 'sun:05:00-sun:07:00') */
|
|
43
|
+
maintenanceWindow?: string;
|
|
44
|
+
/** Port (default: 6379) */
|
|
45
|
+
port?: number;
|
|
46
|
+
/** Parameter group family (default: 'redis7') */
|
|
47
|
+
parameterGroupFamily?: string;
|
|
48
|
+
/** Custom parameters */
|
|
49
|
+
parameters?: Record<string, string>;
|
|
50
|
+
/** Removal policy (default: 'retain' for data safety) */
|
|
51
|
+
removalPolicy?: 'destroy' | 'retain';
|
|
52
|
+
/** อ้างอิง Tag Config name (ดู configs/tags/) */
|
|
53
|
+
tagConfigName?: string;
|
|
54
|
+
/** Tags เสริม — merge กับ tagConfigName (override ถ้า key ซ้ำ) */
|
|
55
|
+
tags?: Record<string, string>;
|
|
56
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { NaclRuleConfig, NaclConfig } from '../constructs/nacl';
|