cdk-nuxt 2.4.0 → 2.6.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.
Files changed (43) hide show
  1. package/README.md +133 -46
  2. package/lib/cli/deploy-server.js +9 -2
  3. package/lib/cli/destroy-server.js +8 -1
  4. package/lib/functions/access-logs-analysis/group-by-date/package.json +20 -19
  5. package/lib/functions/access-logs-analysis/group-by-date/pnpm-lock.yaml +1385 -0
  6. package/lib/functions/access-logs-analysis/partitioning/package.json +20 -19
  7. package/lib/functions/access-logs-analysis/partitioning/pnpm-lock.yaml +1122 -0
  8. package/lib/functions/assets-cleanup/package.json +19 -18
  9. package/lib/functions/assets-cleanup/pnpm-lock.yaml +1377 -0
  10. package/lib/stack/access-logs-analysis/AccessLogsAnalysis.js +19 -4
  11. package/lib/stack/access-logs-analysis/AccessLogsAnalysis.ts +23 -5
  12. package/lib/stack/server/NuxtServerAppStack.d.ts +18 -3
  13. package/lib/stack/server/NuxtServerAppStack.js +56 -20
  14. package/lib/stack/server/NuxtServerAppStack.ts +76 -24
  15. package/lib/stack/server/NuxtServerAppStackProps.d.ts +73 -0
  16. package/lib/stack/server/NuxtServerAppStackProps.js +1 -1
  17. package/lib/stack/server/NuxtServerAppStackProps.ts +80 -0
  18. package/lib/templates/stack-index-server.ts +60 -24
  19. package/package.json +44 -42
  20. package/lib/functions/access-logs-analysis/group-by-date/.gitignore +0 -2
  21. package/lib/functions/access-logs-analysis/group-by-date/build/app/index.d.ts +0 -2
  22. package/lib/functions/access-logs-analysis/group-by-date/build/app/index.js +0 -57
  23. package/lib/functions/access-logs-analysis/group-by-date/build/app/index.js.map +0 -1
  24. package/lib/functions/access-logs-analysis/group-by-date/yarn.lock +0 -1253
  25. package/lib/functions/access-logs-analysis/partitioning/.gitignore +0 -2
  26. package/lib/functions/access-logs-analysis/partitioning/build/app/create-partition.d.ts +0 -1
  27. package/lib/functions/access-logs-analysis/partitioning/build/app/create-partition.js +0 -57
  28. package/lib/functions/access-logs-analysis/partitioning/build/app/create-partition.js.map +0 -1
  29. package/lib/functions/access-logs-analysis/partitioning/build/app/transform-partition.d.ts +0 -2
  30. package/lib/functions/access-logs-analysis/partitioning/build/app/transform-partition.js +0 -72
  31. package/lib/functions/access-logs-analysis/partitioning/build/app/transform-partition.js.map +0 -1
  32. package/lib/functions/access-logs-analysis/partitioning/build/app/types.d.ts +0 -7
  33. package/lib/functions/access-logs-analysis/partitioning/build/app/types.js +0 -3
  34. package/lib/functions/access-logs-analysis/partitioning/build/app/types.js.map +0 -1
  35. package/lib/functions/access-logs-analysis/partitioning/build/app/util.d.ts +0 -9
  36. package/lib/functions/access-logs-analysis/partitioning/build/app/util.js +0 -44
  37. package/lib/functions/access-logs-analysis/partitioning/build/app/util.js.map +0 -1
  38. package/lib/functions/access-logs-analysis/partitioning/yarn.lock +0 -1009
  39. package/lib/functions/assets-cleanup/.gitignore +0 -2
  40. package/lib/functions/assets-cleanup/build/app/index.d.ts +0 -1
  41. package/lib/functions/assets-cleanup/build/app/index.js +0 -114
  42. package/lib/functions/assets-cleanup/build/app/index.js.map +0 -1
  43. package/lib/functions/assets-cleanup/yarn.lock +0 -1245
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # AWS CDK Nuxt 3 Deployment Stack
1
+ # AWS CDK Nuxt Deployment Stack (Nuxt 3 & Nuxt 4)
2
2
 
