@thunder-so/thunder 1.3.0 → 1.3.2

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.
@@ -0,0 +1,177 @@
1
+ # ECS Fargate Configuration Reference
2
+
3
+ Complete reference for every option available in the `Fargate` construct. Covers container configuration, compute sizing, Nixpacks, secrets, custom domains, and VPC integration. For a quick start see [fargate-basic.md](./fargate-basic.md).
4
+
5
+ ## Full Example
6
+
7
+ ```typescript
8
+ import { Cdk, Fargate, type FargateProps } from '@thunder-so/thunder';
9
+
10
+ const config: FargateProps = {
11
+ // Identity
12
+ env: {
13
+ account: '123456789012',
14
+ region: 'us-east-1',
15
+ },
16
+ application: 'myapp',
17
+ service: 'api',
18
+ environment: 'prod',
19
+
20
+ // Source
21
+ rootDir: '.', // monorepo: e.g. 'apps/api'
22
+
23
+ // Custom Domain
24
+ domain: 'api.example.com',
25
+ regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
26
+ hostedZoneId: 'Z1234567890ABC',
27
+
28
+ // Service
29
+ serviceProps: {
30
+ dockerFile: 'Dockerfile',
31
+ dockerBuildArgs: ['NODE_ENV=production'],
32
+ architecture: Cdk.aws_ecs.CpuArchitecture.ARM64,
33
+ cpu: 512,
34
+ memorySize: 1024,
35
+ port: 3000,
36
+ desiredCount: 2,
37
+ healthCheckPath: '/health',
38
+ variables: [
39
+ { NODE_ENV: 'production' },
40
+ ],
41
+ secrets: [
42
+ { key: 'DATABASE_URL', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:/myapp/db-abc123' },
43
+ ],
44
+ },
45
+
46
+ // Build System (Nixpacks alternative to Dockerfile)
47
+ // buildProps: {
48
+ // buildSystem: 'Nixpacks',
49
+ // runtime_version: '22',
50
+ // installcmd: 'pnpm install',
51
+ // buildcmd: 'pnpm run build',
52
+ // startcmd: 'pnpm start',
53
+ // },
54
+
55
+ // VPC (optional)
56
+ // vpc: existingVpc,
57
+
58
+ // Debug
59
+ debug: false,
60
+ };
61
+
62
+ new Fargate(new Cdk.App(), 'myapp-api-prod-stack', config);
63
+ ```
64
+
65
+ ## Property Reference
66
+
67
+ ### Identity (`AppProps`)
68
+
69
+ | Property | Type | Required | Default | Description |
70
+ |---|---|---|---|---|
71
+ | `env.account` | `string` | Yes | - | AWS account ID |
72
+ | `env.region` | `string` | Yes | - | AWS region |
73
+ | `application` | `string` | Yes | - | Project name |
74
+ | `service` | `string` | Yes | - | Service name |
75
+ | `environment` | `string` | Yes | - | Environment label |
76
+ | `rootDir` | `string` | No | `.` | Root of your app. Used as Docker build context. |
77
+ | `debug` | `boolean` | No | `false` | Enable verbose logging |
78
+
79
+ ### Custom Domain
80
+
81
+ | Property | Type | Description |
82
+ |---|---|---|
83
+ | `domain` | `string` | Public domain, e.g. `api.example.com` |
84
+ | `regionalCertificateArn` | `string` | ACM certificate ARN - **must be in the same region as the service** |
85
+ | `hostedZoneId` | `string` | Route53 hosted zone ID |
86
+
87
+ When all three are provided: HTTPS listener is added, HTTP redirects to HTTPS, and a Route53 A record is created.
88
+
89
+ ### `serviceProps`
90
+
91
+ #### Container
92
+
93
+ | Property | Type | Default | Description |
94
+ |---|---|---|---|
95
+ | `dockerFile` | `string` | `Dockerfile` | Path to Dockerfile relative to `rootDir` |
96
+ | `dockerBuildArgs` | `string[]` | - | Build args in `KEY=VALUE` format |
97
+ | `architecture` | `CpuArchitecture` | `X86_64` | `ARM64` or `X86_64`. ARM64 is cheaper on Fargate. |
98
+ | `port` | `number` | `3000` | Port your container listens on |
99
+ | `healthCheckPath` | `string` | `/` | HTTP path for ALB and ECS health checks |
100
+
101
+ #### Compute
102
+
103
+ | Property | Type | Default | Description |
104
+ |---|---|---|---|
105
+ | `cpu` | `number` | `256` | CPU units (256 = 0.25 vCPU). Must be a [valid Fargate combination](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html). |
106
+ | `memorySize` | `number` | `512` | Memory in MB. Must be valid for the chosen CPU. |
107
+ | `desiredCount` | `number` | `1` | Number of running task instances |
108
+
109
+ #### Environment
110
+
111
+ | Property | Type | Description |
112
+ |---|---|---|
113
+ | `variables` | `Array<{ [key: string]: string }>` | Plain environment variables injected into the container |
114
+ | `secrets` | `{ key: string; resource: string }[]` | Secrets Manager ARNs injected as env vars at container start. Task role is granted read access automatically. |
115
+
116
+ ### `buildProps` (Nixpacks)
117
+
118
+ | Property | Type | Default | Description |
119
+ |---|---|---|---|
120
+ | `buildSystem` | `'Nixpacks'` | - | Set to `'Nixpacks'` to auto-generate a Dockerfile. Requires Nixpacks CLI installed. |
121
+ | `runtime_version` | `string \| number` | `24` | Node.js version for Nixpacks (`NIXPACKS_NODE_VERSION`) |
122
+ | `installcmd` | `string` | auto | Override install command |
123
+ | `buildcmd` | `string` | auto | Override build command |
124
+ | `startcmd` | `string` | auto | Override start command |
125
+ | `environment` | `Array<{ [key: string]: string }>` | - | Build-time environment variables |
126
+ | `secrets` | `{ key: string; resource: string }[]` | - | Build-time secrets from Secrets Manager |
127
+
128
+ ### VPC
129
+
130
+ | Property | Type | Description |
131
+ |---|---|---|
132
+ | `vpc` | `IVpc \| IVpcLink` | Attach to an existing VPC. If not provided, a new VPC with 2 public subnets across 2 AZs is created automatically. |
133
+
134
+ ## Networking Details
135
+
136
+ - Tasks run in **public subnets** with `assignPublicIp: true` (no NAT Gateway cost)
137
+ - A dedicated security group restricts inbound traffic to the ALB only
138
+ - The ALB security group allows all outbound traffic
139
+ - Health check: `wget` to `localhost:PORT/healthCheckPath`, 15s interval, 5s timeout, 3 retries, 60s grace period
140
+
141
+ ## Load Balancer Details
142
+
143
+ - HTTP/1.1 and HTTP/2 supported
144
+ - HTTP (port 80) is always created; HTTPS (port 443) is added when a domain is configured
145
+ - HTTP → HTTPS redirect is automatic when HTTPS is enabled
146
+ - ALB name is derived from `application-service-environment`
147
+
148
+ ## Stack Outputs
149
+
150
+ | Output | Description |
151
+ |---|---|
152
+ | `LoadBalancerDNS` | ALB DNS name |
153
+ | `Route53Domain` | Custom domain URL (only if domain is configured) |
154
+
155
+ ## CPU / Memory Valid Combinations
156
+
157
+ | CPU | vCPU | Valid Memory Values (MB) |
158
+ |---|---|---|
159
+ | 256 | 0.25 | 512, 1024, 2048 |
160
+ | 512 | 0.5 | 1024, 2048, 3072, 4096 |
161
+ | 1024 | 1 | 2048–8192 (in 1024 increments) |
162
+ | 2048 | 2 | 4096–16384 (in 1024 increments) |
163
+ | 4096 | 4 | 8192–30720 (in 1024 increments) |
164
+
165
+ ## Estimated Cost
166
+
167
+ | Scenario | Monthly (no free tier, `us-east-1`) |
168
+ |---|---|
169
+ | 1 task (0.25 vCPU / 512 MB) | ~$33 |
170
+ | 2 tasks (0.5 vCPU / 1 GB each) | ~$47 |
171
+
172
+ The ALB (~$22/month) is the dominant fixed cost. See [Fargate pricing](https://aws.amazon.com/fargate/pricing/).
173
+
174
+ ## Related
175
+
176
+ - [fargate-basic.md](./fargate-basic.md) - Quick start with Dockerfile
177
+ - [fargate-nixpacks.md](./fargate-nixpacks.md) - Auto-generate Dockerfiles with Nixpacks
@@ -0,0 +1,199 @@
1
+ # Auto-generate Dockerfiles for Fargate with Nixpacks
2
+
3
+ Skip writing a `Dockerfile` entirely. [Nixpacks](https://nixpacks.com/) inspects your project, detects the language and framework, and generates an optimized container image automatically. Thunder runs Nixpacks during `cdk synth` and uses the result as your Fargate container.
4
+
5
+ Works with Node.js, Python, Go, Ruby, Rust, PHP, Java, Deno, and more.
6
+
7
+ ## How It Works
8
+
9
+ When `buildProps.buildSystem` is set to `'Nixpacks'`, Thunder runs the Nixpacks CLI during `cdk synth` to generate a `.nixpacks/Dockerfile` in your project root. That generated Dockerfile is then used as the container image for your Fargate task.
10
+
11
+ The flow:
12
+ 1. `cdk deploy` triggers synth
13
+ 2. Thunder runs `nixpacks build --out .` in your `rootDir`
14
+ 3. Nixpacks detects your runtime (Node, Python, Go, etc.) and generates `.nixpacks/Dockerfile`
15
+ 4. CDK builds and pushes the image to ECR using that Dockerfile
16
+ 5. Fargate pulls and runs the image
17
+
18
+ ## Prerequisites
19
+
20
+ Install the [Nixpacks CLI](https://nixpacks.com/docs/install):
21
+
22
+ ```bash
23
+ # macOS / Linux
24
+ curl -sSL https://nixpacks.com/install.sh | bash
25
+
26
+ # or via npm
27
+ npm install -g nixpacks
28
+ ```
29
+
30
+ Verify:
31
+ ```bash
32
+ nixpacks --version
33
+ ```
34
+
35
+ ## Basic Example
36
+
37
+ ```typescript
38
+ import { Cdk, Fargate, type FargateProps } from '@thunder-so/thunder';
39
+
40
+ const config: FargateProps = {
41
+ env: { account: '123456789012', region: 'us-east-1' },
42
+ application: 'myapp',
43
+ service: 'api',
44
+ environment: 'prod',
45
+ rootDir: '.',
46
+
47
+ serviceProps: {
48
+ port: 3000,
49
+ cpu: 512,
50
+ memorySize: 1024,
51
+ desiredCount: 1,
52
+ },
53
+
54
+ buildProps: {
55
+ buildSystem: 'Nixpacks',
56
+ },
57
+ };
58
+
59
+ new Fargate(new Cdk.App(), 'myapp-api-prod-stack', config);
60
+ ```
61
+
62
+ ## Custom Commands
63
+
64
+ Override Nixpacks' auto-detected commands:
65
+
66
+ ```typescript
67
+ buildProps: {
68
+ buildSystem: 'Nixpacks',
69
+ installcmd: 'pnpm install',
70
+ buildcmd: 'pnpm run build',
71
+ startcmd: 'pnpm start',
72
+ },
73
+ ```
74
+
75
+ If not set, Nixpacks auto-detects the best commands for your project based on `package.json`, `Pipfile`, `go.mod`, etc.
76
+
77
+ ## Node.js Version
78
+
79
+ Control the Node.js version via `runtime_version`:
80
+
81
+ ```typescript
82
+ buildProps: {
83
+ buildSystem: 'Nixpacks',
84
+ runtime_version: '22', // sets NIXPACKS_NODE_VERSION
85
+ },
86
+ ```
87
+
88
+ ## Build Environment Variables
89
+
90
+ Pass environment variables into the Nixpacks build:
91
+
92
+ ```typescript
93
+ buildProps: {
94
+ buildSystem: 'Nixpacks',
95
+ environment: [
96
+ { VITE_API_URL: 'https://api.example.com' },
97
+ ],
98
+ },
99
+ ```
100
+
101
+ ## Build Secrets
102
+
103
+ Inject secrets from AWS Secrets Manager into the build environment:
104
+
105
+ ```typescript
106
+ buildProps: {
107
+ buildSystem: 'Nixpacks',
108
+ secrets: [
109
+ { key: 'NPM_TOKEN', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:/myapp/NPM_TOKEN-abc123' },
110
+ ],
111
+ },
112
+ ```
113
+
114
+ ## Full Example with Domain
115
+
116
+ ```typescript
117
+ import { Cdk, Fargate, type FargateProps } from '@thunder-so/thunder';
118
+
119
+ const config: FargateProps = {
120
+ env: { account: '123456789012', region: 'us-east-1' },
121
+ application: 'myapp',
122
+ service: 'web',
123
+ environment: 'prod',
124
+ rootDir: '.',
125
+
126
+ domain: 'app.example.com',
127
+ regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
128
+ hostedZoneId: 'Z1234567890ABC',
129
+
130
+ serviceProps: {
131
+ architecture: Cdk.aws_ecs.CpuArchitecture.ARM64,
132
+ cpu: 512,
133
+ memorySize: 1024,
134
+ port: 3000,
135
+ desiredCount: 2,
136
+ healthCheckPath: '/health',
137
+ variables: [{ NODE_ENV: 'production' }],
138
+ secrets: [
139
+ { key: 'DATABASE_URL', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:/myapp/db-abc123' },
140
+ ],
141
+ },
142
+
143
+ buildProps: {
144
+ buildSystem: 'Nixpacks',
145
+ runtime_version: '22',
146
+ startcmd: 'node dist/server.js',
147
+ },
148
+ };
149
+
150
+ new Fargate(new Cdk.App(), 'myapp-web-prod-stack', config);
151
+ ```
152
+
153
+ ## Supported Languages & Frameworks
154
+
155
+ Nixpacks auto-detects and supports:
156
+
157
+ - **Node.js** - npm, pnpm, yarn, bun
158
+ - **Python** - pip, pipenv, poetry
159
+ - **Go**
160
+ - **Ruby** - bundler
161
+ - **Rust** - cargo
162
+ - **PHP** - composer
163
+ - **Java** - maven, gradle
164
+ - **Deno**
165
+
166
+ See the full list in the [Nixpacks documentation](https://nixpacks.com/docs/providers).
167
+
168
+ ## Nixpacks Configuration File
169
+
170
+ For advanced control, add a `nixpacks.toml` to your project root:
171
+
172
+ ```toml
173
+ # nixpacks.toml
174
+ [phases.install]
175
+ cmds = ["pnpm install --frozen-lockfile"]
176
+
177
+ [phases.build]
178
+ cmds = ["pnpm run build"]
179
+
180
+ [start]
181
+ cmd = "node dist/server.js"
182
+ ```
183
+
184
+ See [Nixpacks configuration docs](https://nixpacks.com/docs/configuration/file).
185
+
186
+ ## Troubleshooting
187
+
188
+ **`nixpacks: command not found`** - Install the CLI before running `cdk deploy`. Thunder calls it during synth.
189
+
190
+ **Wrong Node version** - Set `runtime_version` in `buildProps` or add a `.node-version` / `.nvmrc` file to your project root.
191
+
192
+ **Build fails** - Run `nixpacks build .` locally first to debug. The generated Dockerfile is at `.nixpacks/Dockerfile`.
193
+
194
+ **Port mismatch** - Ensure `serviceProps.port` matches the port your app listens on. Nixpacks sets `PORT` as an env var; use `process.env.PORT` in your app.
195
+
196
+ ## Related
197
+
198
+ - [fargate-basic.md](./fargate-basic.md) - Basic Dockerfile-based deployment
199
+ - [fargate-full.md](./fargate-full.md) - Full configuration reference
@@ -0,0 +1,115 @@
1
+ # Deploy AnalogJS to AWS Fargate
2
+
3
+ Run your AnalogJS app with full SSR support on [AWS ECS Fargate](https://aws.amazon.com/fargate/) using Thunder's `Fargate` construct.
4
+
5
+ ## 1. Create a New AnalogJS Project
6
+
7
+ ```bash
8
+ bunx create-analog@latest my-analog-app
9
+ cd my-analog-app
10
+ ```
11
+
12
+ Reference: [AnalogJS Getting Started](https://analogjs.org/docs/getting-started)
13
+
14
+ ## 2. Create Dockerfile
15
+
16
+ ```dockerfile
17
+ FROM oven/bun:latest AS builder
18
+ WORKDIR /app
19
+
20
+ COPY package.json bun.lockb ./
21
+ RUN bun install --frozen-lockfile
22
+
23
+ COPY . .
24
+ RUN bun run build
25
+
26
+ FROM oven/bun:latest AS runner
27
+ WORKDIR /app
28
+
29
+ ENV NODE_ENV=production
30
+ ENV HOST=0.0.0.0
31
+ ENV PORT=3000
32
+
33
+ COPY --from=builder /app/dist/analog ./
34
+
35
+ EXPOSE 3000
36
+
37
+ CMD ["bun", "run", "server/index.mjs"]
38
+ ```
39
+
40
+ ## 3. Install Thunder
41
+
42
+ ```bash
43
+ bun add @thunder-so/thunder --development
44
+ ```
45
+
46
+ ## 4. Create Stack File
47
+
48
+ Create `stack/prod.ts`:
49
+
50
+ ```typescript
51
+ import { Cdk, Fargate, type FargateProps } from '@thunder-so/thunder';
52
+
53
+ const config: FargateProps = {
54
+ env: {
55
+ account: '123456789012',
56
+ region: 'us-east-1',
57
+ },
58
+ application: 'myapp',
59
+ service: 'web',
60
+ environment: 'prod',
61
+ rootDir: '.',
62
+
63
+ serviceProps: {
64
+ dockerFile: 'Dockerfile',
65
+ architecture: Cdk.aws_ecs.CpuArchitecture.ARM64,
66
+ cpu: 512,
67
+ memorySize: 1024,
68
+ port: 3000,
69
+ desiredCount: 1,
70
+ healthCheckPath: '/',
71
+ },
72
+ };
73
+
74
+ new Fargate(
75
+ new Cdk.App(),
76
+ `${config.application}-${config.service}-${config.environment}-stack`,
77
+ config
78
+ );
79
+ ```
80
+
81
+ ## 5. Deploy
82
+
83
+ ```bash
84
+ npx cdk deploy --app "npx tsx stack/prod.ts" --profile default
85
+ ```
86
+
87
+ ## Custom Domain with HTTPS
88
+
89
+ ```typescript
90
+ const config: FargateProps = {
91
+ // ...
92
+ domain: 'app.example.com',
93
+ regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
94
+ hostedZoneId: 'Z1234567890ABC',
95
+ };
96
+ ```
97
+
98
+ ## Environment Variables
99
+
100
+ ```typescript
101
+ serviceProps: {
102
+ // ...
103
+ variables: [
104
+ { NODE_ENV: 'production' },
105
+ ],
106
+ secrets: [
107
+ { key: 'DATABASE_URL', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:/myapp/db-abc123' },
108
+ ],
109
+ },
110
+ ```
111
+
112
+ ## Related
113
+
114
+ - [fargate-basic.md](../fargate-basic.md) - Fargate construct reference
115
+ - [analogjs-serverless.md](./analogjs-serverless.md) - AnalogJS on Lambda
@@ -0,0 +1,121 @@
1
+ # Deploy AnalogJS to AWS Lambda + S3 + CloudFront
2
+
3
+ Deploy your AnalogJS app with server-side rendering to AWS using Thunder's `AnalogJS` construct. This creates a hybrid architecture: [Lambda](https://aws.amazon.com/lambda/) handles SSR and API routes, [S3](https://aws.amazon.com/s3/) hosts static assets, and [CloudFront](https://aws.amazon.com/cloudfront/) unifies both.
4
+
5
+ ## 1. Create a New AnalogJS Project
6
+
7
+ ```bash
8
+ bunx create-analog@latest my-analog-app
9
+ cd my-analog-app
10
+ ```
11
+
12
+ Reference: [AnalogJS Getting Started](https://analogjs.org/docs/getting-started)
13
+
14
+ ## 2. Configure Nitro for AWS Lambda
15
+
16
+ AnalogJS uses [Nitro](https://nitro.unjs.io/) for server-side rendering. Set the `aws-lambda` preset in `vite.config.ts`:
17
+
18
+ ```typescript
19
+ import { defineConfig } from 'vite';
20
+ import analog from '@analogjs/platform';
21
+
22
+ export default defineConfig({
23
+ plugins: [
24
+ analog({
25
+ nitro: {
26
+ preset: 'aws-lambda',
27
+ },
28
+ }),
29
+ ],
30
+ });
31
+ ```
32
+
33
+ Reference: [Nitro AWS Lambda Preset](https://nitro.build/deploy/providers/aws)
34
+
35
+ ## 3. Build Your App
36
+
37
+ ```bash
38
+ bun run build
39
+ ```
40
+
41
+ This generates:
42
+ - `dist/analog/server/` - Lambda handler
43
+ - `dist/analog/public/` - Static assets for S3
44
+
45
+ ## 4. Install Thunder
46
+
47
+ ```bash
48
+ bun add @thunder-so/thunder --development
49
+ ```
50
+
51
+ ## 5. Create Stack File
52
+
53
+ Create `stack/prod.ts`:
54
+
55
+ ```typescript
56
+ import { Cdk, AnalogJS, type AnalogJSProps } from '@thunder-so/thunder';
57
+
58
+ const config: AnalogJSProps = {
59
+ env: {
60
+ account: '123456789012',
61
+ region: 'us-east-1',
62
+ },
63
+ application: 'myapp',
64
+ service: 'web',
65
+ environment: 'prod',
66
+ rootDir: '.',
67
+ };
68
+
69
+ new AnalogJS(
70
+ new Cdk.App(),
71
+ `${config.application}-${config.service}-${config.environment}-stack`,
72
+ config
73
+ );
74
+ ```
75
+
76
+ ## 6. Deploy
77
+
78
+ ```bash
79
+ npx cdk deploy --app "npx tsx stack/prod.ts" --profile default
80
+ ```
81
+
82
+ ## Custom Domain
83
+
84
+ ```typescript
85
+ const config: AnalogJSProps = {
86
+ // ...
87
+ domain: 'app.example.com',
88
+ hostedZoneId: 'Z1234567890ABC',
89
+ globalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
90
+ regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/def-456',
91
+ };
92
+ ```
93
+
94
+ ## Environment Variables
95
+
96
+ ```typescript
97
+ serverProps: {
98
+ variables: [
99
+ { NODE_ENV: 'production' },
100
+ ],
101
+ secrets: [
102
+ { key: 'DATABASE_URL', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:/myapp/db-abc123' },
103
+ ],
104
+ },
105
+ ```
106
+
107
+ ## Performance Tuning
108
+
109
+ ```typescript
110
+ serverProps: {
111
+ memorySize: 1792,
112
+ timeout: 10,
113
+ keepWarm: true,
114
+ tracing: true,
115
+ },
116
+ ```
117
+
118
+ ## Related
119
+
120
+ - [serverless.md](../serverless.md) - Serverless construct overview
121
+ - [lambda-basic.md](../lambda-basic.md) - Lambda construct reference