@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,130 @@
1
+ # Deploy SvelteKit to AWS Fargate
2
+
3
+ Run your SvelteKit 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 SvelteKit Project
6
+
7
+ ```bash
8
+ bunx sv create my-sveltekit-app
9
+ cd my-sveltekit-app
10
+ ```
11
+
12
+ Reference: [SvelteKit Creating a Project](https://svelte.dev/docs/kit/creating-a-project)
13
+
14
+ ## 2. Configure SvelteKit for Node
15
+
16
+ Edit `svelte.config.js`:
17
+
18
+ ```javascript
19
+ import adapter from '@sveltejs/adapter-node';
20
+
21
+ export default {
22
+ kit: {
23
+ adapter: adapter()
24
+ }
25
+ };
26
+ ```
27
+
28
+ ## 3. Create Dockerfile
29
+
30
+ ```dockerfile
31
+ FROM oven/bun:latest AS builder
32
+ WORKDIR /app
33
+
34
+ COPY package.json bun.lockb ./
35
+ RUN bun install --frozen-lockfile
36
+
37
+ COPY . .
38
+ RUN bun run build
39
+
40
+ FROM oven/bun:latest AS runner
41
+ WORKDIR /app
42
+
43
+ ENV NODE_ENV=production
44
+ ENV HOST=0.0.0.0
45
+ ENV PORT=3000
46
+
47
+ COPY --from=builder /app/build ./build
48
+ COPY --from=builder /app/package.json ./
49
+
50
+ EXPOSE 3000
51
+
52
+ CMD ["bun", "run", "build"]
53
+ ```
54
+
55
+ ## 4. Install Thunder
56
+
57
+ ```bash
58
+ bun add @thunder-so/thunder --development
59
+ ```
60
+
61
+ ## 5. Create Stack File
62
+
63
+ Create `stack/prod.ts`:
64
+
65
+ ```typescript
66
+ import { Cdk, Fargate, type FargateProps } from '@thunder-so/thunder';
67
+
68
+ const config: FargateProps = {
69
+ env: {
70
+ account: '123456789012',
71
+ region: 'us-east-1',
72
+ },
73
+ application: 'myapp',
74
+ service: 'web',
75
+ environment: 'prod',
76
+ rootDir: '.',
77
+
78
+ serviceProps: {
79
+ dockerFile: 'Dockerfile',
80
+ architecture: Cdk.aws_ecs.CpuArchitecture.ARM64,
81
+ cpu: 512,
82
+ memorySize: 1024,
83
+ port: 3000,
84
+ desiredCount: 1,
85
+ healthCheckPath: '/',
86
+ },
87
+ };
88
+
89
+ new Fargate(
90
+ new Cdk.App(),
91
+ `${config.application}-${config.service}-${config.environment}-stack`,
92
+ config
93
+ );
94
+ ```
95
+
96
+ ## 6. Deploy
97
+
98
+ ```bash
99
+ npx cdk deploy --app "npx tsx stack/prod.ts" --profile default
100
+ ```
101
+
102
+ ## Custom Domain with HTTPS
103
+
104
+ ```typescript
105
+ const config: FargateProps = {
106
+ // ...
107
+ domain: 'app.example.com',
108
+ regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
109
+ hostedZoneId: 'Z1234567890ABC',
110
+ };
111
+ ```
112
+
113
+ ## Environment Variables
114
+
115
+ ```typescript
116
+ serviceProps: {
117
+ // ...
118
+ variables: [
119
+ { NODE_ENV: 'production' },
120
+ ],
121
+ secrets: [
122
+ { key: 'DATABASE_URL', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:/myapp/db-abc123' },
123
+ ],
124
+ },
125
+ ```
126
+
127
+ ## Related
128
+
129
+ - [fargate-basic.md](../fargate-basic.md) - Fargate construct reference
130
+ - [sveltekit-serverless.md](./sveltekit-serverless.md) - SvelteKit on Lambda
@@ -0,0 +1,120 @@
1
+ # Deploy SvelteKit to AWS Lambda + S3 + CloudFront
2
+
3
+ Deploy your SvelteKit app with server-side rendering to AWS using Thunder's `SvelteKit` 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 SvelteKit Project
6
+
7
+ ```bash
8
+ bunx sv create my-sveltekit-app
9
+ cd my-sveltekit-app
10
+ ```
11
+
12
+ Reference: [SvelteKit Creating a Project](https://svelte.dev/docs/kit/creating-a-project)
13
+
14
+ ## 2. Install Lambda Adapter
15
+
16
+ ```bash
17
+ bun add -D @foladayo/sveltekit-adapter-lambda
18
+ ```
19
+
20
+ ## 3. Configure SvelteKit for AWS Lambda
21
+
22
+ Edit `svelte.config.js`:
23
+
24
+ ```javascript
25
+ import adapter from '@foladayo/sveltekit-adapter-lambda';
26
+
27
+ export default {
28
+ kit: {
29
+ adapter: adapter({
30
+ precompress: false,
31
+ serveStatic: true, // Required: serves prerendered pages
32
+ })
33
+ }
34
+ };
35
+ ```
36
+
37
+ Reference: [@foladayo/sveltekit-adapter-lambda](https://www.npmjs.com/package/@foladayo/sveltekit-adapter-lambda)
38
+
39
+ ## 4. Build Your App
40
+
41
+ ```bash
42
+ bun run build
43
+ ```
44
+
45
+ This generates:
46
+ - `build/` - Lambda handler (flat structure)
47
+ - `build/client/` - Static assets for S3
48
+
49
+ ## 5. Install Thunder
50
+
51
+ ```bash
52
+ bun add @thunder-so/thunder --development
53
+ ```
54
+
55
+ ## 6. Create Stack File
56
+
57
+ Create `stack/prod.ts`:
58
+
59
+ ```typescript
60
+ import { Cdk, SvelteKit, type SvelteKitProps } from '@thunder-so/thunder';
61
+
62
+ const config: SvelteKitProps = {
63
+ env: {
64
+ account: '123456789012',
65
+ region: 'us-east-1',
66
+ },
67
+ application: 'myapp',
68
+ service: 'web',
69
+ environment: 'prod',
70
+ rootDir: '.',
71
+ };
72
+
73
+ new SvelteKit(
74
+ new Cdk.App(),
75
+ `${config.application}-${config.service}-${config.environment}-stack`,
76
+ config
77
+ );
78
+ ```
79
+
80
+ ## 7. Deploy
81
+
82
+ ```bash
83
+ npx cdk deploy --app "npx tsx stack/prod.ts" --profile default
84
+ ```
85
+
86
+ ## Custom Domain
87
+
88
+ ```typescript
89
+ const config: SvelteKitProps = {
90
+ // ...
91
+ domain: 'app.example.com',
92
+ hostedZoneId: 'Z1234567890ABC',
93
+ globalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
94
+ regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/def-456',
95
+ };
96
+ ```
97
+
98
+ ## Environment Variables
99
+
100
+ ```typescript
101
+ serverProps: {
102
+ variables: [
103
+ { NODE_ENV: 'production' },
104
+ ],
105
+ secrets: [
106
+ { key: 'DATABASE_URL', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:/myapp/db-abc123' },
107
+ ],
108
+ },
109
+ ```
110
+
111
+ ## Important Notes
112
+
113
+ - **`serveStatic: true` is required** - Without it, prerendered pages return 404
114
+ - **`package.json` is auto-included** - The build output uses ESM and needs `"type": "module"`
115
+ - **Requires Node.js 22+** - Use `Runtime.NODEJS_22_X`
116
+
117
+ ## Related
118
+
119
+ - [serverless.md](../serverless.md) - Serverless construct overview
120
+ - [lambda-basic.md](../lambda-basic.md) - Lambda construct reference
@@ -0,0 +1,115 @@
1
+ # Deploy TanStack Start to AWS Fargate
2
+
3
+ Run your TanStack Start 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 TanStack Start Project
6
+
7
+ ```bash
8
+ bunx create-tanstack-start my-app
9
+ cd my-app
10
+ ```
11
+
12
+ Reference: [TanStack Start Quick Start](https://tanstack.com/start/latest/docs/framework/react/quick-start)
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/.output ./
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
+ - [tanstack-start-serverless.md](./tanstack-start-serverless.md) - TanStack Start on Lambda
@@ -0,0 +1,205 @@
1
+ # Deploy TanStack Start to AWS Lambda + S3 + CloudFront
2
+
3
+ Deploy your TanStack Start app with server-side rendering to AWS using Thunder's `TanStackStart` 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 TanStack Start Project
6
+
7
+ ```bash
8
+ bunx create-tanstack-start my-app
9
+ cd my-app
10
+ ```
11
+
12
+ Reference: [TanStack Start Quick Start](https://tanstack.com/start/latest/docs/framework/react/quick-start)
13
+
14
+ ## 2. Configure Nitro for AWS Lambda
15
+
16
+ TanStack Start uses [Nitro](https://nitro.unjs.io/) for server-side rendering. You **must** explicitly set the `aws-lambda` preset - the default is `node-server` which won't work on Lambda.
17
+
18
+ Edit `app.config.ts` (or create it if it doesn't exist):
19
+
20
+ ```typescript
21
+ import { defineConfig } from '@tanstack/start/config';
22
+ import { nitro } from 'nitro/vite';
23
+
24
+ export default defineConfig({
25
+ vite: {
26
+ plugins: [
27
+ nitro({
28
+ preset: 'aws-lambda', // Required for Lambda deployment
29
+ }),
30
+ ],
31
+ },
32
+ });
33
+ ```
34
+
35
+ **Alternative:** If using `@tanstack/nitro-v2-vite-plugin`:
36
+
37
+ ```typescript
38
+ import { nitroV2Plugin } from '@tanstack/nitro-v2-vite-plugin';
39
+
40
+ export default defineConfig({
41
+ vite: {
42
+ plugins: [
43
+ nitroV2Plugin({
44
+ preset: 'aws-lambda',
45
+ }),
46
+ ],
47
+ },
48
+ });
49
+ ```
50
+
51
+ Reference: [Nitro AWS Lambda Preset](https://nitro.build/deploy/providers/aws)
52
+
53
+ ## 3. Build Your App
54
+
55
+ ```bash
56
+ bun run build
57
+ ```
58
+
59
+ This generates:
60
+ - `.output/server/` - Lambda handler
61
+ - `.output/public/` - Static assets for S3
62
+
63
+ ## 4. Install Thunder
64
+
65
+ ```bash
66
+ bun add @thunder-so/thunder --development
67
+ ```
68
+
69
+ ## 5. Create Stack File
70
+
71
+ Create `stack/prod.ts`:
72
+
73
+ ```typescript
74
+ import { Cdk, TanStackStart, type TanStackStartProps } from '@thunder-so/thunder';
75
+
76
+ const config: TanStackStartProps = {
77
+ env: {
78
+ account: '123456789012', // Your AWS account ID
79
+ region: 'us-east-1',
80
+ },
81
+ application: 'myapp',
82
+ service: 'web',
83
+ environment: 'prod',
84
+
85
+ rootDir: '.',
86
+ };
87
+
88
+ new TanStackStart(
89
+ new Cdk.App(),
90
+ `${config.application}-${config.service}-${config.environment}-stack`,
91
+ config
92
+ );
93
+ ```
94
+
95
+ ## 6. Deploy
96
+
97
+ ```bash
98
+ npx cdk deploy --app "npx tsx stack/prod.ts" --profile default
99
+ ```
100
+
101
+ CDK outputs the CloudFront and API Gateway URLs:
102
+
103
+ ```
104
+ Outputs:
105
+ myapp-web-prod-stack.CloudFrontUrl = https://d1234abcd.cloudfront.net
106
+ myapp-web-prod-stack.ApiGatewayUrl = https://abc123.execute-api.us-east-1.amazonaws.com
107
+ ```
108
+
109
+ ## Custom Domain (Optional)
110
+
111
+ 1. [Create a Route53 Hosted Zone](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/AboutHZWorkingWith.html)
112
+ 2. [Request a global ACM certificate](https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html) in **`us-east-1`** (for CloudFront)
113
+ 3. [Request a regional ACM certificate](https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html) in your **function's region** (for API Gateway)
114
+
115
+ Update your stack:
116
+
117
+ ```typescript
118
+ const config: TanStackStartProps = {
119
+ // ...
120
+ domain: 'app.example.com',
121
+ hostedZoneId: 'Z1234567890ABC',
122
+ globalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
123
+ regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/def-456',
124
+ };
125
+ ```
126
+
127
+ ## Environment Variables
128
+
129
+ ```typescript
130
+ const config: TanStackStartProps = {
131
+ // ...
132
+ serverProps: {
133
+ variables: [
134
+ { NODE_ENV: 'production' },
135
+ { API_BASE_URL: 'https://api.example.com' },
136
+ ],
137
+ },
138
+ };
139
+ ```
140
+
141
+ ## Secrets from AWS Secrets Manager
142
+
143
+ ```bash
144
+ aws secretsmanager create-secret \
145
+ --name "/myapp/DATABASE_URL" \
146
+ --secret-string "postgres://user:pass@host/db"
147
+ ```
148
+
149
+ ```typescript
150
+ serverProps: {
151
+ secrets: [
152
+ { key: 'DATABASE_URL', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:/myapp/DATABASE_URL-abc123' },
153
+ ],
154
+ },
155
+ ```
156
+
157
+ ## Performance Tuning
158
+
159
+ ```typescript
160
+ serverProps: {
161
+ memorySize: 1792, // More memory = more CPU
162
+ timeout: 10,
163
+ keepWarm: true, // Ping every 5 min to prevent cold starts
164
+ tracing: true, // Enable AWS X-Ray
165
+ },
166
+ ```
167
+
168
+ ## Container Mode (Optional)
169
+
170
+ For larger apps, use Docker:
171
+
172
+ Create `Dockerfile`:
173
+
174
+ ```dockerfile
175
+ FROM public.ecr.aws/lambda/nodejs:22
176
+
177
+ COPY .output/server/ ./
178
+
179
+ CMD ["index.handler"]
180
+ ```
181
+
182
+ Update your stack:
183
+
184
+ ```typescript
185
+ serverProps: {
186
+ dockerFile: 'Dockerfile',
187
+ memorySize: 2048,
188
+ },
189
+ ```
190
+
191
+ ## Troubleshooting
192
+
193
+ **Error: `Runtime.HandlerNotFound: index.handler is undefined`**
194
+
195
+ You forgot to set `preset: 'aws-lambda'` in your Nitro config. The default `node-server` preset outputs an HTTP server, not a Lambda handler.
196
+
197
+ **Static assets not loading**
198
+
199
+ Check that your build output is in `.output/public/`. Thunder automatically deploys this to S3 and routes `*.*` requests through CloudFront.
200
+
201
+ ## Related
202
+
203
+ - [serverless.md](../serverless.md) - Serverless construct overview
204
+ - [lambda-basic.md](../lambda-basic.md) - Lambda construct reference
205
+ - [static-basic.md](../static-basic.md) - Static construct reference