create-chaaskit 0.1.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/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +25 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/add-infra.d.ts +6 -0
- package/dist/commands/add-infra.d.ts.map +1 -0
- package/dist/commands/add-infra.js +160 -0
- package/dist/commands/add-infra.js.map +1 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.d.ts.map +1 -0
- package/dist/commands/build.js +63 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/db-sync.d.ts +13 -0
- package/dist/commands/db-sync.d.ts.map +1 -0
- package/dist/commands/db-sync.js +108 -0
- package/dist/commands/db-sync.js.map +1 -0
- package/dist/commands/dev.d.ts +7 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +61 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/init.d.ts +9 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +214 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +57 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/.env.example +24 -0
- package/dist/templates/README.md +81 -0
- package/dist/templates/app/components/AcceptInviteClient.tsx +10 -0
- package/dist/templates/app/components/AdminDashboardClient.tsx +10 -0
- package/dist/templates/app/components/AdminTeamClient.tsx +10 -0
- package/dist/templates/app/components/AdminTeamsClient.tsx +10 -0
- package/dist/templates/app/components/AdminUsersClient.tsx +10 -0
- package/dist/templates/app/components/ApiKeysClient.tsx +10 -0
- package/dist/templates/app/components/AutomationsClient.tsx +10 -0
- package/dist/templates/app/components/ChatClient.tsx +13 -0
- package/dist/templates/app/components/ClientOnly.tsx +6 -0
- package/dist/templates/app/components/DocumentsClient.tsx +10 -0
- package/dist/templates/app/components/OAuthConsentClient.tsx +10 -0
- package/dist/templates/app/components/PricingClient.tsx +10 -0
- package/dist/templates/app/components/TeamSettingsClient.tsx +10 -0
- package/dist/templates/app/components/VerifyEmailClient.tsx +10 -0
- package/dist/templates/app/entry.client.tsx +12 -0
- package/dist/templates/app/entry.server.tsx +67 -0
- package/dist/templates/app/root.tsx +91 -0
- package/dist/templates/app/routes/_index.tsx +82 -0
- package/dist/templates/app/routes/admin._index.tsx +57 -0
- package/dist/templates/app/routes/admin.teams.$teamId.tsx +57 -0
- package/dist/templates/app/routes/admin.teams._index.tsx +57 -0
- package/dist/templates/app/routes/admin.users.tsx +57 -0
- package/dist/templates/app/routes/api-keys.tsx +57 -0
- package/dist/templates/app/routes/automations.tsx +57 -0
- package/dist/templates/app/routes/chat._index.tsx +11 -0
- package/dist/templates/app/routes/chat.admin._index.tsx +10 -0
- package/dist/templates/app/routes/chat.admin.teams.$teamId.tsx +10 -0
- package/dist/templates/app/routes/chat.admin.teams._index.tsx +10 -0
- package/dist/templates/app/routes/chat.admin.users.tsx +10 -0
- package/dist/templates/app/routes/chat.api-keys.tsx +10 -0
- package/dist/templates/app/routes/chat.automations.tsx +10 -0
- package/dist/templates/app/routes/chat.documents.tsx +10 -0
- package/dist/templates/app/routes/chat.team.$teamId.settings.tsx +10 -0
- package/dist/templates/app/routes/chat.thread.$threadId.tsx +11 -0
- package/dist/templates/app/routes/chat.tsx +39 -0
- package/dist/templates/app/routes/documents.tsx +57 -0
- package/dist/templates/app/routes/invite.$token.tsx +10 -0
- package/dist/templates/app/routes/login.tsx +334 -0
- package/dist/templates/app/routes/oauth.consent.tsx +10 -0
- package/dist/templates/app/routes/pricing.tsx +10 -0
- package/dist/templates/app/routes/privacy.tsx +197 -0
- package/dist/templates/app/routes/register.tsx +398 -0
- package/dist/templates/app/routes/shared.$shareId.tsx +226 -0
- package/dist/templates/app/routes/team.$teamId.settings.tsx +57 -0
- package/dist/templates/app/routes/terms.tsx +173 -0
- package/dist/templates/app/routes/thread.$threadId.tsx +102 -0
- package/dist/templates/app/routes/verify-email.tsx +10 -0
- package/dist/templates/app/routes.ts +47 -0
- package/dist/templates/config/app.config.ts +216 -0
- package/dist/templates/docs/admin.md +257 -0
- package/dist/templates/docs/api-keys.md +403 -0
- package/dist/templates/docs/authentication.md +247 -0
- package/dist/templates/docs/configuration.md +1212 -0
- package/dist/templates/docs/custom-pages.md +466 -0
- package/dist/templates/docs/deployment.md +362 -0
- package/dist/templates/docs/development.md +411 -0
- package/dist/templates/docs/documents.md +293 -0
- package/dist/templates/docs/extensions.md +639 -0
- package/dist/templates/docs/index.md +139 -0
- package/dist/templates/docs/installation.md +286 -0
- package/dist/templates/docs/mcp.md +952 -0
- package/dist/templates/docs/native-tools.md +688 -0
- package/dist/templates/docs/queue.md +514 -0
- package/dist/templates/docs/scheduled-prompts.md +279 -0
- package/dist/templates/docs/settings.md +415 -0
- package/dist/templates/docs/slack.md +318 -0
- package/dist/templates/docs/styling.md +288 -0
- package/dist/templates/extensions/agents/.gitkeep +0 -0
- package/dist/templates/extensions/pages/.gitkeep +0 -0
- package/dist/templates/extensions/payment-plans/.gitkeep +0 -0
- package/dist/templates/index.html +16 -0
- package/dist/templates/infra-aws/.github/workflows/deploy.yml +95 -0
- package/dist/templates/infra-aws/README.md +207 -0
- package/dist/templates/infra-aws/bin/cdk.ts +18 -0
- package/dist/templates/infra-aws/cdk.json +43 -0
- package/dist/templates/infra-aws/config/deployment.ts +156 -0
- package/dist/templates/infra-aws/lib/chaaskit-stack.ts +419 -0
- package/dist/templates/infra-aws/package.json +27 -0
- package/dist/templates/infra-aws/scripts/build-app.sh +63 -0
- package/dist/templates/infra-aws/tsconfig.json +25 -0
- package/dist/templates/package.json +46 -0
- package/dist/templates/prisma/schema/base.prisma +584 -0
- package/dist/templates/prisma/schema/custom.prisma +24 -0
- package/dist/templates/prisma/schema.prisma +271 -0
- package/dist/templates/public/favicon.svg +4 -0
- package/dist/templates/public/logo.svg +4 -0
- package/dist/templates/react-router.config.ts +11 -0
- package/dist/templates/server.js +52 -0
- package/dist/templates/src/main.tsx +8 -0
- package/dist/templates/tsconfig.json +26 -0
- package/dist/templates/vite.config.ts +26 -0
- package/package.json +46 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
name: Deploy to AWS
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
inputs:
|
|
8
|
+
stage:
|
|
9
|
+
description: 'Deployment stage'
|
|
10
|
+
required: true
|
|
11
|
+
default: 'prod'
|
|
12
|
+
type: choice
|
|
13
|
+
options:
|
|
14
|
+
- staging
|
|
15
|
+
- prod
|
|
16
|
+
|
|
17
|
+
env:
|
|
18
|
+
AWS_REGION: us-west-2
|
|
19
|
+
SERVICE_NAME: {{SERVICE_NAME}}
|
|
20
|
+
|
|
21
|
+
jobs:
|
|
22
|
+
deploy:
|
|
23
|
+
name: Deploy to AWS Elastic Beanstalk
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
|
|
26
|
+
permissions:
|
|
27
|
+
contents: read
|
|
28
|
+
id-token: write
|
|
29
|
+
|
|
30
|
+
steps:
|
|
31
|
+
- name: Checkout code
|
|
32
|
+
uses: actions/checkout@v4
|
|
33
|
+
|
|
34
|
+
- name: Setup Node.js
|
|
35
|
+
uses: actions/setup-node@v4
|
|
36
|
+
with:
|
|
37
|
+
node-version: '22'
|
|
38
|
+
|
|
39
|
+
- name: Setup pnpm
|
|
40
|
+
uses: pnpm/action-setup@v4
|
|
41
|
+
with:
|
|
42
|
+
version: 9
|
|
43
|
+
|
|
44
|
+
- name: Get pnpm store directory
|
|
45
|
+
shell: bash
|
|
46
|
+
run: |
|
|
47
|
+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
|
|
48
|
+
|
|
49
|
+
- name: Setup pnpm cache
|
|
50
|
+
uses: actions/cache@v4
|
|
51
|
+
with:
|
|
52
|
+
path: ${{ env.STORE_PATH }}
|
|
53
|
+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
54
|
+
restore-keys: |
|
|
55
|
+
${{ runner.os }}-pnpm-store-
|
|
56
|
+
|
|
57
|
+
- name: Install dependencies
|
|
58
|
+
run: pnpm install --frozen-lockfile
|
|
59
|
+
|
|
60
|
+
- name: Build application
|
|
61
|
+
run: |
|
|
62
|
+
pnpm build
|
|
63
|
+
pnpm db:generate
|
|
64
|
+
|
|
65
|
+
- name: Package for Elastic Beanstalk
|
|
66
|
+
run: |
|
|
67
|
+
export BUILD_VERSION=${{ github.sha }}
|
|
68
|
+
cd cdk && chmod +x ./scripts/build-app.sh && ./scripts/build-app.sh
|
|
69
|
+
|
|
70
|
+
- name: Configure AWS credentials
|
|
71
|
+
uses: aws-actions/configure-aws-credentials@v4
|
|
72
|
+
with:
|
|
73
|
+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
74
|
+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
75
|
+
aws-region: ${{ env.AWS_REGION }}
|
|
76
|
+
|
|
77
|
+
- name: Install CDK dependencies
|
|
78
|
+
run: |
|
|
79
|
+
cd cdk
|
|
80
|
+
npm install
|
|
81
|
+
|
|
82
|
+
- name: Deploy CDK Stack
|
|
83
|
+
run: |
|
|
84
|
+
cd cdk
|
|
85
|
+
npx cdk deploy --require-approval never
|
|
86
|
+
env:
|
|
87
|
+
STAGE: ${{ inputs.stage || 'prod' }}
|
|
88
|
+
BUILD_VERSION: ${{ github.sha }}
|
|
89
|
+
|
|
90
|
+
- name: Get deployment URL
|
|
91
|
+
if: success()
|
|
92
|
+
run: |
|
|
93
|
+
STAGE=${{ inputs.stage || 'prod' }}
|
|
94
|
+
echo "Deployment complete!"
|
|
95
|
+
echo "Check your application at the Elastic Beanstalk environment URL"
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# AWS CDK Infrastructure
|
|
2
|
+
|
|
3
|
+
This directory contains AWS CDK infrastructure code for deploying your ChaasKit application to AWS Elastic Beanstalk with RDS PostgreSQL.
|
|
4
|
+
|
|
5
|
+
## Architecture
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
9
|
+
│ AWS Cloud │
|
|
10
|
+
│ ┌───────────────────────────────────────────────────────┐ │
|
|
11
|
+
│ │ VPC │ │
|
|
12
|
+
│ │ ┌─────────────┐ ┌─────────────────────────────┐ │ │
|
|
13
|
+
│ │ │ Public │ │ Private Subnet │ │ │
|
|
14
|
+
│ │ │ Subnet │ │ ┌─────────────────────┐ │ │ │
|
|
15
|
+
│ │ │ ┌───────┐ │ │ │ Elastic Beanstalk │ │ │ │
|
|
16
|
+
│ │ │ │ ALB │──┼─────┼──│ Node.js 22 │ │ │ │
|
|
17
|
+
│ │ │ └───────┘ │ │ └─────────┬───────────┘ │ │ │
|
|
18
|
+
│ │ └─────────────┘ │ │ │ │ │
|
|
19
|
+
│ │ │ ┌─────────▼───────────┐ │ │ │
|
|
20
|
+
│ │ │ │ RDS PostgreSQL 16 │ │ │ │
|
|
21
|
+
│ │ │ └─────────────────────┘ │ │ │
|
|
22
|
+
│ │ └─────────────────────────────┘ │ │
|
|
23
|
+
│ └───────────────────────────────────────────────────────┘ │
|
|
24
|
+
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
|
|
25
|
+
│ │ ACM (SSL) │ │ Secrets Mgr │ │ S3 (Assets) │ │
|
|
26
|
+
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
|
|
27
|
+
└─────────────────────────────────────────────────────────────┘
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Prerequisites
|
|
31
|
+
|
|
32
|
+
1. **AWS CLI** configured with appropriate credentials
|
|
33
|
+
2. **Node.js 20+** and npm
|
|
34
|
+
3. **AWS CDK CLI**: `npm install -g aws-cdk`
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
### 1. Configure Deployment
|
|
39
|
+
|
|
40
|
+
Edit `config/deployment.ts` with your settings:
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
export const config: DeploymentConfig = {
|
|
44
|
+
serviceName: 'my-app',
|
|
45
|
+
region: 'us-west-2',
|
|
46
|
+
balancerType: 'load_balancer', // or 'single_instance' for dev
|
|
47
|
+
instanceType: 't4g.small',
|
|
48
|
+
maxInstances: 2,
|
|
49
|
+
};
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. Install Dependencies
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
cd cdk
|
|
56
|
+
npm install
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### 3. Bootstrap CDK (First Time Only)
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
npx cdk bootstrap aws://YOUR_ACCOUNT_ID/us-west-2
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 4. Deploy
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm run deploy
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
This will:
|
|
72
|
+
1. Build your ChaasKit app
|
|
73
|
+
2. Package it for Elastic Beanstalk
|
|
74
|
+
3. Deploy all infrastructure
|
|
75
|
+
|
|
76
|
+
## Configuration Options
|
|
77
|
+
|
|
78
|
+
| Option | Description | Default |
|
|
79
|
+
|--------|-------------|---------|
|
|
80
|
+
| `serviceName` | Name for AWS resources | Required |
|
|
81
|
+
| `region` | AWS region | `us-west-2` |
|
|
82
|
+
| `balancerType` | `load_balancer` or `single_instance` | `load_balancer` |
|
|
83
|
+
| `instanceType` | EC2 instance type | `t4g.small` |
|
|
84
|
+
| `maxInstances` | Max auto-scaling instances | `2` |
|
|
85
|
+
| `dbInstanceSize` | RDS instance size | `MICRO` |
|
|
86
|
+
| `domainName` | Custom domain (optional) | - |
|
|
87
|
+
| `certificateArn` | ACM cert ARN for HTTPS | - |
|
|
88
|
+
|
|
89
|
+
## Environment Variables
|
|
90
|
+
|
|
91
|
+
The following environment variables are automatically configured:
|
|
92
|
+
|
|
93
|
+
- `NODE_ENV=production`
|
|
94
|
+
- `PORT=8080`
|
|
95
|
+
- `INTERNAL_S3_BUCKET` - S3 bucket for file storage
|
|
96
|
+
- `DB_SECRET_ARN` - ARN of the database credentials secret
|
|
97
|
+
- `AWS_REGION` - Deployment region
|
|
98
|
+
|
|
99
|
+
### Setting Application Secrets
|
|
100
|
+
|
|
101
|
+
After deployment, add your application secrets (API keys, etc.) via the AWS Console or CLI:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
# Via AWS Console:
|
|
105
|
+
# 1. Go to Elastic Beanstalk > Your Environment > Configuration
|
|
106
|
+
# 2. Edit "Software" section
|
|
107
|
+
# 3. Add environment variables
|
|
108
|
+
|
|
109
|
+
# Or via AWS CLI:
|
|
110
|
+
aws elasticbeanstalk update-environment \
|
|
111
|
+
--environment-name my-app-prod \
|
|
112
|
+
--option-settings \
|
|
113
|
+
Namespace=aws:elasticbeanstalk:application:environment,OptionName=OPENAI_API_KEY,Value=sk-xxx \
|
|
114
|
+
Namespace=aws:elasticbeanstalk:application:environment,OptionName=AUTH_SECRET,Value=your-secret
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Database Connection
|
|
118
|
+
|
|
119
|
+
The app reads database credentials from AWS Secrets Manager. The `DB_SECRET_ARN` environment variable contains the secret ARN.
|
|
120
|
+
|
|
121
|
+
Your app should fetch the secret at startup:
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { SecretsManager } from '@aws-sdk/client-secrets-manager';
|
|
125
|
+
|
|
126
|
+
async function getDatabaseUrl(): Promise<string> {
|
|
127
|
+
const client = new SecretsManager({ region: process.env.AWS_REGION });
|
|
128
|
+
const secret = await client.getSecretValue({ SecretId: process.env.DB_SECRET_ARN });
|
|
129
|
+
const credentials = JSON.parse(secret.SecretString!);
|
|
130
|
+
|
|
131
|
+
return `postgresql://${credentials.username}:${credentials.password}@${credentials.host}:${credentials.port}/${credentials.dbname}`;
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Custom Domain Setup
|
|
136
|
+
|
|
137
|
+
1. **Create ACM Certificate** in AWS Certificate Manager (must be in the same region)
|
|
138
|
+
2. **Update config/deployment.ts**:
|
|
139
|
+
```typescript
|
|
140
|
+
domainName: 'app.example.com',
|
|
141
|
+
certificateArn: 'arn:aws:acm:us-west-2:123456789:certificate/xxx',
|
|
142
|
+
```
|
|
143
|
+
3. **Create Route 53 record** pointing to the ALB
|
|
144
|
+
|
|
145
|
+
## Staging vs Production
|
|
146
|
+
|
|
147
|
+
Deploy to different stages:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
# Staging
|
|
151
|
+
STAGE=staging npm run deploy
|
|
152
|
+
|
|
153
|
+
# Production (default)
|
|
154
|
+
STAGE=prod npm run deploy
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Each stage creates isolated resources (VPC, RDS, etc.).
|
|
158
|
+
|
|
159
|
+
## CI/CD with GitHub Actions
|
|
160
|
+
|
|
161
|
+
A GitHub Actions workflow is included at `.github/workflows/deploy.yml`.
|
|
162
|
+
|
|
163
|
+
Required GitHub Secrets:
|
|
164
|
+
- `AWS_ACCESS_KEY_ID`
|
|
165
|
+
- `AWS_SECRET_ACCESS_KEY`
|
|
166
|
+
|
|
167
|
+
## Cost Estimation
|
|
168
|
+
|
|
169
|
+
Approximate monthly costs (us-west-2):
|
|
170
|
+
|
|
171
|
+
| Component | Single Instance | Load Balanced |
|
|
172
|
+
|-----------|-----------------|---------------|
|
|
173
|
+
| EC2 (t4g.small) | ~$12 | ~$24 |
|
|
174
|
+
| RDS (db.t4g.micro) | ~$13 | ~$13 |
|
|
175
|
+
| ALB | $0 | ~$18 |
|
|
176
|
+
| NAT Gateway | $0 | ~$32 |
|
|
177
|
+
| **Total** | **~$25/mo** | **~$87/mo** |
|
|
178
|
+
|
|
179
|
+
Use `single_instance` for development to minimize costs.
|
|
180
|
+
|
|
181
|
+
## Useful Commands
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
npm run synth # Synthesize CloudFormation template
|
|
185
|
+
npm run diff # Show changes vs deployed stack
|
|
186
|
+
npm run deploy # Build app and deploy
|
|
187
|
+
npm run destroy # Delete all resources
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Troubleshooting
|
|
191
|
+
|
|
192
|
+
### Deployment Fails
|
|
193
|
+
|
|
194
|
+
1. Check CloudFormation events in AWS Console
|
|
195
|
+
2. Review Elastic Beanstalk logs: `eb logs`
|
|
196
|
+
|
|
197
|
+
### Database Connection Issues
|
|
198
|
+
|
|
199
|
+
1. Verify security group allows traffic from EB instances
|
|
200
|
+
2. Check the secret exists and has correct values
|
|
201
|
+
3. Ensure the app is correctly reading `DB_SECRET_ARN`
|
|
202
|
+
|
|
203
|
+
### Health Check Failures
|
|
204
|
+
|
|
205
|
+
1. Ensure `/api/health` endpoint returns 200
|
|
206
|
+
2. Check application logs for startup errors
|
|
207
|
+
3. Verify all required environment variables are set
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import 'source-map-support/register';
|
|
3
|
+
import * as cdk from 'aws-cdk-lib';
|
|
4
|
+
import { ChaaskitStack } from '../lib/chaaskit-stack';
|
|
5
|
+
import { config } from '../config/deployment';
|
|
6
|
+
|
|
7
|
+
const app = new cdk.App();
|
|
8
|
+
|
|
9
|
+
const stage = app.node.tryGetContext('stage') || process.env.STAGE || 'prod';
|
|
10
|
+
|
|
11
|
+
new ChaaskitStack(app, `${config.serviceName}-${stage}`, {
|
|
12
|
+
env: {
|
|
13
|
+
account: process.env.CDK_DEFAULT_ACCOUNT,
|
|
14
|
+
region: config.region,
|
|
15
|
+
},
|
|
16
|
+
stage,
|
|
17
|
+
config,
|
|
18
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app": "npx ts-node --prefer-ts-exts bin/cdk.ts",
|
|
3
|
+
"watch": {
|
|
4
|
+
"include": [
|
|
5
|
+
"**"
|
|
6
|
+
],
|
|
7
|
+
"exclude": [
|
|
8
|
+
"README.md",
|
|
9
|
+
"cdk*.json",
|
|
10
|
+
"**/*.d.ts",
|
|
11
|
+
"**/*.js",
|
|
12
|
+
"tsconfig.json",
|
|
13
|
+
"package*.json",
|
|
14
|
+
"node_modules",
|
|
15
|
+
"cdk.out"
|
|
16
|
+
]
|
|
17
|
+
},
|
|
18
|
+
"context": {
|
|
19
|
+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
|
|
20
|
+
"@aws-cdk/core:checkSecretUsage": true,
|
|
21
|
+
"@aws-cdk/core:target-partitions": [
|
|
22
|
+
"aws",
|
|
23
|
+
"aws-cn"
|
|
24
|
+
],
|
|
25
|
+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
|
|
26
|
+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
|
|
27
|
+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
|
|
28
|
+
"@aws-cdk/aws-iam:minimizePolicies": true,
|
|
29
|
+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
|
|
30
|
+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
|
|
31
|
+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
|
|
32
|
+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
|
|
33
|
+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
|
|
34
|
+
"@aws-cdk/core:enablePartitionLiterals": true,
|
|
35
|
+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
|
|
36
|
+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
|
|
37
|
+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
|
|
38
|
+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
|
|
39
|
+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
|
|
40
|
+
"@aws-cdk/aws-route53-patters:useCertificate": true,
|
|
41
|
+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
|
|
2
|
+
|
|
3
|
+
export interface DeploymentConfig {
|
|
4
|
+
/**
|
|
5
|
+
* Service name used for naming AWS resources.
|
|
6
|
+
* Must be lowercase, alphanumeric, and hyphens only.
|
|
7
|
+
*/
|
|
8
|
+
serviceName: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* AWS region to deploy to
|
|
12
|
+
*/
|
|
13
|
+
region: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Balancer type:
|
|
17
|
+
* - 'load_balancer': Create new Application Load Balancer (default)
|
|
18
|
+
* - 'shared': Use existing shared ALB (requires sharedAlb config)
|
|
19
|
+
* - 'single_instance': No load balancer, single EC2 instance (dev/testing)
|
|
20
|
+
*/
|
|
21
|
+
balancerType: 'load_balancer' | 'shared' | 'single_instance';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* EC2 instance type for the application servers
|
|
25
|
+
* Recommended: t4g.small for small workloads, t4g.medium for medium
|
|
26
|
+
*/
|
|
27
|
+
instanceType: string;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Maximum number of instances for auto-scaling
|
|
31
|
+
*/
|
|
32
|
+
maxInstances: number;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Database configuration:
|
|
36
|
+
* - 'create': Create a new RDS instance (default)
|
|
37
|
+
* - 'existing': Use an existing RDS via Secrets Manager
|
|
38
|
+
*/
|
|
39
|
+
database: 'create' | 'existing';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* RDS instance size (only used when database: 'create')
|
|
43
|
+
* Recommended: MICRO for dev, SMALL for staging, MEDIUM+ for production
|
|
44
|
+
*/
|
|
45
|
+
dbInstanceSize?: ec2.InstanceSize;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Existing database secret ARN in Secrets Manager (required when database: 'existing')
|
|
49
|
+
* The secret should contain: host, port, dbname, username, password
|
|
50
|
+
*/
|
|
51
|
+
existingDbSecretArn?: string;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Custom domain name (optional)
|
|
55
|
+
* Example: 'app.example.com'
|
|
56
|
+
*/
|
|
57
|
+
domainName?: string;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* ACM certificate ARN for HTTPS
|
|
61
|
+
* Required for shared ALB or custom domain with new ALB
|
|
62
|
+
*/
|
|
63
|
+
certificateArn?: string;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Shared ALB configuration (required when balancerType: 'shared')
|
|
67
|
+
*/
|
|
68
|
+
sharedAlb?: {
|
|
69
|
+
/** ARN of the shared ALB */
|
|
70
|
+
albArn: string;
|
|
71
|
+
/** ARN of the HTTPS listener (port 443) */
|
|
72
|
+
listenerArn: string;
|
|
73
|
+
/** Host headers for routing (e.g., ['app.example.com', '*.example.com']) */
|
|
74
|
+
hostHeaders: string[];
|
|
75
|
+
/** Priority for the listener rule (must be unique per listener) */
|
|
76
|
+
priority: number;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Existing VPC configuration (required when using shared ALB or existing RDS)
|
|
81
|
+
*/
|
|
82
|
+
existingVpc?: {
|
|
83
|
+
/** VPC ID */
|
|
84
|
+
vpcId: string;
|
|
85
|
+
/** Private subnet IDs for EC2/RDS */
|
|
86
|
+
privateSubnetIds: string[];
|
|
87
|
+
/** Public subnet IDs for ALB */
|
|
88
|
+
publicSubnetIds: string[];
|
|
89
|
+
/** Security group ID that allows RDS access (optional) */
|
|
90
|
+
dbSecurityGroupId?: string;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Build version identifier (typically git commit SHA)
|
|
95
|
+
* This determines which app-{version}.zip file to deploy
|
|
96
|
+
*/
|
|
97
|
+
buildVersion: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Configure your deployment settings here
|
|
102
|
+
*/
|
|
103
|
+
export const config: DeploymentConfig = {
|
|
104
|
+
// Service name - will be used for AWS resource naming
|
|
105
|
+
serviceName: '{{SERVICE_NAME}}',
|
|
106
|
+
|
|
107
|
+
// AWS region
|
|
108
|
+
region: 'us-west-2',
|
|
109
|
+
|
|
110
|
+
// Balancer type: 'load_balancer' (new), 'shared' (existing), or 'single_instance'
|
|
111
|
+
balancerType: 'load_balancer',
|
|
112
|
+
|
|
113
|
+
// Instance type - t4g instances are ARM-based and cost-effective
|
|
114
|
+
instanceType: 't4g.small',
|
|
115
|
+
|
|
116
|
+
// Maximum instances for auto-scaling
|
|
117
|
+
maxInstances: 2,
|
|
118
|
+
|
|
119
|
+
// Database: 'create' for new RDS, 'existing' for shared RDS
|
|
120
|
+
database: 'create',
|
|
121
|
+
|
|
122
|
+
// Database instance size (when database: 'create')
|
|
123
|
+
dbInstanceSize: ec2.InstanceSize.MICRO,
|
|
124
|
+
|
|
125
|
+
// Custom domain (uncomment and configure)
|
|
126
|
+
// domainName: 'app.example.com',
|
|
127
|
+
// certificateArn: 'arn:aws:acm:us-west-2:123456789:certificate/xxx',
|
|
128
|
+
|
|
129
|
+
// ============================================================
|
|
130
|
+
// SHARED RESOURCES (uncomment to use existing infrastructure)
|
|
131
|
+
// ============================================================
|
|
132
|
+
|
|
133
|
+
// To use an existing database:
|
|
134
|
+
// database: 'existing',
|
|
135
|
+
// existingDbSecretArn: 'arn:aws:secretsmanager:us-west-2:ACCOUNT:secret:SECRET_ID',
|
|
136
|
+
|
|
137
|
+
// To use a shared ALB:
|
|
138
|
+
// balancerType: 'shared',
|
|
139
|
+
// sharedAlb: {
|
|
140
|
+
// albArn: 'arn:aws:elasticloadbalancing:us-west-2:ACCOUNT:loadbalancer/app/NAME/ID',
|
|
141
|
+
// listenerArn: 'arn:aws:elasticloadbalancing:us-west-2:ACCOUNT:listener/app/NAME/ID/LISTENER_ID',
|
|
142
|
+
// hostHeaders: ['app.example.com'],
|
|
143
|
+
// priority: 10,
|
|
144
|
+
// },
|
|
145
|
+
|
|
146
|
+
// To use an existing VPC (required for shared ALB or existing RDS):
|
|
147
|
+
// existingVpc: {
|
|
148
|
+
// vpcId: 'vpc-xxx',
|
|
149
|
+
// privateSubnetIds: ['subnet-xxx', 'subnet-yyy'],
|
|
150
|
+
// publicSubnetIds: ['subnet-xxx', 'subnet-yyy'],
|
|
151
|
+
// dbSecurityGroupId: 'sg-xxx',
|
|
152
|
+
// },
|
|
153
|
+
|
|
154
|
+
// Build version - set by CI/CD or use 'latest' for manual deploys
|
|
155
|
+
buildVersion: process.env.BUILD_VERSION || 'latest',
|
|
156
|
+
};
|