@worktif/runtime 0.3.0-edge.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/LICENSE +101 -0
- package/README.md +495 -0
- package/out/dist/bin/index.js +212 -0
- package/out/dist/bin/purenow.js +218 -0
- package/out/dist/bin/templates/runtime-web/cdk/.gitignore.template +25 -0
- package/out/dist/bin/templates/runtime-web/cdk/README.md.template +267 -0
- package/out/dist/bin/templates/runtime-web/cdk/bin/app.ts.template +173 -0
- package/out/dist/bin/templates/runtime-web/cdk/cdk.json.template +79 -0
- package/out/dist/bin/templates/runtime-web/cdk/package.json.template +28 -0
- package/out/dist/bin/templates/runtime-web/cdk/tsconfig.json.template +38 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/.env.example +15 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/README.md +118 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/gitignore.template +64 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/package.json +34 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/purenow.config.ts +105 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/app.tsx +35 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/handlers/users/index.ts +17 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/handlers/users/users.handlers.ts +222 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/index.tsx +71 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/about-page.tsx +65 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/home-page.tsx +55 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/pages/users-page.tsx +66 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/routes.tsx +61 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/services/index.ts +17 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/services/users.service.ts +133 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/ties/index.ts +17 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/src/ties/users.ties.ts +53 -0
- package/out/dist/bin/templates/runtime-web/purenow-basic/tsconfig.json +53 -0
- package/out/dist/lib/index.d.ts +4 -0
- package/out/dist/lib/index.js +4 -0
- package/out/dist/lib/lib/index.d.ts +3 -0
- package/out/dist/lib/lib/runtime-web/index.d.ts +17 -0
- package/out/dist/lib/lib/runtime-web/pipelines/browser-pipeline.d.ts +110 -0
- package/out/dist/lib/lib/runtime-web/pipelines/index.d.ts +2 -0
- package/out/dist/lib/lib/runtime-web/pureweb.d.ts +65 -0
- package/out/dist/lib/lib/runtime-web/types/config.types.d.ts +301 -0
- package/out/dist/lib/lib/runtime-web/types/http.types.d.ts +171 -0
- package/out/dist/lib/lib/runtime-web/types/index.d.ts +14 -0
- package/out/dist/lib/lib/runtime-web/types/infra.types.d.ts +225 -0
- package/out/dist/lib/lib/runtime-web/types/lambda.types.d.ts +175 -0
- package/out/dist/lib/lib/runtime-web/types/microservice.types.d.ts +70 -0
- package/out/dist/lib/lib/runtime-web/types/runtime.types.d.ts +55 -0
- package/out/dist/lib/utils/index.d.ts +2 -0
- package/out/dist/lib/utils/types/index.d.ts +3 -0
- package/out/dist/lib/utils/types/runtime.config.types.d.ts +71 -0
- package/out/dist/src/bin/index.d.ts +5 -0
- package/out/dist/src/bin/index.unix.d.ts +5 -0
- package/out/dist/src/bin/purenow-runtime-cli.d.ts +31 -0
- package/out/dist/src/bin/services/index.d.ts +8 -0
- package/out/dist/src/bin/services/purenow-runtime-deployment.strategy.d.ts +37 -0
- package/out/dist/src/bin/services/purenow-runtime-stacks-deploy.service.d.ts +58 -0
- package/out/dist/src/bin/services/purenow-runtime-stacks-deploy.service.types.d.ts +18 -0
- package/out/dist/src/bin/services/runtime-web-cli-extensions.d.ts +2 -0
- package/out/dist/src/bin/services/template.service.d.ts +53 -0
- package/out/dist/src/bin/services/utils/index.d.ts +2 -0
- package/out/dist/src/bin/utils/errors.d.ts +68 -0
- package/out/dist/src/lib/runtime-web/index.d.ts +17 -0
- package/out/dist/src/lib/runtime-web/pipelines/browser-pipeline.d.ts +110 -0
- package/out/dist/src/lib/runtime-web/pipelines/index.d.ts +2 -0
- package/out/dist/src/lib/runtime-web/pureweb.d.ts +65 -0
- package/out/dist/src/lib/runtime-web/types/config.types.d.ts +301 -0
- package/out/dist/src/lib/runtime-web/types/http.types.d.ts +171 -0
- package/out/dist/src/lib/runtime-web/types/index.d.ts +14 -0
- package/out/dist/src/lib/runtime-web/types/infra.types.d.ts +225 -0
- package/out/dist/src/lib/runtime-web/types/lambda.types.d.ts +175 -0
- package/out/dist/src/lib/runtime-web/types/microservice.types.d.ts +70 -0
- package/out/dist/src/lib/runtime-web/types/runtime.types.d.ts +55 -0
- package/package.json +133 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# CDK asset staging directory
|
|
2
|
+
.cdk.staging
|
|
3
|
+
cdk.out
|
|
4
|
+
|
|
5
|
+
# Dependency directories
|
|
6
|
+
node_modules/
|
|
7
|
+
|
|
8
|
+
# TypeScript compiled output
|
|
9
|
+
*.js
|
|
10
|
+
*.d.ts
|
|
11
|
+
|
|
12
|
+
# Environment variables
|
|
13
|
+
.env
|
|
14
|
+
.env.local
|
|
15
|
+
|
|
16
|
+
# IDE
|
|
17
|
+
.vscode/
|
|
18
|
+
.idea/
|
|
19
|
+
*.swp
|
|
20
|
+
*.swo
|
|
21
|
+
*~
|
|
22
|
+
|
|
23
|
+
# OS
|
|
24
|
+
.DS_Store
|
|
25
|
+
Thumbs.db
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# {{STACK_NAME}} CDK Infrastructure
|
|
2
|
+
|
|
3
|
+
This directory contains the AWS CDK infrastructure code for deploying {{STACK_NAME}} to AWS.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
The CDK app uses the `PurenowStack` construct from `@worktif/purenow/infra` to provision all required AWS resources:
|
|
8
|
+
|
|
9
|
+
- **S3 Bucket**: Stores static assets and cached SSR responses
|
|
10
|
+
- **Lambda Function**: Handles server-side rendering of React components
|
|
11
|
+
- **CloudFront Distribution**: CDN for global content delivery
|
|
12
|
+
- **DynamoDB Table**: (Optional) Stores SEO metadata when `enableSeo` is true
|
|
13
|
+
- **IAM Roles**: Least-privilege permissions for Lambda execution
|
|
14
|
+
|
|
15
|
+
## Prerequisites
|
|
16
|
+
|
|
17
|
+
1. **AWS CLI**: Install and configure AWS CLI with your credentials
|
|
18
|
+
```bash
|
|
19
|
+
aws configure
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
2. **Node.js**: Version 18 or higher
|
|
23
|
+
|
|
24
|
+
3. **AWS CDK**: Install globally (optional, can use npx)
|
|
25
|
+
```bash
|
|
26
|
+
npm install -g aws-cdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Getting Started
|
|
30
|
+
|
|
31
|
+
**Good news!** If you initialized this CDK app using `purenow init`, all dependencies have already been installed automatically. You can skip directly to deployment!
|
|
32
|
+
|
|
33
|
+
### 1. Verify Installation (Already Done!)
|
|
34
|
+
|
|
35
|
+
During initialization, Purenow automatically:
|
|
36
|
+
- ✓ Installed all project dependencies (React, Purenow, etc.)
|
|
37
|
+
- ✓ Installed all CDK dependencies (aws-cdk-lib, constructs, etc.)
|
|
38
|
+
- ✓ Validated that all packages are correctly installed
|
|
39
|
+
|
|
40
|
+
If you need to reinstall dependencies manually:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Install project dependencies (from project root)
|
|
44
|
+
cd ..
|
|
45
|
+
npm install
|
|
46
|
+
|
|
47
|
+
# Install CDK dependencies
|
|
48
|
+
cd cdk
|
|
49
|
+
npm install
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 2. Bootstrap CDK (First Time Only)
|
|
53
|
+
|
|
54
|
+
Bootstrap provisions the CDK toolkit resources in your AWS account:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
cdk bootstrap
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
This only needs to be done once per AWS account/region combination.
|
|
61
|
+
|
|
62
|
+
**Note**: If you chose to run bootstrap during initialization, this step is already complete!
|
|
63
|
+
|
|
64
|
+
### 3. Deploy Infrastructure
|
|
65
|
+
|
|
66
|
+
Deploy to the default stage (dev):
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
cdk deploy --all
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Deploy to a specific stage:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npm run deploy:dev # Deploy to dev
|
|
76
|
+
npm run deploy:staging # Deploy to staging
|
|
77
|
+
npm run deploy:prod # Deploy to prod
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 4. View Deployment Outputs
|
|
81
|
+
|
|
82
|
+
After deployment, CDK will display important outputs:
|
|
83
|
+
|
|
84
|
+
- **CloudFront URL**: Your application's public URL
|
|
85
|
+
- **S3 Bucket Name**: Where static assets are stored
|
|
86
|
+
- **Lambda Function ARN**: The SSR handler function
|
|
87
|
+
|
|
88
|
+
## Configuration
|
|
89
|
+
|
|
90
|
+
### Main Configuration (bin/app.ts)
|
|
91
|
+
|
|
92
|
+
The CDK app is configured in `bin/app.ts`. Key properties:
|
|
93
|
+
|
|
94
|
+
- **stage**: Environment name (`dev`, `staging`, `prod`)
|
|
95
|
+
- Affects resource naming and removal policies
|
|
96
|
+
- Production stages have stricter retention policies
|
|
97
|
+
|
|
98
|
+
- **serviceName**: Identifier for your service
|
|
99
|
+
- Used as prefix for all AWS resources
|
|
100
|
+
- Example: `my-app` → `my-app-static-dev`, `my-app-ssr-handler-dev`
|
|
101
|
+
|
|
102
|
+
- **enableSeo**: Enable SEO features
|
|
103
|
+
- Creates DynamoDB table for SEO metadata
|
|
104
|
+
- Enables server-side rendering of meta tags
|
|
105
|
+
|
|
106
|
+
- **env.account**: AWS account ID
|
|
107
|
+
- Defaults to `CDK_DEFAULT_ACCOUNT` environment variable
|
|
108
|
+
- Can be hardcoded for specific environments
|
|
109
|
+
|
|
110
|
+
- **env.region**: AWS region
|
|
111
|
+
- Resolved from AWS SDK default provider chain (AWS_REGION env var, ~/.aws/config)
|
|
112
|
+
- Set to `{{REGION}}` during initialization based on your AWS configuration
|
|
113
|
+
- Common values: `us-east-1`, `us-west-2`, `eu-west-1`, `eu-central-1`
|
|
114
|
+
|
|
115
|
+
### Optional Configuration
|
|
116
|
+
|
|
117
|
+
Uncomment these in `bin/app.ts` to customize:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// Increase Lambda memory (default: 512 MB)
|
|
121
|
+
lambdaMemorySize: 1024,
|
|
122
|
+
|
|
123
|
+
// Increase Lambda timeout (default: 29 seconds)
|
|
124
|
+
lambdaTimeout: 60,
|
|
125
|
+
|
|
126
|
+
// Add custom environment variables
|
|
127
|
+
customEnvironmentVariables: {
|
|
128
|
+
MY_API_KEY: 'value',
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
// Configure custom domain
|
|
132
|
+
domainName: 'example.com',
|
|
133
|
+
certificateArn: 'arn:aws:acm:...',
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## Multiple Stages
|
|
137
|
+
|
|
138
|
+
To deploy multiple stages (dev, staging, prod), duplicate the stack instantiation in `bin/app.ts`:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
// Dev stage
|
|
142
|
+
new PurenowStack(app, `${serviceName}-dev`, {
|
|
143
|
+
stage: 'dev',
|
|
144
|
+
serviceName,
|
|
145
|
+
enableSeo: true,
|
|
146
|
+
env: { account: '...', region: '{{REGION}}' },
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// Staging stage
|
|
150
|
+
new PurenowStack(app, `${serviceName}-staging`, {
|
|
151
|
+
stage: 'staging',
|
|
152
|
+
serviceName,
|
|
153
|
+
enableSeo: true,
|
|
154
|
+
env: { account: '...', region: '{{REGION}}' },
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// Production stage
|
|
158
|
+
new PurenowStack(app, `${serviceName}-prod`, {
|
|
159
|
+
stage: 'prod',
|
|
160
|
+
serviceName,
|
|
161
|
+
enableSeo: true,
|
|
162
|
+
env: { account: '...', region: '{{REGION}}' },
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Useful Commands
|
|
167
|
+
|
|
168
|
+
- `npm run build`: Compile TypeScript to JavaScript
|
|
169
|
+
- `npm run watch`: Watch for changes and compile
|
|
170
|
+
- `cdk synth`: Synthesize CloudFormation template
|
|
171
|
+
- `cdk diff --all`: Compare deployed stack with current state
|
|
172
|
+
- `cdk deploy --all`: Deploy stack to AWS
|
|
173
|
+
- `cdk destroy`: Remove all resources (use with caution!)
|
|
174
|
+
|
|
175
|
+
## Troubleshooting
|
|
176
|
+
|
|
177
|
+
### "Unable to resolve AWS account"
|
|
178
|
+
|
|
179
|
+
**Problem**: CDK can't determine your AWS account ID.
|
|
180
|
+
|
|
181
|
+
**Solution**: Set environment variables or configure AWS CLI:
|
|
182
|
+
```bash
|
|
183
|
+
# Option 1: Set environment variables
|
|
184
|
+
export CDK_DEFAULT_ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
|
|
185
|
+
export AWS_REGION={{REGION}}
|
|
186
|
+
|
|
187
|
+
# Option 2: Configure AWS CLI (recommended)
|
|
188
|
+
aws configure set region {{REGION}}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### "Stack already exists"
|
|
192
|
+
|
|
193
|
+
**Problem**: A stack with the same name already exists.
|
|
194
|
+
|
|
195
|
+
**Solution**: CDK will update the existing stack. Use `cdk diff` to preview changes.
|
|
196
|
+
|
|
197
|
+
### "Insufficient permissions"
|
|
198
|
+
|
|
199
|
+
**Problem**: Your AWS credentials don't have required permissions.
|
|
200
|
+
|
|
201
|
+
**Solution**: Ensure your IAM user/role has permissions for:
|
|
202
|
+
- CloudFormation
|
|
203
|
+
- S3
|
|
204
|
+
- Lambda
|
|
205
|
+
- CloudFront
|
|
206
|
+
- DynamoDB (if enableSeo is true)
|
|
207
|
+
- IAM (for creating roles)
|
|
208
|
+
|
|
209
|
+
### "Lambda bundle not found"
|
|
210
|
+
|
|
211
|
+
**Problem**: The Lambda bundle hasn't been built.
|
|
212
|
+
|
|
213
|
+
**Solution**: Build your Purenow application first:
|
|
214
|
+
```bash
|
|
215
|
+
cd ..
|
|
216
|
+
npm run build
|
|
217
|
+
cd cdk
|
|
218
|
+
cdk deploy --all
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
### "Dependencies not installed"
|
|
222
|
+
|
|
223
|
+
**Problem**: CDK dependencies are missing or corrupted.
|
|
224
|
+
|
|
225
|
+
**Solution**:
|
|
226
|
+
|
|
227
|
+
If you initialized with `purenow init`, dependencies should already be installed. If you're experiencing issues:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# Reinstall project dependencies
|
|
231
|
+
cd ..
|
|
232
|
+
rm -rf node_modules package-lock.json
|
|
233
|
+
npm install
|
|
234
|
+
|
|
235
|
+
# Reinstall CDK dependencies
|
|
236
|
+
cd cdk
|
|
237
|
+
rm -rf node_modules package-lock.json
|
|
238
|
+
npm install
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### "Package manager mismatch"
|
|
242
|
+
|
|
243
|
+
**Problem**: Different package managers used in project vs CDK directory.
|
|
244
|
+
|
|
245
|
+
**Solution**:
|
|
246
|
+
|
|
247
|
+
Purenow automatically detects your package manager (npm, yarn, or pnpm) and uses it consistently. If you need to switch:
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# For npm
|
|
251
|
+
rm -rf node_modules package-lock.json yarn.lock pnpm-lock.yaml
|
|
252
|
+
npm install
|
|
253
|
+
|
|
254
|
+
# For yarn
|
|
255
|
+
rm -rf node_modules package-lock.json yarn.lock pnpm-lock.yaml
|
|
256
|
+
yarn install
|
|
257
|
+
|
|
258
|
+
# For pnpm
|
|
259
|
+
rm -rf node_modules package-lock.json yarn.lock pnpm-lock.yaml
|
|
260
|
+
pnpm install
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Learn More
|
|
264
|
+
|
|
265
|
+
- [AWS CDK Documentation](https://docs.aws.amazon.com/cdk/)
|
|
266
|
+
- [Purenow Documentation](https://github.com/worktif/purenow)
|
|
267
|
+
- [PurenowStack API Reference](https://github.com/worktif/purenow/blob/main/docs/CDK_USAGE.md)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
|
|
4
|
+
import * as cdk from 'aws-cdk-lib';
|
|
5
|
+
|
|
6
|
+
import { PurenowInfraStack, RuntimeWebStack, PurenowRuntimeStack, sanitizeStackName } from '@worktif/purenow/infra';
|
|
7
|
+
import { getStage } from '@worktif/purenow/bin';
|
|
8
|
+
|
|
9
|
+
import { UsersTies } from '../../src/ties/users.ties';
|
|
10
|
+
import { createUserHandler, deleteUserHandler, getUserHandler, updateUserHandler } from '../../src/handlers/users';
|
|
11
|
+
import runtimeConfig from '../../purenow.config';
|
|
12
|
+
|
|
13
|
+
const app = new cdk.App();
|
|
14
|
+
|
|
15
|
+
// Stage name used for naming and environment separation.
|
|
16
|
+
// Common values: 'dev', 'staging', 'prod'
|
|
17
|
+
// const stage = '{{STAGE}}';
|
|
18
|
+
const stage = app.node.tryGetContext('stage') || process.env.STAGE || '{{STAGE}}';
|
|
19
|
+
|
|
20
|
+
// Service identifier used for resource naming, tags, etc.
|
|
21
|
+
// This will be used as a prefix for all AWS resources (e.g., my-app-static-dev)
|
|
22
|
+
export const serviceName = sanitizeStackName(runtimeConfig.projectName);
|
|
23
|
+
|
|
24
|
+
// Enable SEO-ready features in the frontend (e.g. metadata, sitemaps).
|
|
25
|
+
// When enabled, creates a DynamoDB table for storing SEO metadata.
|
|
26
|
+
const enableSeo = {{ENABLE_SEO}};
|
|
27
|
+
|
|
28
|
+
// AWS environment configuration
|
|
29
|
+
const env = {
|
|
30
|
+
// Account ID from AWS credentials
|
|
31
|
+
account: process.env.CDK_DEFAULT_ACCOUNT,
|
|
32
|
+
// Region resolved from AWS SDK default provider chain (env vars, config file, etc.)
|
|
33
|
+
region: getStage(runtimeConfig, stage).awsRegion || '{{REGION}}' || 'us-east-1',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Create the Infrastructure stack (S3, DynamoDB, CloudFront, IAM)
|
|
37
|
+
// This stack contains slow-changing infrastructure resources
|
|
38
|
+
const infraStack = new PurenowInfraStack(app, `${serviceName}-PurenowInfra-${stage}`, {
|
|
39
|
+
// Stage name (dev, staging, prod)
|
|
40
|
+
stage: stage as 'dev' | 'staging' | 'prod',
|
|
41
|
+
|
|
42
|
+
// Service name for resource identification
|
|
43
|
+
serviceName,
|
|
44
|
+
|
|
45
|
+
// Enable SEO features (DynamoDB table for metadata)
|
|
46
|
+
enableSeo,
|
|
47
|
+
|
|
48
|
+
// AWS environment configuration
|
|
49
|
+
env,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Create the Runtime stack (Lambda functions, Lambda Layers, API Gateway)
|
|
53
|
+
// This stack contains fast-changing runtime resources
|
|
54
|
+
// It imports values from the Infrastructure stack via cross-stack references
|
|
55
|
+
const runtimeStack = new PurenowRuntimeStack(app, `${serviceName}-PurenowRuntime-${stage}`, {
|
|
56
|
+
// Stage name (dev, staging, prod)
|
|
57
|
+
stage: stage as 'dev' | 'staging' | 'prod',
|
|
58
|
+
|
|
59
|
+
// Service name for resource identification
|
|
60
|
+
serviceName,
|
|
61
|
+
|
|
62
|
+
// Enable SEO features (must match infraStack)
|
|
63
|
+
enableSeo,
|
|
64
|
+
|
|
65
|
+
// App entry point - the file where you call purenow() to configure your app
|
|
66
|
+
// This enables automatic Lambda bundling by the CDK stack
|
|
67
|
+
appEntryPoint: './src/index.tsx',
|
|
68
|
+
|
|
69
|
+
// API Gateway configuration
|
|
70
|
+
// Enable API Gateway for proper routing, CORS, and Lambda warmup
|
|
71
|
+
enableApiGateway: true,
|
|
72
|
+
|
|
73
|
+
// Enable Lambda warmup (reduces cold starts)
|
|
74
|
+
// Recommended: true for staging/prod, false for dev to reduce costs
|
|
75
|
+
enableWarmup: stage !== 'dev',
|
|
76
|
+
|
|
77
|
+
// Reference to Infrastructure stack for cross-stack references
|
|
78
|
+
infraStack,
|
|
79
|
+
|
|
80
|
+
// AWS environment configuration
|
|
81
|
+
env,
|
|
82
|
+
|
|
83
|
+
// Optional: Customize Lambda configuration
|
|
84
|
+
// lambdaMemorySize: 512, // Memory in MB (default: 512)
|
|
85
|
+
// lambdaTimeout: 29, // Timeout in seconds (default: 29)
|
|
86
|
+
|
|
87
|
+
// Optional: Add custom environment variables for Lambda
|
|
88
|
+
// customEnvironmentVariables: {
|
|
89
|
+
// MY_CUSTOM_VAR: 'value',
|
|
90
|
+
// },
|
|
91
|
+
|
|
92
|
+
// Optional: Configure CORS allowed origins for production
|
|
93
|
+
// allowedOrigins: ['https://example.com', 'https://www.example.com'],
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Create the Runtime Web stack
|
|
97
|
+
// This stack maps high-level "register" configuration to concrete Lambda routes
|
|
98
|
+
// It reuses shared infrastructure from the Infrastructure stack via cross-stack references
|
|
99
|
+
const runtimeWebStack = new RuntimeWebStack(app, `${serviceName}-RuntimeWeb-${stage}`, {
|
|
100
|
+
// Stage name (dev, staging, prod)
|
|
101
|
+
// Must be consistent with other stacks in the same environment
|
|
102
|
+
stage: stage as 'dev' | 'staging' | 'prod',
|
|
103
|
+
|
|
104
|
+
// Service name for resource identification
|
|
105
|
+
// Used as a prefix for Runtime Web resources (Lambdas, logs, etc.)
|
|
106
|
+
serviceName,
|
|
107
|
+
|
|
108
|
+
// Reference to Infrastructure stack for shared resources (tables, buckets, queues, etc.)
|
|
109
|
+
infraStack,
|
|
110
|
+
|
|
111
|
+
// AWS environment configuration (account + region)
|
|
112
|
+
// Should match the env used in Infrastructure and Runtime stacks
|
|
113
|
+
env,
|
|
114
|
+
|
|
115
|
+
// Runtime Web "register" configuration:
|
|
116
|
+
// microservice registry with service definition
|
|
117
|
+
register: {
|
|
118
|
+
// "payments" domain – logical microservice of routes / operations for payments | @example
|
|
119
|
+
payments: {
|
|
120
|
+
// Ties – shared domain models / dependencies used by this module
|
|
121
|
+
// These are injected into all related Lambdas
|
|
122
|
+
ties: [UsersTies],
|
|
123
|
+
|
|
124
|
+
// Lambda handlers for the "payments" domain
|
|
125
|
+
// Each handler is wired into the API according to the Runtime Web conventions
|
|
126
|
+
lambdas: [
|
|
127
|
+
createUserHandler,
|
|
128
|
+
getUserHandler,
|
|
129
|
+
updateUserHandler,
|
|
130
|
+
deleteUserHandler,
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
// API mode – how Runtime Web exposes HTTP endpoints
|
|
136
|
+
// 'apiGateway' uses Amazon API Gateway (recommended for production)
|
|
137
|
+
apiMode: 'apiGateway',
|
|
138
|
+
|
|
139
|
+
// Default memory size (in MB) for Lambda functions managed by Runtime Web
|
|
140
|
+
// Tune per workload if needed for performance / cost optimization
|
|
141
|
+
lambdaMemorySize: 512,
|
|
142
|
+
|
|
143
|
+
// Default Lambda timeout (in seconds) for Runtime Web handlers
|
|
144
|
+
// Should cover typical request latency including external integrations
|
|
145
|
+
lambdaTimeout: 30,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// To add more stages (staging, prod), duplicate the stack instantiation:
|
|
149
|
+
// const infraStackStaging = new PurenowInfraStack(app, 'PurenowInfra-staging', {
|
|
150
|
+
// stage: 'staging',
|
|
151
|
+
// serviceName,
|
|
152
|
+
// enableSeo: true,
|
|
153
|
+
// env: {
|
|
154
|
+
// account: process.env.CDK_DEFAULT_ACCOUNT,
|
|
155
|
+
// region: '{{REGION}}', // Same region as dev, or specify different region
|
|
156
|
+
// },
|
|
157
|
+
// });
|
|
158
|
+
//
|
|
159
|
+
// const runtimeStackStaging = new PurenowRuntimeStack(app, 'PurenowRuntime-staging', {
|
|
160
|
+
// stage: 'staging',
|
|
161
|
+
// serviceName,
|
|
162
|
+
// enableSeo: true,
|
|
163
|
+
// appEntryPoint: './src/index.tsx',
|
|
164
|
+
// enableApiGateway: true,
|
|
165
|
+
// enableWarmup: true,
|
|
166
|
+
// infraStack: infraStackStaging,
|
|
167
|
+
// env: {
|
|
168
|
+
// account: process.env.CDK_DEFAULT_ACCOUNT,
|
|
169
|
+
// region: '{{REGION}}',
|
|
170
|
+
// },
|
|
171
|
+
// });
|
|
172
|
+
|
|
173
|
+
app.synth();
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"app": "npx ts-node --prefer-ts-exts bin/app.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
|
+
"yarn.lock",
|
|
15
|
+
"node_modules",
|
|
16
|
+
"test"
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"notices": false,
|
|
20
|
+
"context": {
|
|
21
|
+
"@aws-cdk/aws-lambda:recognizeLayerVersion": true,
|
|
22
|
+
"@aws-cdk/core:checkSecretUsage": true,
|
|
23
|
+
"@aws-cdk/core:target-partitions": [
|
|
24
|
+
"aws",
|
|
25
|
+
"aws-cn"
|
|
26
|
+
],
|
|
27
|
+
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
|
|
28
|
+
"@aws-cdk/core:stackRelativeExports": true,
|
|
29
|
+
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
|
|
30
|
+
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
|
|
31
|
+
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
|
|
32
|
+
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
|
|
33
|
+
"@aws-cdk/aws-ec2:uniqueImdsv2TemplateName": true,
|
|
34
|
+
"@aws-cdk/aws-ecs:arnFormatIncludesClusterName": true,
|
|
35
|
+
"@aws-cdk/aws-iam:minimizePolicies": true,
|
|
36
|
+
"@aws-cdk/core:validateSnapshotRemovalPolicy": true,
|
|
37
|
+
"@aws-cdk/aws-codepipeline:crossAccountKeyAliasStackSafeResourceName": true,
|
|
38
|
+
"@aws-cdk/aws-s3:createDefaultLoggingPolicy": true,
|
|
39
|
+
"@aws-cdk/aws-sns-subscriptions:restrictSqsDescryption": true,
|
|
40
|
+
"@aws-cdk/aws-apigateway:disableCloudWatchRole": true,
|
|
41
|
+
"@aws-cdk/core:enablePartitionLiterals": true,
|
|
42
|
+
"@aws-cdk/aws-events:eventsTargetQueueSameAccount": true,
|
|
43
|
+
"@aws-cdk/aws-iam:standardizedServicePrincipals": true,
|
|
44
|
+
"@aws-cdk/aws-ecs:disableExplicitDeploymentControllerForCircuitBreaker": true,
|
|
45
|
+
"@aws-cdk/aws-iam:importedRoleStackSafeDefaultPolicyName": true,
|
|
46
|
+
"@aws-cdk/aws-s3:serverAccessLogsUseBucketPolicy": true,
|
|
47
|
+
"@aws-cdk/aws-route53-patters:useCertificate": true,
|
|
48
|
+
"@aws-cdk/customresources:installLatestAwsSdkDefault": false,
|
|
49
|
+
"@aws-cdk/aws-rds:databaseProxyUniqueResourceName": true,
|
|
50
|
+
"@aws-cdk/aws-codedeploy:removeAlarmsFromDeploymentGroup": true,
|
|
51
|
+
"@aws-cdk/aws-apigateway:authorizerChangeDeploymentLogicalId": true,
|
|
52
|
+
"@aws-cdk/aws-ec2:launchTemplateDefaultUserData": true,
|
|
53
|
+
"@aws-cdk/aws-secretsmanager:useAttachedSecretResourcePolicyForSecretTargetAttachments": true,
|
|
54
|
+
"@aws-cdk/aws-redshift:columnId": true,
|
|
55
|
+
"@aws-cdk/aws-stepfunctions-tasks:enableEmrServicePolicyV2": true,
|
|
56
|
+
"@aws-cdk/aws-ec2:restrictDefaultSecurityGroup": true,
|
|
57
|
+
"@aws-cdk/aws-apigateway:requestValidatorUniqueId": true,
|
|
58
|
+
"@aws-cdk/aws-kms:aliasNameRef": true,
|
|
59
|
+
"@aws-cdk/aws-autoscaling:generateLaunchTemplateInsteadOfLaunchConfig": true,
|
|
60
|
+
"@aws-cdk/core:includePrefixInUniqueNameGeneration": true,
|
|
61
|
+
"@aws-cdk/aws-efs:denyAnonymousAccess": true,
|
|
62
|
+
"@aws-cdk/aws-opensearchservice:enableOpensearchMultiAzWithStandby": true,
|
|
63
|
+
"@aws-cdk/aws-lambda-nodejs:useLatestRuntimeVersion": true,
|
|
64
|
+
"@aws-cdk/aws-efs:mountTargetOrderInsensitiveLogicalId": true,
|
|
65
|
+
"@aws-cdk/aws-rds:auroraClusterChangeScopeOfInstanceParameterGroupWithEachParameters": true,
|
|
66
|
+
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
|
|
67
|
+
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
|
|
68
|
+
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
|
|
69
|
+
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
|
|
70
|
+
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true,
|
|
71
|
+
"@aws-cdk/aws-codepipeline:defaultPipelineTypeToV2": true,
|
|
72
|
+
"@aws-cdk/aws-kms:reduceCrossAccountRegionPolicyScope": true,
|
|
73
|
+
"@aws-cdk/aws-eks:nodegroupNameAttribute": true,
|
|
74
|
+
"@aws-cdk/aws-ec2:ebsDefaultGp3Volume": true,
|
|
75
|
+
"@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm": true,
|
|
76
|
+
"@aws-cdk/custom-resources:logApiResponseDataPropertyTrueDefault": false,
|
|
77
|
+
"@aws-cdk/aws-s3:keepNotificationInImportedBucket": false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "{{STACK_NAME}}-cdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"description": "CDK infrastructure for {{STACK_NAME}}",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsc",
|
|
8
|
+
"watch": "tsc -w",
|
|
9
|
+
"synth": "cdk synth",
|
|
10
|
+
"deploy": "cdk deploy --all",
|
|
11
|
+
"deploy:dev": "cdk deploy --context stage=dev --all",
|
|
12
|
+
"deploy:staging": "cdk deploy --context stage=staging --all",
|
|
13
|
+
"deploy:prod": "cdk deploy --context stage=prod --all",
|
|
14
|
+
"diff": "cdk diff",
|
|
15
|
+
"destroy": "cdk destroy"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/node": "^20.0.0",
|
|
19
|
+
"aws-cdk": "^2.100.0",
|
|
20
|
+
"ts-node": "^10.9.0",
|
|
21
|
+
"typescript": "^5.0.0"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@worktif/purenow": "^{{PURENOW_VERSION}}",
|
|
25
|
+
"aws-cdk-lib": "^2.100.0",
|
|
26
|
+
"constructs": "^10.0.0"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": [
|
|
6
|
+
"ES2020"
|
|
7
|
+
],
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noImplicitAny": true,
|
|
11
|
+
"strictNullChecks": true,
|
|
12
|
+
"noImplicitThis": true,
|
|
13
|
+
"alwaysStrict": true,
|
|
14
|
+
"noUnusedLocals": false,
|
|
15
|
+
"noUnusedParameters": false,
|
|
16
|
+
"noImplicitReturns": true,
|
|
17
|
+
"noFallthroughCasesInSwitch": false,
|
|
18
|
+
"inlineSourceMap": true,
|
|
19
|
+
"inlineSources": true,
|
|
20
|
+
"experimentalDecorators": true,
|
|
21
|
+
"strictPropertyInitialization": false,
|
|
22
|
+
"typeRoots": [
|
|
23
|
+
"./node_modules/@types"
|
|
24
|
+
],
|
|
25
|
+
"moduleResolution": "node16",
|
|
26
|
+
"resolveJsonModule": true,
|
|
27
|
+
"esModuleInterop": true,
|
|
28
|
+
"skipLibCheck": true,
|
|
29
|
+
"forceConsistentCasingInFileNames": true
|
|
30
|
+
},
|
|
31
|
+
"include": [
|
|
32
|
+
"bin/**/*.ts"
|
|
33
|
+
],
|
|
34
|
+
"exclude": [
|
|
35
|
+
"node_modules",
|
|
36
|
+
"cdk.out"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Application Configuration
|
|
2
|
+
PURE_ENV_STACK_NAME=purenow-app
|
|
3
|
+
PURE_ENV_STAGE=dev
|
|
4
|
+
|
|
5
|
+
# AWS Configuration (optional - can be set via AWS CLI or ~/.aws/config)
|
|
6
|
+
# AWS_REGION=us-east-1 # Or eu-central-1, us-west-2, etc.
|
|
7
|
+
# AWS_PROFILE=default
|
|
8
|
+
|
|
9
|
+
# Development Server
|
|
10
|
+
# PORT=3000
|
|
11
|
+
|
|
12
|
+
# Feature Flags (optional)
|
|
13
|
+
# PURE_ENV_ENABLE_SEO=false
|
|
14
|
+
# PURE_ENV_ENABLE_MANIFEST=true
|
|
15
|
+
# PURE_ENV_ENABLE_WARMUP=false
|