stacktape 3.5.8 → 3.6.0-beta.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/.tsconfig.bun-build.json +1 -0
- package/ai-docs/cli-ref/aws-profile-create.md +22 -0
- package/ai-docs/cli-ref/aws-profile-delete.md +22 -0
- package/ai-docs/cli-ref/aws-profile-list.md +20 -0
- package/ai-docs/cli-ref/aws-profile-update.md +22 -0
- package/ai-docs/cli-ref/bastion-session.md +29 -0
- package/ai-docs/cli-ref/bastion-tunnel.md +30 -0
- package/ai-docs/cli-ref/bucket-sync.md +30 -0
- package/ai-docs/cli-ref/cf-module-update.md +26 -0
- package/ai-docs/cli-ref/cf-rollback.md +28 -0
- package/ai-docs/cli-ref/codebuild-deploy.md +34 -0
- package/ai-docs/cli-ref/compile-template.md +25 -0
- package/ai-docs/cli-ref/container-session.md +30 -0
- package/ai-docs/cli-ref/debug-alarms.md +28 -0
- package/ai-docs/cli-ref/debug-aws-sdk.md +33 -0
- package/ai-docs/cli-ref/debug-container-exec.md +36 -0
- package/ai-docs/cli-ref/debug-dynamodb.md +35 -0
- package/ai-docs/cli-ref/debug-logs.md +34 -0
- package/ai-docs/cli-ref/debug-metrics.md +33 -0
- package/ai-docs/cli-ref/debug-opensearch.md +35 -0
- package/ai-docs/cli-ref/debug-redis.md +36 -0
- package/ai-docs/cli-ref/debug-sql.md +35 -0
- package/ai-docs/cli-ref/defaults-configure.md +29 -0
- package/ai-docs/cli-ref/defaults-list.md +20 -0
- package/ai-docs/cli-ref/delete.md +24 -0
- package/ai-docs/cli-ref/deploy.md +25 -0
- package/ai-docs/cli-ref/deployment-script-run.md +28 -0
- package/ai-docs/cli-ref/dev-stop.md +26 -0
- package/ai-docs/cli-ref/dev.md +45 -0
- package/ai-docs/cli-ref/domain-add.md +26 -0
- package/ai-docs/cli-ref/help.md +18 -0
- package/ai-docs/cli-ref/info-operations.md +22 -0
- package/ai-docs/cli-ref/info-stack.md +30 -0
- package/ai-docs/cli-ref/info-stacks.md +26 -0
- package/ai-docs/cli-ref/info-whoami.md +22 -0
- package/ai-docs/cli-ref/init.md +30 -0
- package/ai-docs/cli-ref/login.md +20 -0
- package/ai-docs/cli-ref/logout.md +18 -0
- package/ai-docs/cli-ref/mcp-add.md +22 -0
- package/ai-docs/cli-ref/mcp.md +20 -0
- package/ai-docs/cli-ref/org-create.md +24 -0
- package/ai-docs/cli-ref/org-delete.md +24 -0
- package/ai-docs/cli-ref/org-list.md +22 -0
- package/ai-docs/cli-ref/package-workloads.md +25 -0
- package/ai-docs/cli-ref/param-get.md +26 -0
- package/ai-docs/cli-ref/preview-changes.md +23 -0
- package/ai-docs/cli-ref/project-create.md +22 -0
- package/ai-docs/cli-ref/projects-list.md +22 -0
- package/ai-docs/cli-ref/rollback.md +28 -0
- package/ai-docs/cli-ref/script-run.md +29 -0
- package/ai-docs/cli-ref/secret-create.md +28 -0
- package/ai-docs/cli-ref/secret-delete.md +26 -0
- package/ai-docs/cli-ref/secret-get.md +26 -0
- package/ai-docs/cli-ref/upgrade.md +20 -0
- package/ai-docs/cli-ref/version.md +18 -0
- package/ai-docs/concept/connecting-resources.md +369 -0
- package/ai-docs/concept/directives.md +371 -0
- package/ai-docs/concept/extending-cloudformation.md +315 -0
- package/ai-docs/concept/overrides-and-transforms.md +352 -0
- package/ai-docs/concept/stages-and-environments.md +347 -0
- package/ai-docs/concept/typescript-config.md +447 -0
- package/ai-docs/concept/yaml-config.md +338 -0
- package/ai-docs/config-ref/_root.md +142 -0
- package/ai-docs/config-ref/application-load-balancer.md +1109 -0
- package/ai-docs/config-ref/astro-web.md +115 -0
- package/ai-docs/config-ref/aws-cdk-construct.md +68 -0
- package/ai-docs/config-ref/bastion.md +93 -0
- package/ai-docs/config-ref/batch-job.md +179 -0
- package/ai-docs/config-ref/bucket.md +348 -0
- package/ai-docs/config-ref/cdn.md +496 -0
- package/ai-docs/config-ref/custom-resource.md +80 -0
- package/ai-docs/config-ref/deployment-script.md +79 -0
- package/ai-docs/config-ref/dynamo-db-table.md +202 -0
- package/ai-docs/config-ref/edge-lambda-function.md +87 -0
- package/ai-docs/config-ref/efs-filesystem.md +72 -0
- package/ai-docs/config-ref/event-bus.md +63 -0
- package/ai-docs/config-ref/function.md +409 -0
- package/ai-docs/config-ref/hosting-bucket.md +171 -0
- package/ai-docs/config-ref/http-api-gateway.md +149 -0
- package/ai-docs/config-ref/http-endpoint.md +92 -0
- package/ai-docs/config-ref/kinesis-stream.md +97 -0
- package/ai-docs/config-ref/mongo-db-atlas-cluster.md +254 -0
- package/ai-docs/config-ref/multi-container-workload.md +399 -0
- package/ai-docs/config-ref/network-load-balancer.md +118 -0
- package/ai-docs/config-ref/nextjs-web.md +147 -0
- package/ai-docs/config-ref/nuxt-web.md +81 -0
- package/ai-docs/config-ref/open-search.md +206 -0
- package/ai-docs/config-ref/private-service.md +75 -0
- package/ai-docs/config-ref/redis-cluster.md +223 -0
- package/ai-docs/config-ref/relational-database.md +525 -0
- package/ai-docs/config-ref/remix-web.md +74 -0
- package/ai-docs/config-ref/sns-topic.md +69 -0
- package/ai-docs/config-ref/solidstart-web.md +75 -0
- package/ai-docs/config-ref/sqs-queue-not-empty.md +405 -0
- package/ai-docs/config-ref/sqs-queue.md +232 -0
- package/ai-docs/config-ref/state-machine.md +235 -0
- package/ai-docs/config-ref/sveltekit-web.md +81 -0
- package/ai-docs/config-ref/tanstack-web.md +75 -0
- package/ai-docs/config-ref/upstash-redis.md +59 -0
- package/ai-docs/config-ref/user-auth-pool.md +876 -0
- package/ai-docs/config-ref/web-app-firewall.md +212 -0
- package/ai-docs/config-ref/web-service.md +178 -0
- package/ai-docs/config-ref/worker-service.md +41 -0
- package/ai-docs/getting-started/console.md +232 -0
- package/ai-docs/getting-started/deployment.md +434 -0
- package/ai-docs/getting-started/dev-mode.md +118 -0
- package/ai-docs/getting-started/how-it-works.md +119 -0
- package/ai-docs/getting-started/intro.md +157 -0
- package/ai-docs/getting-started/using-with-ai.md +228 -0
- package/ai-docs/getting-started/workflow.md +197 -0
- package/ai-docs/index.json +1514 -0
- package/ai-docs/recipe/background-jobs.md +183 -0
- package/ai-docs/recipe/database-migrations.md +240 -0
- package/ai-docs/recipe/graphql-api.md +211 -0
- package/ai-docs/recipe/monorepo-setup.md +183 -0
- package/ai-docs/recipe/nextjs-full-stack.md +188 -0
- package/ai-docs/recipe/rest-api-with-database.md +156 -0
- package/ai-docs/recipe/scheduled-tasks.md +186 -0
- package/ai-docs/recipe/static-website.md +241 -0
- package/ai-docs/troubleshooting/cloudformation-stack-states.md +189 -0
- package/bin/stacktape.js +0 -12
- package/package.json +1 -1
- package/plain.d.ts +309 -54
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
---
|
|
2
|
+
docType: getting-started
|
|
3
|
+
title: Introduction
|
|
4
|
+
tags:
|
|
5
|
+
- introduction
|
|
6
|
+
- getting-started
|
|
7
|
+
source: docs/_curated-docs/getting-started/intro.mdx
|
|
8
|
+
priority: 2
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Stacktape
|
|
12
|
+
|
|
13
|
+
Stacktape is a cloud development framework that lets you deploy production-grade infrastructure to **your own AWS account** with minimal configuration. Think of it as PaaS-level simplicity with full AWS ownership.
|
|
14
|
+
|
|
15
|
+
**What it does:**
|
|
16
|
+
|
|
17
|
+
- Takes a ~30 line config and generates ~1,200+ lines of CloudFormation
|
|
18
|
+
- Handles packaging, bundling, permissions, networking, and security
|
|
19
|
+
- Deploys containers, serverless functions, databases, and 30+ AWS resource types
|
|
20
|
+
- Provides a development mode for fast local iteration
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
### 1. Install
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm install -g stacktape
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### 2. Login
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
stacktape login
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### 3. Configure AWS credentials
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
stacktape aws-profile:create
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### 4. Create your config
|
|
43
|
+
|
|
44
|
+
Create `stacktape.ts`:
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import {
|
|
48
|
+
defineConfig,
|
|
49
|
+
LambdaFunction,
|
|
50
|
+
HttpApiGateway,
|
|
51
|
+
HttpApiIntegration,
|
|
52
|
+
DynamoDbTable,
|
|
53
|
+
StacktapeLambdaBuildpackPackaging
|
|
54
|
+
} from 'stacktape';
|
|
55
|
+
|
|
56
|
+
export default defineConfig(() => {
|
|
57
|
+
const db = new DynamoDbTable({
|
|
58
|
+
primaryKey: { partitionKey: { name: 'id', type: 'string' } }
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const api = new HttpApiGateway({});
|
|
62
|
+
|
|
63
|
+
const handler = new LambdaFunction({
|
|
64
|
+
packaging: new StacktapeLambdaBuildpackPackaging({
|
|
65
|
+
entryfilePath: './src/handler.ts'
|
|
66
|
+
}),
|
|
67
|
+
connectTo: [db],
|
|
68
|
+
events: [
|
|
69
|
+
new HttpApiIntegration({
|
|
70
|
+
httpApiGatewayName: api.resourceName,
|
|
71
|
+
method: 'GET',
|
|
72
|
+
path: '/'
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return { resources: { api, handler, db } };
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Create `src/handler.ts`:
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
export const handler = async () => ({
|
|
85
|
+
statusCode: 200,
|
|
86
|
+
body: JSON.stringify({ message: 'Hello from Stacktape!' })
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 5. Deploy
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
stacktape deploy --stage dev --region us-east-1
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Your API is now live on AWS.
|
|
97
|
+
|
|
98
|
+
## What happens during deploy
|
|
99
|
+
|
|
100
|
+
1. **Config parsing** - Resolves directives like `$Secret()` and validates the config
|
|
101
|
+
2. **Code packaging** - Bundles Lambda functions with esbuild, builds Docker images
|
|
102
|
+
3. **CloudFormation generation** - Transforms your config into AWS CloudFormation
|
|
103
|
+
4. **Deployment** - Creates all resources in AWS in the correct dependency order
|
|
104
|
+
|
|
105
|
+
## Core concepts
|
|
106
|
+
|
|
107
|
+
**Stage** - An isolated environment (`dev`, `staging`, `production`). Each stage creates completely separate resources.
|
|
108
|
+
|
|
109
|
+
**connectTo** - Automatically configures IAM permissions, injects environment variables, and sets up networking between resources.
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const handler = new LambdaFunction({
|
|
113
|
+
connectTo: [db] // Grants permissions, injects STP_DB_TABLE_NAME
|
|
114
|
+
// ...
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
**Directives** - Special functions for dynamic values:
|
|
119
|
+
|
|
120
|
+
- `$Secret('name')` - Reference AWS Secrets Manager
|
|
121
|
+
- `$ResourceParam('resource', 'param')` - Get values from other resources
|
|
122
|
+
- `$Stage()` - Current stage name
|
|
123
|
+
|
|
124
|
+
## Config formats
|
|
125
|
+
|
|
126
|
+
Stacktape supports TypeScript (recommended), YAML, and JSON configs.
|
|
127
|
+
|
|
128
|
+
**TypeScript** - Full type safety, autocomplete, conditional logic:
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
export default defineConfig(({ stage }) => ({
|
|
132
|
+
resources: {
|
|
133
|
+
db: new RelationalDatabase({
|
|
134
|
+
instanceSize: stage === 'prod' ? 'db.t4g.medium' : 'db.t4g.micro'
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**YAML** - Simpler syntax, no build step:
|
|
141
|
+
|
|
142
|
+
```yaml
|
|
143
|
+
resources:
|
|
144
|
+
handler:
|
|
145
|
+
type: function
|
|
146
|
+
properties:
|
|
147
|
+
packaging:
|
|
148
|
+
type: stacktape-lambda-buildpack
|
|
149
|
+
properties:
|
|
150
|
+
entryfilePath: ./src/handler.ts
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Next steps
|
|
154
|
+
|
|
155
|
+
- [Workflow](/getting-started/workflow) - Understand the development and deployment workflow
|
|
156
|
+
- [Dev Mode](/getting-started/dev-mode) - Run locally with real cloud resources
|
|
157
|
+
- [Using with AI](/getting-started/using-with-ai) - Let AI agents build your infrastructure
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
---
|
|
2
|
+
docType: getting-started
|
|
3
|
+
title: Using with AI
|
|
4
|
+
tags:
|
|
5
|
+
- using
|
|
6
|
+
- with
|
|
7
|
+
- getting-started
|
|
8
|
+
source: docs/_curated-docs/getting-started/using-with-ai.mdx
|
|
9
|
+
priority: 2
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Using with AI
|
|
13
|
+
|
|
14
|
+
Stacktape's dev mode has an **agent mode** designed for AI coding assistants. It provides an HTTP API that lets AI agents start dev environments, trigger rebuilds, read logs, and even query databases - all programmatically.
|
|
15
|
+
|
|
16
|
+
## The AI workflow
|
|
17
|
+
|
|
18
|
+
When an AI agent builds infrastructure with Stacktape, the workflow looks like this:
|
|
19
|
+
|
|
20
|
+
1. **Write config** - AI writes/edits `stacktape.ts` based on your requirements
|
|
21
|
+
2. **Start dev mode** - AI starts agent mode to run the stack locally
|
|
22
|
+
3. **Write application code** - AI implements your handlers, services, etc.
|
|
23
|
+
4. **Test and iterate** - AI reads logs, triggers rebuilds, fixes errors
|
|
24
|
+
5. **Deploy** - Once working locally, AI deploys to AWS
|
|
25
|
+
|
|
26
|
+
The key is the **feedback loop**: the AI can see what's happening (logs, errors) and iterate until it works.
|
|
27
|
+
|
|
28
|
+
## Starting agent mode
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
stacktape dev --agent --agentPort 9900 --resources all --stage dev --region us-east-1
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
| Flag | Description |
|
|
35
|
+
| ------------- | ------------------------------------------- |
|
|
36
|
+
| `--agent` | Enable agent mode with HTTP API |
|
|
37
|
+
| `--agentPort` | Port for the HTTP server (default: 7331) |
|
|
38
|
+
| `--resources` | Workloads to run (`all` or comma-separated) |
|
|
39
|
+
|
|
40
|
+
The command outputs API endpoints when ready:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
AGENT_READY on port 9900
|
|
44
|
+
GET /status - workload status
|
|
45
|
+
GET /logs - get logs
|
|
46
|
+
POST /rebuild/{name} - rebuild workload
|
|
47
|
+
POST /stop - shutdown
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## API endpoints
|
|
51
|
+
|
|
52
|
+
### Check status
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
curl http://localhost:9900/status
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
```json
|
|
59
|
+
{
|
|
60
|
+
"phase": "ready",
|
|
61
|
+
"ready": true,
|
|
62
|
+
"workloads": {
|
|
63
|
+
"myApi": "http://localhost:3000",
|
|
64
|
+
"myWorker": "running"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
**Phase values:** `starting`, `ready`, `rebuilding`, `stopping`, `stopped`
|
|
70
|
+
|
|
71
|
+
### Get verbose status
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
curl "http://localhost:9900/status?verbose=true"
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Returns full details including ports, source directories, and local database status.
|
|
78
|
+
|
|
79
|
+
### Read logs
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
curl "http://localhost:9900/logs?limit=50"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"logs": "14:30:15 [myApi] Server started\n14:30:16 [myWorker] Processing...",
|
|
88
|
+
"count": 2,
|
|
89
|
+
"nextCursor": 1706000001
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Cursor-based pagination:** Use `nextCursor` from the response as `cursor` in the next request to get only new logs.
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
curl "http://localhost:9900/logs?cursor=1706000001"
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Rebuild a workload
|
|
100
|
+
|
|
101
|
+
After making code changes:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
curl -X POST http://localhost:9900/rebuild/myApi
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Rebuild all
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
curl -X POST http://localhost:9900/rebuild/all
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Stop dev mode
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
curl -X POST http://localhost:9900/stop
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Database endpoints
|
|
120
|
+
|
|
121
|
+
Agent mode exposes endpoints to query locally-emulated databases directly.
|
|
122
|
+
|
|
123
|
+
### PostgreSQL / MySQL
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
# Execute SQL
|
|
127
|
+
curl -X POST http://localhost:9900/postgres/myDb/query \
|
|
128
|
+
-H "Content-Type: application/json" \
|
|
129
|
+
-d '{"sql": "SELECT * FROM users LIMIT 10"}'
|
|
130
|
+
|
|
131
|
+
# Get schema
|
|
132
|
+
curl http://localhost:9900/postgres/myDb/schema
|
|
133
|
+
|
|
134
|
+
# List tables
|
|
135
|
+
curl http://localhost:9900/postgres/myDb/tables
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Redis
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
# Execute command
|
|
142
|
+
curl -X POST http://localhost:9900/redis/myCache/command \
|
|
143
|
+
-d '{"command": ["GET", "mykey"]}'
|
|
144
|
+
|
|
145
|
+
# List keys
|
|
146
|
+
curl http://localhost:9900/redis/myCache/keys
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### DynamoDB
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
# Scan table
|
|
153
|
+
curl -X POST http://localhost:9900/dynamodb/myTable/scan
|
|
154
|
+
|
|
155
|
+
# Query
|
|
156
|
+
curl -X POST http://localhost:9900/dynamodb/myTable/query \
|
|
157
|
+
-d '{"partitionKey": "user123"}'
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## AI agent example session
|
|
161
|
+
|
|
162
|
+
Here's what an AI session might look like:
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
User: Build me an API that stores and retrieves notes
|
|
166
|
+
|
|
167
|
+
AI: I'll create the config and start dev mode.
|
|
168
|
+
|
|
169
|
+
[Writes stacktape.ts with Lambda + DynamoDB]
|
|
170
|
+
[Writes src/handler.ts with basic CRUD]
|
|
171
|
+
|
|
172
|
+
$ stacktape dev --agent --agentPort 9900 --resources all --stage dev
|
|
173
|
+
|
|
174
|
+
AI: Dev mode is starting. Let me check the status...
|
|
175
|
+
|
|
176
|
+
$ curl http://localhost:9900/status
|
|
177
|
+
{"phase":"ready","ready":true,"workloads":{"api":"http://localhost:3000"}}
|
|
178
|
+
|
|
179
|
+
AI: Everything is running. Let me test the endpoint...
|
|
180
|
+
|
|
181
|
+
$ curl http://localhost:3000/notes
|
|
182
|
+
{"error":"Table not found"}
|
|
183
|
+
|
|
184
|
+
AI: There's an error. Let me check the logs...
|
|
185
|
+
|
|
186
|
+
$ curl http://localhost:9900/logs
|
|
187
|
+
{"logs":"[api] ERROR: STP_NOTES_TABLE_NAME is undefined"}
|
|
188
|
+
|
|
189
|
+
AI: The environment variable isn't being injected. I need to add connectTo.
|
|
190
|
+
|
|
191
|
+
[Edits stacktape.ts to add connectTo: [notesTable]]
|
|
192
|
+
|
|
193
|
+
$ curl -X POST http://localhost:9900/rebuild/api
|
|
194
|
+
|
|
195
|
+
AI: Rebuilt. Testing again...
|
|
196
|
+
|
|
197
|
+
$ curl http://localhost:3000/notes
|
|
198
|
+
{"notes":[]}
|
|
199
|
+
|
|
200
|
+
AI: Working! The API is ready.
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Best practices for AI agents
|
|
204
|
+
|
|
205
|
+
1. **Poll status first** - Wait for `phase === "ready"` before making requests
|
|
206
|
+
2. **Use cursors for logs** - Always use `nextCursor` to avoid re-fetching old logs
|
|
207
|
+
3. **Rebuild specific workloads** - Faster than rebuilding everything
|
|
208
|
+
4. **Check sourceDir in verbose status** - Know where source files are when debugging
|
|
209
|
+
5. **Use database endpoints** - Query data directly to verify behavior
|
|
210
|
+
|
|
211
|
+
## Stopping agent mode
|
|
212
|
+
|
|
213
|
+
From another terminal:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
stacktape dev --stop --agentPort 9900
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Or via API:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
curl -X POST http://localhost:9900/stop
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Next steps
|
|
226
|
+
|
|
227
|
+
- [Dev Mode](/getting-started/dev-mode) - Understanding dev mode in depth
|
|
228
|
+
- [Console](/getting-started/console) - Web-based management
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
---
|
|
2
|
+
docType: getting-started
|
|
3
|
+
title: Workflow
|
|
4
|
+
tags:
|
|
5
|
+
- workflow
|
|
6
|
+
- getting-started
|
|
7
|
+
source: docs/_curated-docs/getting-started/workflow.mdx
|
|
8
|
+
priority: 2
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Workflow
|
|
12
|
+
|
|
13
|
+
Stacktape is an Infrastructure-as-Code (IaC) tool. You define your infrastructure in a config file, and Stacktape translates it into AWS CloudFormation and deploys it.
|
|
14
|
+
|
|
15
|
+
## The mental model
|
|
16
|
+
|
|
17
|
+
**Traditional IaC (CloudFormation, Terraform):**
|
|
18
|
+
|
|
19
|
+
- You write hundreds of lines describing every detail
|
|
20
|
+
- You manage IAM policies, security groups, VPC configs manually
|
|
21
|
+
- Mistakes are common, debugging is painful
|
|
22
|
+
|
|
23
|
+
**Stacktape:**
|
|
24
|
+
|
|
25
|
+
- You write what you want at a high level (~30 lines)
|
|
26
|
+
- Stacktape generates the low-level details (~1,200+ lines of CloudFormation)
|
|
27
|
+
- Best practices are built in (security, networking, permissions)
|
|
28
|
+
|
|
29
|
+
You still own everything. It all deploys to your AWS account. You can inspect, override, or eject at any time.
|
|
30
|
+
|
|
31
|
+
## Configuration file
|
|
32
|
+
|
|
33
|
+
Your config file (`stacktape.ts`, `stacktape.yml`, or `stacktape.json`) defines:
|
|
34
|
+
|
|
35
|
+
- **Resources** - Lambda functions, databases, queues, buckets, etc.
|
|
36
|
+
- **Connections** - Which resources can access each other
|
|
37
|
+
- **Scripts** - Database migrations, seed scripts, utilities
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
// stacktape.ts
|
|
41
|
+
import { defineConfig, LambdaFunction, RelationalDatabase } from 'stacktape';
|
|
42
|
+
|
|
43
|
+
export default defineConfig(({ stage }) => {
|
|
44
|
+
const db = new RelationalDatabase({
|
|
45
|
+
engine: { type: 'postgres', version: '16' },
|
|
46
|
+
primaryInstance: {
|
|
47
|
+
instanceSize: stage === 'prod' ? 'db.t4g.medium' : 'db.t4g.micro'
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const api = new LambdaFunction({
|
|
52
|
+
packaging: { type: 'stacktape-lambda-buildpack', properties: { entryfilePath: './src/api.ts' } },
|
|
53
|
+
connectTo: [db]
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return { resources: { db, api } };
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Stages and environments
|
|
61
|
+
|
|
62
|
+
Each deployment has a **stage** (environment name). Stages are completely isolated - separate databases, separate functions, separate everything.
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
stacktape deploy --stage dev --region us-east-1 # my-app-dev stack
|
|
66
|
+
stacktape deploy --stage staging --region us-east-1 # my-app-staging stack
|
|
67
|
+
stacktape deploy --stage prod --region us-east-1 # my-app-prod stack
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Use stages in your config for environment-specific settings:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
export default defineConfig(({ stage }) => ({
|
|
74
|
+
resources: {
|
|
75
|
+
db: new RelationalDatabase({
|
|
76
|
+
primaryInstance: {
|
|
77
|
+
instanceSize: stage === 'prod' ? 'db.t4g.medium' : 'db.t4g.micro',
|
|
78
|
+
multiAz: stage === 'prod'
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
}));
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## The connectTo pattern
|
|
86
|
+
|
|
87
|
+
When you connect resources with `connectTo`, Stacktape automatically:
|
|
88
|
+
|
|
89
|
+
1. **Grants IAM permissions** - The source resource can access the target
|
|
90
|
+
2. **Injects environment variables** - Connection strings, hostnames, ARNs
|
|
91
|
+
3. **Configures networking** - Security groups, VPC placement if needed
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const db = new DynamoDbTable({
|
|
95
|
+
/* ... */
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const handler = new LambdaFunction({
|
|
99
|
+
connectTo: [db] // Handler gets read/write access to db
|
|
100
|
+
// ...
|
|
101
|
+
});
|
|
102
|
+
// Environment: STP_DB_TABLE_NAME, STP_DB_TABLE_ARN
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
This replaces pages of IAM policies and networking configs with a single line.
|
|
106
|
+
|
|
107
|
+
## Deployment flow
|
|
108
|
+
|
|
109
|
+
When you run `stacktape deploy`:
|
|
110
|
+
|
|
111
|
+
1. **Parse** - Load config, resolve directives (`$Secret()`, `$Stage()`, etc.)
|
|
112
|
+
2. **Validate** - Check config structure and resource compatibility
|
|
113
|
+
3. **Package** - Bundle Lambda code with esbuild, build Docker images
|
|
114
|
+
4. **Generate** - Transform config into CloudFormation template
|
|
115
|
+
5. **Deploy** - Upload artifacts to S3, execute CloudFormation
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
$ stacktape deploy --stage dev --region us-east-1
|
|
119
|
+
|
|
120
|
+
Packaging handler... [2.1s]
|
|
121
|
+
Uploading artifacts... [1.4s]
|
|
122
|
+
Deploying stack my-app-dev... [45s]
|
|
123
|
+
|
|
124
|
+
Stack deployed successfully!
|
|
125
|
+
|
|
126
|
+
Outputs:
|
|
127
|
+
api.url: https://abc123.execute-api.us-east-1.amazonaws.com
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Development workflow
|
|
131
|
+
|
|
132
|
+
For active development, use **dev mode** instead of deploying every change:
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
stacktape dev --stage dev --region us-east-1
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
This runs your workloads locally while connected to (or emulating) cloud resources. See [Dev Mode](/getting-started/dev-mode).
|
|
139
|
+
|
|
140
|
+
## Typical iteration cycle
|
|
141
|
+
|
|
142
|
+
1. **Write config** - Define your infrastructure in `stacktape.ts`
|
|
143
|
+
2. **Dev mode** - Iterate locally with `stacktape dev`
|
|
144
|
+
3. **Deploy** - Ship to dev/staging with `stacktape deploy`
|
|
145
|
+
4. **Test** - Verify in cloud environment
|
|
146
|
+
5. **Production** - Deploy to prod stage
|
|
147
|
+
|
|
148
|
+
## Extending Stacktape
|
|
149
|
+
|
|
150
|
+
Need something Stacktape doesn't support natively? You have options:
|
|
151
|
+
|
|
152
|
+
**Overrides** - Modify any generated CloudFormation property:
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
const fn = new LambdaFunction({
|
|
156
|
+
// ...
|
|
157
|
+
overrides: {
|
|
158
|
+
lambda: { Description: 'Custom description' }
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Raw CloudFormation** - Add any AWS resource:
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
export default defineConfig(() => ({
|
|
167
|
+
resources: {
|
|
168
|
+
/* ... */
|
|
169
|
+
},
|
|
170
|
+
cloudformationResources: {
|
|
171
|
+
myTopic: {
|
|
172
|
+
Type: 'AWS::SNS::Topic',
|
|
173
|
+
Properties: { TopicName: 'my-topic' }
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}));
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
**Transforms** - Programmatically modify resources (TypeScript only):
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
const fn = new LambdaFunction({
|
|
183
|
+
// ...
|
|
184
|
+
transforms: {
|
|
185
|
+
lambda: (props) => ({
|
|
186
|
+
...props,
|
|
187
|
+
MemorySize: (props.MemorySize ?? 128) * 2
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Next steps
|
|
194
|
+
|
|
195
|
+
- [Dev Mode](/getting-started/dev-mode) - Local development with cloud resources
|
|
196
|
+
- [Using with AI](/getting-started/using-with-ai) - AI-assisted development
|
|
197
|
+
- [Console](/getting-started/console) - Web-based management
|