@thunder-so/thunder 1.3.1 → 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.
- package/.kiro/settings/lsp.json +198 -0
- package/README.md +60 -118
- package/docs/fargate-basic.md +222 -0
- package/docs/fargate-full.md +177 -0
- package/docs/fargate-nixpacks.md +199 -0
- package/docs/frameworks/analogjs-fargate.md +115 -0
- package/docs/frameworks/analogjs-serverless.md +121 -0
- package/docs/frameworks/astro-fargate.md +120 -0
- package/docs/frameworks/astro-serverless.md +112 -0
- package/docs/frameworks/astro-static.md +108 -0
- package/docs/frameworks/nextjs-fargate-dockerfile.md +227 -0
- package/docs/frameworks/nextjs-fargate-nixpacks.md +113 -0
- package/docs/frameworks/nextjs-static.md +160 -0
- package/docs/frameworks/nuxt-fargate.md +115 -0
- package/docs/frameworks/nuxt-serverless.md +122 -0
- package/docs/frameworks/solidstart-fargate.md +115 -0
- package/docs/frameworks/solidstart-serverless.md +116 -0
- package/docs/frameworks/sveltekit-fargate.md +130 -0
- package/docs/frameworks/sveltekit-serverless.md +120 -0
- package/docs/frameworks/tanstack-start-fargate.md +115 -0
- package/docs/frameworks/tanstack-start-serverless.md +205 -0
- package/docs/lambda-basic.md +178 -0
- package/docs/lambda-containers.md +179 -0
- package/docs/lambda-full.md +185 -0
- package/docs/serverless.md +267 -0
- package/docs/static-basic.md +151 -0
- package/docs/static-edge-functions.md +187 -0
- package/docs/static-full.md +145 -0
- package/index.ts +8 -8
- package/package.json +1 -1
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Deploy Astro to AWS Fargate
|
|
2
|
+
|
|
3
|
+
Run your Astro 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 Astro Project
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bunx create-astro@latest my-astro-app
|
|
9
|
+
cd my-astro-app
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Reference: [Astro Installation Docs](https://docs.astro.build/en/install-and-setup/)
|
|
13
|
+
|
|
14
|
+
## 2. Configure Astro for Node Server
|
|
15
|
+
|
|
16
|
+
Edit `astro.config.mjs`:
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
import { defineConfig } from 'astro/config';
|
|
20
|
+
import node from '@astrojs/node';
|
|
21
|
+
|
|
22
|
+
export default defineConfig({
|
|
23
|
+
output: 'server',
|
|
24
|
+
adapter: node({
|
|
25
|
+
mode: 'standalone',
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 3. Create Dockerfile
|
|
31
|
+
|
|
32
|
+
```dockerfile
|
|
33
|
+
FROM public.ecr.aws/docker/library/node:22-alpine AS builder
|
|
34
|
+
WORKDIR /app
|
|
35
|
+
|
|
36
|
+
COPY package.json bun.lockb ./
|
|
37
|
+
RUN corepack enable && corepack prepare bun@latest --activate
|
|
38
|
+
RUN bun install --frozen-lockfile
|
|
39
|
+
|
|
40
|
+
COPY . .
|
|
41
|
+
RUN bun run build
|
|
42
|
+
|
|
43
|
+
FROM public.ecr.aws/docker/library/node:22-alpine AS runner
|
|
44
|
+
WORKDIR /app
|
|
45
|
+
|
|
46
|
+
ENV NODE_ENV=production
|
|
47
|
+
ENV HOST=0.0.0.0
|
|
48
|
+
ENV PORT=4321
|
|
49
|
+
|
|
50
|
+
COPY --from=builder /app/dist ./dist
|
|
51
|
+
COPY --from=builder /app/node_modules ./node_modules
|
|
52
|
+
COPY --from=builder /app/package.json ./
|
|
53
|
+
|
|
54
|
+
EXPOSE 4321
|
|
55
|
+
|
|
56
|
+
CMD ["node", "./dist/server/entry.mjs"]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 4. Install Thunder
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
bun add @thunder-so/thunder --development
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## 5. Create Stack File
|
|
66
|
+
|
|
67
|
+
Create `stack/prod.ts`:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { Cdk, Fargate, type FargateProps } from '@thunder-so/thunder';
|
|
71
|
+
|
|
72
|
+
const config: FargateProps = {
|
|
73
|
+
env: {
|
|
74
|
+
account: '123456789012',
|
|
75
|
+
region: 'us-east-1',
|
|
76
|
+
},
|
|
77
|
+
application: 'myapp',
|
|
78
|
+
service: 'web',
|
|
79
|
+
environment: 'prod',
|
|
80
|
+
rootDir: '.',
|
|
81
|
+
|
|
82
|
+
serviceProps: {
|
|
83
|
+
dockerFile: 'Dockerfile',
|
|
84
|
+
architecture: Cdk.aws_ecs.CpuArchitecture.ARM64,
|
|
85
|
+
cpu: 512,
|
|
86
|
+
memorySize: 1024,
|
|
87
|
+
port: 4321,
|
|
88
|
+
desiredCount: 1,
|
|
89
|
+
healthCheckPath: '/',
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
new Fargate(
|
|
94
|
+
new Cdk.App(),
|
|
95
|
+
`${config.application}-${config.service}-${config.environment}-stack`,
|
|
96
|
+
config
|
|
97
|
+
);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 6. Deploy
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
npx cdk deploy --app "npx tsx stack/prod.ts" --profile default
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Custom Domain
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
const config: FargateProps = {
|
|
110
|
+
// ...
|
|
111
|
+
domain: 'app.example.com',
|
|
112
|
+
regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
|
|
113
|
+
hostedZoneId: 'Z1234567890ABC',
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Related
|
|
118
|
+
|
|
119
|
+
- [fargate-basic.md](../fargate-basic.md) - Fargate construct reference
|
|
120
|
+
- [astro-serverless.md](./astro-serverless.md) - Astro on Lambda
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Deploy Astro with SSR to AWS Lambda + S3 + CloudFront
|
|
2
|
+
|
|
3
|
+
Deploy your Astro app with server-side rendering to AWS using Thunder's `Astro` 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 Astro Project
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bunx create-astro@latest my-astro-app
|
|
9
|
+
cd my-astro-app
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Reference: [Astro Installation Docs](https://docs.astro.build/en/install-and-setup/)
|
|
13
|
+
|
|
14
|
+
## 2. Install AWS Adapter
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
bun add @astro-aws/adapter
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 3. Configure Astro for AWS Lambda
|
|
21
|
+
|
|
22
|
+
Edit `astro.config.mjs`:
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
import { defineConfig } from 'astro/config';
|
|
26
|
+
import aws from '@astro-aws/adapter';
|
|
27
|
+
|
|
28
|
+
export default defineConfig({
|
|
29
|
+
output: 'server', // Enable SSR
|
|
30
|
+
adapter: aws(),
|
|
31
|
+
});
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Reference: [@astro-aws/adapter](https://www.npmjs.com/package/@astro-aws/adapter)
|
|
35
|
+
|
|
36
|
+
## 4. Build Your App
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
bun run build
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
This generates:
|
|
43
|
+
- `dist/lambda/` - Lambda handler
|
|
44
|
+
- `dist/client/` - Static assets for S3
|
|
45
|
+
|
|
46
|
+
## 5. Install Thunder
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
bun add @thunder-so/thunder --development
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## 6. Create Stack File
|
|
53
|
+
|
|
54
|
+
Create `stack/prod.ts`:
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
import { Cdk, Astro, type AstroProps } from '@thunder-so/thunder';
|
|
58
|
+
|
|
59
|
+
const config: AstroProps = {
|
|
60
|
+
env: {
|
|
61
|
+
account: '123456789012',
|
|
62
|
+
region: 'us-east-1',
|
|
63
|
+
},
|
|
64
|
+
application: 'myapp',
|
|
65
|
+
service: 'web',
|
|
66
|
+
environment: 'prod',
|
|
67
|
+
rootDir: '.',
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
new Astro(
|
|
71
|
+
new Cdk.App(),
|
|
72
|
+
`${config.application}-${config.service}-${config.environment}-stack`,
|
|
73
|
+
config
|
|
74
|
+
);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 7. Deploy
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npx cdk deploy --app "npx tsx stack/prod.ts" --profile default
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Custom Domain
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
const config: AstroProps = {
|
|
87
|
+
// ...
|
|
88
|
+
domain: 'app.example.com',
|
|
89
|
+
hostedZoneId: 'Z1234567890ABC',
|
|
90
|
+
globalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
|
|
91
|
+
regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/def-456',
|
|
92
|
+
};
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Environment Variables
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
serverProps: {
|
|
99
|
+
variables: [
|
|
100
|
+
{ NODE_ENV: 'production' },
|
|
101
|
+
],
|
|
102
|
+
secrets: [
|
|
103
|
+
{ key: 'API_KEY', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:/myapp/api-abc123' },
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Related
|
|
109
|
+
|
|
110
|
+
- [serverless.md](../serverless.md) - Serverless construct overview
|
|
111
|
+
- [astro-static.md](./astro-static.md) - Astro static site
|
|
112
|
+
- [astro-fargate.md](./astro-fargate.md) - Astro on Fargate
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Deploy Astro Static Site to AWS S3 + CloudFront
|
|
2
|
+
|
|
3
|
+
Host your Astro site as a static site on AWS using Thunder's `Static` construct. This guide covers static site generation (SSG) mode - HTML, CSS, and JavaScript served from [S3](https://aws.amazon.com/s3/) through [CloudFront](https://aws.amazon.com/cloudfront/).
|
|
4
|
+
|
|
5
|
+
## 1. Create a New Astro Project
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bunx create-astro@latest my-astro-site
|
|
9
|
+
cd my-astro-site
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
When prompted:
|
|
13
|
+
- Template: Choose any (e.g., "Empty", "Blog", "Portfolio")
|
|
14
|
+
- TypeScript: Yes (recommended)
|
|
15
|
+
- Install dependencies: Yes
|
|
16
|
+
- Git repository: Yes (optional)
|
|
17
|
+
|
|
18
|
+
Reference: [Astro Installation Docs](https://docs.astro.build/en/install-and-setup/)
|
|
19
|
+
|
|
20
|
+
## 2. Configure Static Output
|
|
21
|
+
|
|
22
|
+
Edit `astro.config.mjs`:
|
|
23
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
import { defineConfig } from 'astro/config';
|
|
26
|
+
|
|
27
|
+
export default defineConfig({
|
|
28
|
+
output: 'static', // Default, but explicit is better
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Reference: [Astro Static Exports](https://docs.astro.build/en/guides/deploy/)
|
|
33
|
+
|
|
34
|
+
## 3. Build Your App
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
bun run build
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
This generates static files in the `dist/` directory.
|
|
41
|
+
|
|
42
|
+
## 4. Install Thunder
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
bun add @thunder-so/thunder --development
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 5. Create Stack File
|
|
49
|
+
|
|
50
|
+
Create `stack/prod.ts`:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { Cdk, Static, type StaticProps } from '@thunder-so/thunder';
|
|
54
|
+
|
|
55
|
+
const config: StaticProps = {
|
|
56
|
+
env: {
|
|
57
|
+
account: '123456789012',
|
|
58
|
+
region: 'us-east-1',
|
|
59
|
+
},
|
|
60
|
+
application: 'myapp',
|
|
61
|
+
service: 'web',
|
|
62
|
+
environment: 'prod',
|
|
63
|
+
rootDir: '.',
|
|
64
|
+
outputDir: 'dist',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
new Static(
|
|
68
|
+
new Cdk.App(),
|
|
69
|
+
`${config.application}-${config.service}-${config.environment}-stack`,
|
|
70
|
+
config
|
|
71
|
+
);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## 6. Deploy
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
npx cdk deploy --app "npx tsx stack/prod.ts" --profile default
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Custom Domain
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const config: StaticProps = {
|
|
84
|
+
// ...
|
|
85
|
+
domain: 'site.example.com',
|
|
86
|
+
globalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
|
|
87
|
+
hostedZoneId: 'Z1234567890ABC',
|
|
88
|
+
};
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Redirects and Rewrites
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const config: StaticProps = {
|
|
95
|
+
// ...
|
|
96
|
+
redirects: [
|
|
97
|
+
{ source: '/old-page', destination: '/new-page' },
|
|
98
|
+
],
|
|
99
|
+
rewrites: [
|
|
100
|
+
{ source: '/blog/*', destination: '/posts/*' },
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Related
|
|
106
|
+
|
|
107
|
+
- [static-basic.md](../static-basic.md) - Static construct reference
|
|
108
|
+
- [astro-serverless.md](./astro-serverless.md) - Astro with SSR on Lambda
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# Deploy Next.js to AWS Fargate with Dockerfile
|
|
2
|
+
|
|
3
|
+
Run your Next.js app with full SSR support on [AWS ECS Fargate](https://aws.amazon.com/fargate/) using Thunder's `Fargate` construct. This deploys your app as a Docker container with an [Application Load Balancer](https://aws.amazon.com/elasticloadbalancing/application-load-balancer/) in front - no EC2 instances to manage.
|
|
4
|
+
|
|
5
|
+
Perfect for Next.js apps that need server-side rendering, API routes, or features not supported by static export.
|
|
6
|
+
|
|
7
|
+
## 1. Create a New Next.js Project
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bunx create-next-app@latest my-nextjs-app
|
|
11
|
+
cd my-nextjs-app
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
When prompted:
|
|
15
|
+
- TypeScript: Yes
|
|
16
|
+
- ESLint: Yes
|
|
17
|
+
- Tailwind CSS: Yes (optional)
|
|
18
|
+
- `src/` directory: No (optional)
|
|
19
|
+
- App Router: Yes
|
|
20
|
+
- Turbopack: Yes (optional)
|
|
21
|
+
|
|
22
|
+
Reference: [Next.js Installation Docs](https://nextjs.org/docs/getting-started/installation)
|
|
23
|
+
|
|
24
|
+
## 2. Configure Next.js for Standalone Output
|
|
25
|
+
|
|
26
|
+
Edit `next.config.ts`:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import type { NextConfig } from 'next';
|
|
30
|
+
|
|
31
|
+
const nextConfig: NextConfig = {
|
|
32
|
+
output: 'standalone', // Optimized for Docker
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default nextConfig;
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Reference: [Next.js Standalone Output](https://nextjs.org/docs/app/api-reference/next-config-js/output)
|
|
39
|
+
|
|
40
|
+
## 3. Create Dockerfile
|
|
41
|
+
|
|
42
|
+
Create `Dockerfile` in your project root:
|
|
43
|
+
|
|
44
|
+
```dockerfile
|
|
45
|
+
# Build stage
|
|
46
|
+
FROM public.ecr.aws/docker/library/node:22-alpine AS builder
|
|
47
|
+
WORKDIR /app
|
|
48
|
+
|
|
49
|
+
COPY package.json bun.lockb ./
|
|
50
|
+
RUN corepack enable && corepack prepare bun@latest --activate
|
|
51
|
+
RUN bun install --frozen-lockfile
|
|
52
|
+
|
|
53
|
+
COPY . .
|
|
54
|
+
RUN bun run build
|
|
55
|
+
|
|
56
|
+
# Production stage
|
|
57
|
+
FROM public.ecr.aws/docker/library/node:22-alpine AS runner
|
|
58
|
+
WORKDIR /app
|
|
59
|
+
|
|
60
|
+
ENV NODE_ENV=production
|
|
61
|
+
ENV HOSTNAME=0.0.0.0
|
|
62
|
+
ENV PORT=3000
|
|
63
|
+
|
|
64
|
+
RUN addgroup --system --gid 1001 nodejs
|
|
65
|
+
RUN adduser --system --uid 1001 nextjs
|
|
66
|
+
|
|
67
|
+
COPY --from=builder /app/public ./public
|
|
68
|
+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
69
|
+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
70
|
+
|
|
71
|
+
USER nextjs
|
|
72
|
+
|
|
73
|
+
EXPOSE 3000
|
|
74
|
+
|
|
75
|
+
CMD ["node", "server.js"]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Add `.dockerignore`:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
.git
|
|
82
|
+
node_modules
|
|
83
|
+
.next
|
|
84
|
+
.DS_Store
|
|
85
|
+
cdk.out
|
|
86
|
+
stack
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Reference: [Next.js Docker Deployment](https://nextjs.org/docs/app/guides/docker)
|
|
90
|
+
|
|
91
|
+
## 4. Install Thunder
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
bun add @thunder-so/thunder --development
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## 5. Create Stack File
|
|
98
|
+
|
|
99
|
+
Create `stack/prod.ts`:
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { Cdk, Fargate, type FargateProps } from '@thunder-so/thunder';
|
|
103
|
+
|
|
104
|
+
const config: FargateProps = {
|
|
105
|
+
env: {
|
|
106
|
+
account: '123456789012', // Your AWS account ID
|
|
107
|
+
region: 'us-east-1',
|
|
108
|
+
},
|
|
109
|
+
application: 'myapp',
|
|
110
|
+
service: 'web',
|
|
111
|
+
environment: 'prod',
|
|
112
|
+
|
|
113
|
+
rootDir: '.',
|
|
114
|
+
|
|
115
|
+
serviceProps: {
|
|
116
|
+
dockerFile: 'Dockerfile',
|
|
117
|
+
architecture: Cdk.aws_ecs.CpuArchitecture.ARM64,
|
|
118
|
+
cpu: 512, // 0.5 vCPU
|
|
119
|
+
memorySize: 1024, // 1 GB
|
|
120
|
+
port: 3000,
|
|
121
|
+
desiredCount: 1,
|
|
122
|
+
healthCheckPath: '/',
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
new Fargate(
|
|
127
|
+
new Cdk.App(),
|
|
128
|
+
`${config.application}-${config.service}-${config.environment}-stack`,
|
|
129
|
+
config
|
|
130
|
+
);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## 6. Deploy
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
npx cdk deploy --app "npx tsx stack/prod.ts" --profile default
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
CDK builds your Docker image, pushes it to ECR, and deploys to Fargate. The ALB DNS name is output:
|
|
140
|
+
|
|
141
|
+
```
|
|
142
|
+
Outputs:
|
|
143
|
+
myapp-web-prod-stack.LoadBalancerDNS = myapp-web-prod-1234567890.us-east-1.elb.amazonaws.com
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Custom Domain with HTTPS (Optional)
|
|
147
|
+
|
|
148
|
+
1. [Create a Route53 Hosted Zone](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/AboutHZWorkingWith.html)
|
|
149
|
+
2. [Request an ACM certificate](https://docs.aws.amazon.com/acm/latest/userguide/gs-acm-request-public.html) in the **same region as your service**
|
|
150
|
+
|
|
151
|
+
Update your stack:
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
const config: FargateProps = {
|
|
155
|
+
// ...
|
|
156
|
+
domain: 'app.example.com',
|
|
157
|
+
regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
|
|
158
|
+
hostedZoneId: 'Z1234567890ABC',
|
|
159
|
+
};
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
When a domain is configured:
|
|
163
|
+
- HTTPS listener is added on port 443
|
|
164
|
+
- HTTP on port 80 redirects to HTTPS
|
|
165
|
+
- Route53 A record is created
|
|
166
|
+
|
|
167
|
+
## Environment Variables
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
serviceProps: {
|
|
171
|
+
// ...
|
|
172
|
+
variables: [
|
|
173
|
+
{ NODE_ENV: 'production' },
|
|
174
|
+
{ NEXT_PUBLIC_API_URL: 'https://api.example.com' },
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Secrets from AWS Secrets Manager
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
aws secretsmanager create-secret \
|
|
183
|
+
--name "/myapp/DATABASE_URL" \
|
|
184
|
+
--secret-string "postgres://user:pass@host/db"
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
serviceProps: {
|
|
189
|
+
// ...
|
|
190
|
+
secrets: [
|
|
191
|
+
{ key: 'DATABASE_URL', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:/myapp/DATABASE_URL-abc123' },
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Scaling
|
|
197
|
+
|
|
198
|
+
Increase task count for high availability:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
serviceProps: {
|
|
202
|
+
desiredCount: 2, // Run 2 containers
|
|
203
|
+
cpu: 1024, // 1 vCPU per task
|
|
204
|
+
memorySize: 2048, // 2 GB per task
|
|
205
|
+
},
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
See [Fargate CPU/memory combinations](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-cpu-memory-error.html).
|
|
209
|
+
|
|
210
|
+
## Cost Estimate
|
|
211
|
+
|
|
212
|
+
Minimal deployment (1 task, `us-east-1`, no free tier):
|
|
213
|
+
|
|
214
|
+
| Component | Monthly |
|
|
215
|
+
|---|---|
|
|
216
|
+
| Fargate (1 task, 0.5 vCPU / 1 GB) | ~$15 |
|
|
217
|
+
| Application Load Balancer | ~$22 |
|
|
218
|
+
| CloudWatch Logs | <$1 |
|
|
219
|
+
| Route53 | $0.50 |
|
|
220
|
+
| **Total** | **~$38/month** |
|
|
221
|
+
|
|
222
|
+
## Related
|
|
223
|
+
|
|
224
|
+
- [fargate-basic.md](../fargate-basic.md) - Fargate construct reference
|
|
225
|
+
- [fargate-nixpacks.md](../fargate-nixpacks.md) - Auto-generate Dockerfiles with Nixpacks
|
|
226
|
+
- [fargate-full.md](../fargate-full.md) - Full configuration reference
|
|
227
|
+
- [nextjs-fargate-nixpacks.md](./nextjs-fargate-nixpacks.md) - Next.js on Fargate without writing a Dockerfile
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Deploy Next.js to AWS Fargate with Nixpacks
|
|
2
|
+
|
|
3
|
+
Run your Next.js app on [AWS ECS Fargate](https://aws.amazon.com/fargate/) without writing a Dockerfile. [Nixpacks](https://nixpacks.com/) auto-detects your project and generates an optimized container image.
|
|
4
|
+
|
|
5
|
+
## 1. Create a New Next.js Project
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bunx create-next-app@latest my-nextjs-app
|
|
9
|
+
cd my-nextjs-app
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Reference: [Next.js Installation Docs](https://nextjs.org/docs/getting-started/installation)
|
|
13
|
+
|
|
14
|
+
## 2. Install Nixpacks CLI
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
# macOS / Linux
|
|
18
|
+
curl -sSL https://nixpacks.com/install.sh | bash
|
|
19
|
+
|
|
20
|
+
# or via npm
|
|
21
|
+
npm install -g nixpacks
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Verify:
|
|
25
|
+
```bash
|
|
26
|
+
nixpacks --version
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Reference: [Nixpacks Installation](https://nixpacks.com/docs/install)
|
|
30
|
+
|
|
31
|
+
## 3. Install Thunder
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
bun add @thunder-so/thunder --development
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 4. Create Stack File
|
|
38
|
+
|
|
39
|
+
Create `stack/prod.ts`:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { Cdk, Fargate, type FargateProps } from '@thunder-so/thunder';
|
|
43
|
+
|
|
44
|
+
const config: FargateProps = {
|
|
45
|
+
env: {
|
|
46
|
+
account: '123456789012',
|
|
47
|
+
region: 'us-east-1',
|
|
48
|
+
},
|
|
49
|
+
application: 'myapp',
|
|
50
|
+
service: 'web',
|
|
51
|
+
environment: 'prod',
|
|
52
|
+
rootDir: '.',
|
|
53
|
+
|
|
54
|
+
serviceProps: {
|
|
55
|
+
architecture: Cdk.aws_ecs.CpuArchitecture.ARM64,
|
|
56
|
+
cpu: 512,
|
|
57
|
+
memorySize: 1024,
|
|
58
|
+
port: 3000,
|
|
59
|
+
desiredCount: 1,
|
|
60
|
+
healthCheckPath: '/',
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
buildProps: {
|
|
64
|
+
buildSystem: 'Nixpacks',
|
|
65
|
+
runtime_version: '22',
|
|
66
|
+
startcmd: 'bun start',
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
new Fargate(
|
|
71
|
+
new Cdk.App(),
|
|
72
|
+
`${config.application}-${config.service}-${config.environment}-stack`,
|
|
73
|
+
config
|
|
74
|
+
);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 5. Deploy
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npx cdk deploy --app "npx tsx stack/prod.ts" --profile default
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Nixpacks generates a Dockerfile during `cdk synth`, then CDK builds and deploys it.
|
|
84
|
+
|
|
85
|
+
## Custom Domain with HTTPS
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const config: FargateProps = {
|
|
89
|
+
// ...
|
|
90
|
+
domain: 'app.example.com',
|
|
91
|
+
regionalCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/abc-123',
|
|
92
|
+
hostedZoneId: 'Z1234567890ABC',
|
|
93
|
+
};
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Environment Variables
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
serviceProps: {
|
|
100
|
+
// ...
|
|
101
|
+
variables: [
|
|
102
|
+
{ NODE_ENV: 'production' },
|
|
103
|
+
],
|
|
104
|
+
secrets: [
|
|
105
|
+
{ key: 'DATABASE_URL', resource: 'arn:aws:secretsmanager:us-east-1:123456789012:secret:/myapp/db-abc123' },
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Related
|
|
111
|
+
|
|
112
|
+
- [fargate-nixpacks.md](../fargate-nixpacks.md) - Nixpacks reference
|
|
113
|
+
- [nextjs-fargate-dockerfile.md](./nextjs-fargate-dockerfile.md) - Next.js with custom Dockerfile
|