3
3
  <p>
4
4
  <a href="https://github.com/ferdinandfrank/cdk-nuxt/actions/workflows/publish.yml"><img alt="Build" src="https://img.shields.io/github/actions/workflow/status/ferdinandfrank/cdk-nuxt/publish.yml?logo=github" /></a>
@@ -7,7 +7,7 @@
7
7
  <a href="https://www.npmjs.com/package/cdk-nuxt"><img alt="License" src="https://img.shields.io/npm/l/cdk-nuxt.svg" /></a>
8
8
  </p>
9
9
 
10
- Easily deploy Nuxt 3 applications via CDK on AWS including the following features:
10
+ Easily deploy Nuxt applications (Nuxt 3 and Nuxt 4) via CDK on AWS, including the following features:
11
11
 
12
12
  - Fast responses via [AWS Lambda](https://aws.amazon.com/lambda/)
13
13
  - Publicly available by a custom domain (or subdomain) via [Route53](https://aws.amazon.com/route53/) and [API Gateway](https://aws.amazon.com/api-gateway/)
@@ -17,20 +17,61 @@ Easily deploy Nuxt 3 applications via CDK on AWS including the following feature
17
17
  - Automatic cleanup of outdated static assets and build files
18
18
  - Access logs analysis via [Athena](https://aws.amazon.com/athena/) for the Nuxt app's CloudFront distribution
19
19
 
20
+ ## Table of Contents
21
+
22
+ - [Prerequisites](#prerequisites)
23
+ - [Compatibility](#compatibility)
24
+ - [Installation](#installation)
25
+ - [Setup](#setup)
26
+ - [Configuration](#configuration)
27
+ - [Deployment](#deployment)
28
+ - [Destroy the Stack](#destroy-the-stack)
29
+ - [Reference: Created AWS Resources](#reference-created-aws-resources)
30
+ - [Guidelines](#guidelines)
31
+
20
32
  ## Prerequisites
21
33
 
22
34
  - You need an [AWS account](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/?nc1=h_ls) to create and deploy the required resources for the Nuxt app on AWS.
23
- - This readme currently relies on using [Yarn](https://yarnpkg.com/) as a package manager. Feel free to use another package manager, but you have to adapt the commands accordingly.
35
+ - You can use your preferred package manager: pnpm, npm, or Yarn. The examples below show commands for each where relevant.
36
+
37
+ ## Compatibility
38
+
39
+ This package is compatible with the following Nuxt versions:
40
+ - Nuxt 3 (latest stable)
41
+ - Nuxt 4 (RC and stable)
42
+
43
+ Notes:
44
+ - Make sure to set Nitro's preset to `aws-lambda` as shown below.
45
+ - If you encounter any version-specific issues, please open an issue on GitHub.
24
46
 
25
47
  ## Installation
26
48
 
27
- Install the package and its required dependencies:
49
+ Install the package and its required dependencies (choose your package manager):
50
+
51
+ Using pnpm:
52
+ ```bash
53
+ pnpm add -D cdk-nuxt # The package itself
54
+ pnpm add -D ts-node typescript # To compile the CDK stacks via TypeScript
55
+ pnpm add -D aws-cdk@^2.214.0 # Optional: CDK CLI for the deployment (recommended range)
56
+ ```
57
+
58
+ Using npm:
59
+ ```bash
60
+ npm install --save-dev cdk-nuxt # The package itself
61
+ npm install --save-dev ts-node typescript # To compile the CDK stacks via TypeScript
62
+ npm install --save-dev aws-cdk@^2.214.0 # Optional: CDK CLI for the deployment (recommended range)
63
+ ```
64
+
65
+ Using Yarn:
28
66
  ```bash
29
- yarn add cdk-nuxt --dev # The package itself
30
- yarn add ts-node typescript --dev # To compile the CDK stacks via typescript
31
- yarn add aws-cdk@2.166.0 --dev # CDK cli with this exact version for the deployment
67
+ yarn add -D cdk-nuxt # The package itself
68
+ yarn add -D ts-node typescript # To compile the CDK stacks via TypeScript
69
+ yarn add -D aws-cdk@^2.214.0 # Optional: CDK CLI for the deployment (recommended range)
32
70
  ```
33
71
 
72
+ Note: Installing the AWS CDK CLI (aws-cdk) as a devDependency is optional. You can also invoke the CLI via npx (e.g., `npx cdk ...`). Ensure you are using CDK v2.
73
+ This package targets aws-cdk-lib 2.214.x; for best compatibility, keep your project's aws-cdk-lib within the 2.214.x range as well.
74
+
34
75
  ## Setup
35
76
 
36
77
  1. Set the Nitro preset on your Nuxt configuration file (`nuxt.config.js`) to `aws-lambda`:
@@ -125,48 +166,64 @@ Whether to enable access logs analysis for the Nuxt app's CloudFront distributio
125
166
  An array of cookies to include for reporting in the access logs analysis.
126
167
  Only has an effect when `enableAccessLogsAnalysis` is set to `true`.
127
168
 
128
- ### outdatedAssetsRetentionDays?: boolean
169
+ ### outdatedAssetsRetentionDays?: number
129
170
  The number of days to retain static assets of outdated deployments in the S3 bucket.
130
171
  Useful to allow users to still access old assets after a new deployment when they are still browsing on an old version.
131
172
  Defaults to 30 days.
132
173
 
133
- ### allowHeaders?: string[]
134
- An array of headers to pass to the Nuxt app on SSR requests.
135
- The more headers are passed, the weaker the cache performance will be, as the cache key
136
- is based on the headers.
137
- No headers are passed by default.
138
-
139
- ### allowCookies?: string[]
140
- An array of cookies to pass to the Nuxt app on SSR requests.
141
- The more cookies are passed, the weaker the cache performance will be, as the cache key
142
- is based on the cookies.
143
- No cookies are passed by default.
144
-
145
- ### allowQueryParams?: string[]
146
- An array of query param keys to pass to the Nuxt app on SSR requests.
147
- The more query params are passed, the weaker the cache performance will be, as the cache key
148
- is based on the query params.
149
- Note that this config can not be combined with {@see denyQueryParams}.
150
- If both are specified, the {@see denyQueryParams} will be ignored.
151
- All query params are passed by default.
152
-
153
- ### denyQueryParams?: string[]
154
- An array of query param keys to deny passing to the Nuxt app on SSR requests.
155
- It might be useful to prevent specific external query params, e.g., fbclid, utm_campaign, ...,
156
- to improve cache performance, as the cache key is based on the specified query params.
157
- Note that this config can not be combined with {@see allowQueryParams}.
158
- If both are specified, the {@see denyQueryParams} will be ignored.
159
- All query params are passed by default.
174
+ ### forwardHeaders?: string[]
175
+ An array of HTTP headers to forward to the Nuxt app on origin requests without affecting the cache key at CloudFront edge locations.
176
+ This should only be used for headers that do not affect the response.
177
+
178
+ No headers are forwarded by default.
179
+
180
+ ### cacheKeyHeaders?: string[]
181
+ An array of HTTP headers to forward to the Nuxt app and to include in the cache key for objects that are cached at CloudFront edge locations.
182
+ This should be used for headers that might affect the response, e.g., 'Authorization'.
183
+
184
+ No headers are forwarded or included in the cache key by default.
185
+
186
+ ### forwardCookies?: string[]
187
+ An array of cookies to forward to the Nuxt app on origin requests without affecting the cache key at CloudFront edge locations.
188
+ This should only be used for cookies that do not affect the response.
189
+
190
+ No cookies are forwarded by default.
191
+
192
+ ### cacheKeyCookies?: string[]
193
+ An array of cookies to forward to the Nuxt app and to include in the cache key for objects that are cached at CloudFront edge locations.
194
+ This should be used for cookies that might affect the response, e.g., authentication cookies.
195
+
196
+ No cookies are forwarded or included in the cache key by default.
197
+
198
+ ### forwardQueryParams?: string[]
199
+ An array of query params to forward to the Nuxt app on origin requests without affecting the cache key at CloudFront edge locations.
200
+ This should only be used for query params that do not affect the response and are required on SSR requests.
201
+
202
+ All query params are forwarded by default.
203
+
204
+ ### cacheKeyQueryParams?: string[]
205
+ An array of query params to forward to the Nuxt app and to include in the cache key for objects that are cached at CloudFront edge locations.
206
+ This should be used for query params that affect the response and are required on SSR requests, e.g., filters.
207
+
208
+ All query params are forwarded and included in the cache key by default.
209
+
210
+ ### denyCacheKeyQueryParams?: string[]
211
+ An array of query params to prevent forwarding to the Nuxt app and to not include in the cache key for objects that are cached at CloudFront edge locations.
212
+ When set, all query params that are not specified in this array will be forwarded to the Nuxt app and included in the cache key.
213
+ This should be used for query params that do not affect the response and are not required on SSR requests, e.g., 'fbclid' or 'utm_campaign'.
214
+
215
+ If both `cacheKeyQueryParams` and `denyCacheKeyQueryParams` are specified, the `denyCacheKeyQueryParams` will be ignored.
216
+ All query params are forwarded and included in the cache key by default.
160
217
 
161
218
 
162
219
  ## Deployment
163
220
 
164
- After the installation and the setup you are already good to go to build the Nuxt app and to deploy it to AWS with this package
221
+ After the installation and the setup, you are already good to go to build the Nuxt app and to deploy it to AWS with this package
165
222
  by following the steps below:
166
223
 
167
224
  ### 1. Bootstrap CDK
168
225
  Deploying stacks with the AWS CDK requires dedicated Amazon S3 buckets and other containers to be available to AWS CloudFormation during deployment.
169
- Creating these is called bootstrapping and is **only required once** per account and region.
226
+ Creating this is called bootstrapping and is **only required once** per account and region.
170
227
  To bootstrap, run the following command:
171
228
 
172
229
  ```bash
@@ -177,26 +234,53 @@ See https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html for details.
177
234
 
178
235
  ### 2. Build and Deploy
179
236
 
180
- By running the following script, the Nuxt app will be built automatically via `yarn build`
237
+ By running the following script, the Nuxt app will be built (using your package manager's `build` script)
181
238
  and the CDK stack will be deployed to AWS.
182
239
 
183
240
  ```bash
184
241
  node_modules/.bin/cdk-nuxt-deploy-server
185
242
  ```
186
243
 
187
- Alternatively, you can run the following commands separately to customize the deployment process:
244
+ Alternatively, you can run the following commands separately to customize the deployment process. Choose your package manager:
188
245
 
246
+ Using pnpm:
247
+ ```bash
248
+ pnpm build
249
+ pnpm cdk deploy --require-approval never --all --app="pnpm ts-node stack/index.ts"
250
+ ```
251
+
252
+ Using npm:
253
+ ```bash
254
+ npm run build
255
+ npx cdk deploy --require-approval never --all --app="npx ts-node stack/index.ts"
256
+ ```
257
+
258
+ Using Yarn:
189
259
  ```bash
190
260
  yarn build
191
261
  yarn cdk deploy --require-approval never --all --app="yarn ts-node stack/index.ts"
192
262
  ```
193
263
 
194
- For example, to run the commands with `pnpm`, you can run the following commands:
264
+ #### Deploy with a custom TypeScript configuration
265
+ Depending on your Nuxt app's TypeScript configuration and the setup of your stack, you might need a different TypeScript configuration for the CDK stack.
266
+ You can do so by creating a `tsconfig.cdk.json` file in the root directory of your project and adjust the deployment command accordingly (choose your package manager):
195
267
 
196
- ```bash
268
+ Using pnpm:
197
269
  ```bash
198
270
  pnpm build
199
- pnpm cdk deploy --require-approval never --all --app="pnpm ts-node stack/index.ts"
271
+ pnpm cdk deploy --require-approval never --all --app="pnpm ts-node --project=tsconfig.cdk.json stack/index.ts"
272
+ ```
273
+
274
+ Using npm:
275
+ ```bash
276
+ npm run build
277
+ npx cdk deploy --require-approval never --all --app="npx ts-node --project=tsconfig.cdk.json stack/index.ts"
278
+ ```
279
+
280
+ Using Yarn:
281
+ ```bash
282
+ yarn build
283
+ yarn cdk deploy --require-approval never --all --app="yarn ts-node --project=tsconfig.cdk.json stack/index.ts"
200
284
  ```
201
285
 
202
286
  ## Destroy the Stack
@@ -213,8 +297,8 @@ In the following, you can find an overview of the AWS resources that will be cre
213
297
 
214
298
  ### NuxtServerAppStack
215
299
 
216
- This stack is responsible for deploying dynamic Nuxt 3 apps to AWS.
217
- The following AWS resources will be created by this stack:
300
+ This stack is responsible for deploying dynamic Nuxt apps to AWS.
301
+ This stack will create the following AWS resources:
218
302
 
219
303
  - [Lambda](https://aws.amazon.com/lambda/):
220
304
  - A Lambda function to render the Nuxt app including a separated Lambda layer to provide the `node_modules` of the Nuxt app required for server-side rendering.
@@ -261,10 +345,13 @@ jobs:
261
345
  uses: actions/setup-node@v4
262
346
  with:
263
347
  node-version: '20'
264
- cache: 'yarn'
348
+ cache: 'pnpm' # or 'yarn' or 'npm'
265
349
 
266
350
  - name: Install dependencies
267
- run: yarn install --frozen-lockfile # or `yarn install --immutable` for Yarn >= 2
351
+ run: |
352
+ pnpm install --frozen-lockfile
353
+ # or: npm ci
354
+ # or: yarn install --frozen-lockfile # or `yarn install --immutable` for Yarn >= 2
268
355
 
269
356
  - name: Build and deploy to AWS
270
357
  run: node_modules/.bin/cdk-nuxt-deploy-server # Or run a customized deployment, see 'Build and Deploy' section
@@ -5,6 +5,11 @@ const shell = require("shelljs");
5
5
  const logPrefix = 'CDK Nuxt Deployment';
6
6
  shell.echo(`${logPrefix}: Starting deployment for dynamic Nuxt app...`);
7
7
 
8
+ const pm = process.env.npm_config_user_agent?.includes('pnpm') ? 'pnpm' : (process.env.npm_config_user_agent?.includes('yarn') ? 'yarn' : 'npm');
9
+ const buildCmd = pm === 'pnpm' ? 'pnpm build' : pm === 'yarn' ? 'yarn build' : 'npm run build';
10
+ const tsNodeCmd = pm === 'pnpm' ? 'pnpm ts-node' : pm === 'yarn' ? 'yarn ts-node' : 'npx ts-node';
11
+ const cdkCmd = pm === 'pnpm' ? 'pnpm cdk' : pm === 'yarn' ? 'yarn cdk' : 'npx cdk';
12
+
8
13
  const deploymentSourceFolder = '.output/server';
9
14
 
10
15
  // Refresh the cdk output folder to have a clean state and prevent persisting outdated outputs
@@ -13,7 +18,7 @@ shell.rm('-rf', 'cdk.out');
13
18
 
14
19
  // Build the Nuxt app
15
20
  shell.echo(`${logPrefix}: Building app...`);
16
- if (shell.exec('yarn build').code !== 0) {
21
+ if (shell.exec(buildCmd).code !== 0) {
17
22
  shell.echo(`${logPrefix} Error: Building app failed.`);
18
23
  shell.exit(1);
19
24
  }
@@ -26,7 +31,9 @@ if (shell.test('-d', 'server')) {
26
31
 
27
32
  // Run the deployment
28
33
  shell.echo(`${logPrefix}: Deploying to AWS via CDK...`);
29
- if (shell.exec('yarn cdk deploy --require-approval never --all --app="yarn ts-node stack/index.ts" ' + process.argv.slice(2)).code !== 0) {
34
+ const extraArgs = process.argv.slice(2).join(' ');
35
+ const cmd = `${cdkCmd} deploy --require-approval never --all --app="${tsNodeCmd} stack/index.ts" ${extraArgs}`;
36
+ if (shell.exec(cmd).code !== 0) {
30
37
  shell.echo(`${logPrefix} Error: CDK deployment failed.`);
31
38
  shell.exit(1);
32
39
  }
@@ -3,8 +3,15 @@
3
3
  const shell = require("shelljs");
4
4
  const logPrefix = 'CDK Nuxt Destroy';
5
5
 
6
+ const pm = process.env.npm_config_user_agent?.includes('pnpm') ? 'pnpm' : (process.env.npm_config_user_agent?.includes('yarn') ? 'yarn' : 'npm');
7
+ const tsNodeCmd = pm === 'pnpm' ? 'pnpm ts-node' : pm === 'yarn' ? 'yarn ts-node' : 'npx ts-node';
8
+ const cdkCmd = pm === 'pnpm' ? 'pnpm cdk' : pm === 'yarn' ? 'yarn cdk' : 'npx cdk';
9
+
6
10
  shell.echo(`${logPrefix}: Destroying stack on AWS via CDK...`);
7
- if (shell.exec('yarn cdk destroy --require-approval never --all --app="yarn ts-node stack/index.ts" ' + process.argv.slice(2)).code !== 0) {
11
+
12
+ const extraArgs = process.argv.slice(2).join(' ');
13
+ const cmd = `${cdkCmd} destroy --require-approval never --all --app="${tsNodeCmd} stack/index.ts" ${extraArgs}`;
14
+ if (shell.exec(cmd).code !== 0) {
8
15
  shell.echo(`${logPrefix} Error: CDK destroy failed.`);
9
16
  shell.exit(1);
10
17
  }
@@ -1,21 +1,22 @@
1
1
  {
2
- "name": "cdk-nuxt-access-log-analysis-group-by-date",
3
- "version": "1.0.0",
4
- "main": "index.js",
5
- "license": "UNLICENSED",
6
- "private": true,
7
- "scripts": {
8
- "install-layer": "yarn install --frozen-lockfile --production --modules-folder build/layer/nodejs/node_modules",
9
- "build": "tsc --project ./tsconfig.json"
10
- },
11
- "devDependencies": {
12
- "@aws-sdk/client-s3": "^3.689.0",
13
- "@types/aws-lambda": "^8.10.145",
14
- "@types/node": "^20.10",
15
- "ts-node": "^10.9.2",
16
- "typescript": "^5.6.3"
17
- },
18
- "peerDependencies": {
19
- "@aws-sdk/client-s3": "^3"
20
- }
2
+ "name": "cdk-nuxt-access-log-analysis-group-by-date",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "license": "UNLICENSED",
6
+ "private": true,
7
+ "scripts": {
8
+ "install-layer": "pnpm install --frozen-lockfile --prod --modules-dir build/layer/nodejs/node_modules",
9
+ "build": "tsc --project ./tsconfig.json"
10
+ },
11
+ "devDependencies": {
12
+ "@aws-sdk/client-s3": "^3.689.0",
13
+ "@types/aws-lambda": "^8.10.145",
14
+ "@types/node": "^20.10",
15
+ "ts-node": "^10.9.2",
16
+ "typescript": "^5.6.3"
17
+ },
18
+ "peerDependencies": {
19
+ "@aws-sdk/client-s3": "^3"
20
+ },
21
+ "packageManager": "pnpm@10.15.1"
21
22
  }