Gathering detailed insights and metrics for cdk-nuxt
Gathering detailed insights and metrics for cdk-nuxt
Gathering detailed insights and metrics for cdk-nuxt
Gathering detailed insights and metrics for cdk-nuxt
@thunderso/cdk-nuxt
Deploy Nuxt 3 on Lambda and S3 using AWS CDK
@phila/cdk-ui-nuxt
@thunderso/nuxt-lambda
<p> <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> <a href="https://www.npmjs.c
npm install cdk-nuxt
Typescript
Module System
TypeScript (89.46%)
JavaScript (10.54%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
20 Stars
274 Commits
3 Forks
3 Watchers
2 Branches
2 Contributors
Updated on May 18, 2025
Latest Version
2.4.0
Package Id
cdk-nuxt@2.4.0
Unpacked Size
542.04 kB
Size
146.70 kB
File Count
115
Published on
Nov 12, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
4
Easily deploy Nuxt 3 applications via CDK on AWS including the following features:
Install the package and its required dependencies:
1yarn add cdk-nuxt --dev # The package itself 2yarn add ts-node typescript --dev # To compile the CDK stacks via typescript 3yarn add aws-cdk@2.166.0 --dev # CDK cli with this exact version for the deployment
Set the Nitro preset on your Nuxt configuration file (nuxt.config.js
) to aws-lambda
:
1export default defineNuxtConfig({
2 ...
3 nitro: {
4 preset: 'aws-lambda'
5 },
6 ...
7});
See https://nitro.unjs.io/deploy/providers/aws for more details.
Remove "type": "module"
from your package.json
file, if it exists.
This is required to make the CDK stack work. Click here for details.
Create an AWS account, if you don't have one yet. Then login into the AWS console and note the Account ID
. You will need it in step 7.
Create a hosted zone in Route53 for the desired domain, if you don't have one yet.
This is required to create DNS records for the domain to make the Nuxt app publicly available on that domain.
On the hosted zone details you should see the Hosted zone ID
of the hosted zone. You will need it in step 7.
Request a public regional certificate in the AWS Certificate Manager (ACM) for the desired domain in your desired region, e.g., eu-central-1
, and validate it, if you don't have one yet.
This is required to make the Nuxt app accessible via the custom domain and to provide the custom domain to the Nuxt app via the 'Host' header for server side rendering use cases.
Take note of the displayed ARN
for the certificate. You will need it in step 7.
Request a public global certificate in the AWS Certificate Manager (ACM) for the desired domain in us-east-1
(global) and validate it, if you don't have one yet.
This is required to provide the Nuxt app via HTTPS on the public internet.
Take note of the displayed ARN
for the certificate. You will need it in step 7.
Important: The certificate must be issued in us-east-1 (global) regardless of the region used for the Nuxt app itself as it will be attached to the Cloudfront distribution which works globally.
Run the following command to automatically create the required CDK stack entrypoint at stack/index.ts
. This file defines the config how the Nuxt app will be deployed via CDK. You should adapt the file to the project's needs, especially the props env.account
(setup step 3), hostedZoneId
(setup step 4), regionalTlsCertificateArn
(setup step 5) and globalTlsCertificateArn
(setup step 6).
1node_modules/.bin/cdk-nuxt-init-server
:warning: It's recommended using a
.env
file or another secrets file to import the sensitive secrets into thestack/index.ts
file.
The NuxtServerAppStack
construct can be configured via the following props:
A string identifier for the project the Nuxt app is part of. A project might have multiple different services.
A string identifier for the project's service the Nuxt app is created for. This can be seen as the name of the Nuxt app.
A string to identify the environment of the Nuxt app. This enables us to deploy multiple different environments of the same Nuxt app, e.g., production and development.
The domain (without the protocol) at which the Nuxt app shall be publicly available. A DNS record will be automatically created in Route53 for the domain. This also supports subdomains. Examples: "example.com", "sub.example.com"
The id of the hosted zone to create a DNS record for the specified domain.
The ARN of the certificate to use on CloudFront for the Nuxt app to make it accessible via HTTPS. The certificate must be issued for the specified domain in us-east-1 (global) regardless of the region specified via 'env.region' as CloudFront only works globally.
The ARN of the certificate to use at the ApiGateway for the Nuxt app to make it accessible via the custom domain and to provide the custom domain to the Nuxt app via the 'Host' header for server side rendering use cases. The certificate must be issued in the same region as specified via 'env.region' as ApiGateway works regionally.
The path to the root directory of the Nuxt app (at which the nuxt.config.ts
file is located).
Defaults to '.'.
The file name (without extension) of the Lambda entrypoint within the 'server' directory exporting a handler. Defaults to "index".
A JSON serialized string of environment variables to pass to the Lambda function.
The memory size to apply to the Nuxt app's Lambda. Defaults to 1792MB (optimized for costs and performance for standard Nuxt apps).
Whether to enable AWS X-Ray for the Nuxt Lambda function.
Whether to enable (HTTPS only) API access to the Nuxt app via the /api
path which support all HTTP methods.
See https://nuxt.com/docs/guide/directory-structure/server#recipes for details.
Whether to enable a global Sitemap bucket which is permanently accessible through multiple deployments.
Whether to enable access logs analysis for the Nuxt app's CloudFront distribution via Athena.
An array of cookies to include for reporting in the access logs analysis.
Only has an effect when enableAccessLogsAnalysis
is set to true
.
The number of days to retain static assets of outdated deployments in the S3 bucket. Useful to allow users to still access old assets after a new deployment when they are still browsing on an old version. Defaults to 30 days.
An array of headers to pass to the Nuxt app on SSR requests. The more headers are passed, the weaker the cache performance will be, as the cache key is based on the headers. No headers are passed by default.
An array of cookies to pass to the Nuxt app on SSR requests. The more cookies are passed, the weaker the cache performance will be, as the cache key is based on the cookies. No cookies are passed by default.
An array of query param keys to pass to the Nuxt app on SSR requests. The more query params are passed, the weaker the cache performance will be, as the cache key is based on the query params. Note that this config can not be combined with {@see denyQueryParams}. If both are specified, the {@see denyQueryParams} will be ignored. All query params are passed by default.
An array of query param keys to deny passing to the Nuxt app on SSR requests. It might be useful to prevent specific external query params, e.g., fbclid, utm_campaign, ..., to improve cache performance, as the cache key is based on the specified query params. Note that this config can not be combined with {@see allowQueryParams}. If both are specified, the {@see denyQueryParams} will be ignored. All query params are passed by default.
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 by following the steps below:
Deploying stacks with the AWS CDK requires dedicated Amazon S3 buckets and other containers to be available to AWS CloudFormation during deployment. Creating these is called bootstrapping and is only required once per account and region. To bootstrap, run the following command:
1cdk bootstrap aws://ACCOUNT-NUMBER/REGION
See https://docs.aws.amazon.com/cdk/v2/guide/getting_started.html for details.
By running the following script, the Nuxt app will be built automatically via yarn build
and the CDK stack will be deployed to AWS.
1node_modules/.bin/cdk-nuxt-deploy-server
Alternatively, you can run the following commands separately to customize the deployment process:
1yarn build 2yarn cdk deploy --require-approval never --all --app="yarn ts-node stack/index.ts"
For example, to run the commands with pnpm
, you can run the following commands:
1```bash 2pnpm build 3pnpm cdk deploy --require-approval never --all --app="pnpm ts-node stack/index.ts"
If you want to destroy the stack and all its resources (including storage, e.g., access logs), run the following script:
1node_modules/.bin/cdk-nuxt-destroy-server
In the following, you can find an overview of the AWS resources that will be created by this package for reference.
This stack is responsible for deploying dynamic Nuxt 3 apps to AWS. The following AWS resources will be created by this stack:
node_modules
of the Nuxt app required for server-side rendering..nuxt/dist/client
) with optimized cache settings.enableAccessLogsAnalysis
is set to true
.A
for IPv4 and AAAA
for IPv6) in the configured hosted zone to make the Nuxt app available on the internet via the configured custom domain.enableAccessLogsAnalysis
is set to true
.In the following, you can find some guidelines for the deployment and usages of this package.
Feel free to copy the following GitHub Actions YAML file content into a YAML file at .github/workflows/deploy.yml
to automatically build and deploy the Nuxt app to AWS on every push to a specific branch.
This only works if you're using GitHub for the project's VCS repository.
1name: Deploy 2 3on: 4 push: 5 branches: 6 - master # Feel free to use another branch name 7 8jobs: 9 build: 10 runs-on: ubuntu-latest 11 steps: 12 - name: Checkout source code 13 uses: actions/checkout@v4 14 15 # Enable if using Yarn >= 2 16 # - name: Enable Corepack for Yarn 17 # run: corepack enable 18 19 - name: Configure Node.js 20 uses: actions/setup-node@v4 21 with: 22 node-version: '20' 23 cache: 'yarn' 24 25 - name: Install dependencies 26 run: yarn install --frozen-lockfile # or `yarn install --immutable` for Yarn >= 2 27 28 - name: Build and deploy to AWS 29 run: node_modules/.bin/cdk-nuxt-deploy-server # Or run a customized deployment, see 'Build and Deploy' section 30 env: 31 # Create an IAM user on AWS for the deployment and create the appropriate secrets in the GitHub repository secrets 32 AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} 33 AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 34 AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
No vulnerabilities found.
No security vulnerabilities found.