Easily deploy Nuxt applications (Nuxt 3 and Nuxt 4) via CDK on AWS, including the following features:
- ⚡ Fast responses via AWS Lambda
- 🌐 Custom domain support via Route53 and CloudFront
- 🔒 Automatic HTTPS with certificate management
- 📦 Optimized static asset delivery via S3
- 🔥 Lambda warming via scheduled EventBridge pings
- 🗑️ Automatic cleanup of outdated assets
- 📊 Access logs analysis via Athena (docs)
- 🛡️ WAF integration for security (docs)
- ⚙️ Flexible caching configuration (docs)
- 📚 Full Configuration Reference
- 🚀 Deployment Guide
- 🛡️ WAF Documentation
- 📊 Access Logs Analysis
- 🔄 Caching Configuration
- ✅ Nuxt 3 (latest stable)
- ✅ Nuxt 4 (RC and stable)
Install the package and its peer dependencies:
# Using pnpm (recommended)
pnpm add -D cdk-nuxt aws-cdk@^2.214.0 aws-cdk-lib@^2.214.0 constructs@^10.4.2 typescript ts-node
# Using npm
npm install --save-dev cdk-nuxt aws-cdk@^2.214.0 aws-cdk-lib@^2.214.0 constructs@^10.4.2 typescript ts-node
# Using yarn
yarn add -D cdk-nuxt aws-cdk@^2.214.0 aws-cdk-lib@^2.214.0 constructs@^10.4.2 typescript ts-nodeOptional: If you plan to enable Access Logs Analysis:
pnpm add -D @aws-cdk/aws-glue-alpha@2.214.0-alpha.0Set the Nitro preset in your nuxt.config.ts:
export default defineNuxtConfig({
nitro: {
preset: 'aws-lambda'
},
});Important: Remove "type": "module" from your package.json if present (why?).
Before deployment, you need:
- AWS Account - Create one if you don't have one
- Route53 Hosted Zone - For your domain (guide)
- SSL Certificates - Two certificates for HTTPS:
Generate the CDK stack configuration:
node_modules/.bin/cdk-nuxt-init-serverThis creates stack/index.ts with a complete template including all available configuration options with sensible defaults.
Update the following required values:
env.accountandenv.region- Your AWS account and regionproject,service,environment- Identifiers for your appdomain- Your custom domainhostedZoneId- Your Route53 hosted zone IDglobalTlsCertificateArn- Certificate in us-east-1 for CloudFrontregionalTlsCertificateArn- Certificate in your region for API Gateway
The full template can also be viewed here: lib/templates/stack-index-server.ts
For a complete list of all configuration options, see the Configuration Reference.
💡 Tip: Use environment variables or a
.envfile to store sensitive values like certificate ARNs and AWS account IDs.
First-time setup (once per AWS account/region):
cdk bootstrap aws://YOUR_ACCOUNT_ID/YOUR_REGIONWhen using the WAF via CloudFrontWafStack and using a different region than
us-east-1, you also need to bootstrapus-east-1for the WAF resources:cdk bootstrap aws://YOUR_ACCOUNT_ID/us-east-1
Deploy your app:
node_modules/.bin/cdk-nuxt-deploy-serverThat's it! Your Nuxt app is now live on AWS. 🎉
For detailed deployment options and CI/CD setup, see the Deployment Guide.
When you deploy your Nuxt app, the following AWS resources are automatically created:
-
Lambda Functions:
- Main SSR function for rendering your Nuxt app
- Lambda Layer for node_modules
- Cleanup function for outdated assets
-
S3 Buckets:
- Static assets bucket (
.nuxt/dist/client) - Access logs bucket (if enabled)
- Static assets bucket (
-
CloudFront:
- Global CDN distribution with HTTPS
- Optimized cache behaviors for static and dynamic content
-
API Gateway:
- HTTP API for Lambda function access
- Custom domain configuration
-
Route53:
- DNS records (A and AAAA) for your domain
-
EventBridge Rules:
- Lambda warming (every 5 minutes)
- Asset cleanup (weekly, Tuesdays at 03:30 GMT)
-
Athena (optional):
- Database and tables for access log analysis
- Automatic log partitioning
-
WAF (optional):
- Web Application Firewall for CloudFront distribution
- Protection against common web exploits, bots, and DDoS attacks
- Configurable managed rules and rate limiting
For more details on each resource and their configuration, see the Deployment Guide.
- Quick Start - Get up and running quickly
- Deployment Guide - Detailed deployment instructions, CI/CD setup
- Configuration Reference - Complete list of all configuration options
- WAF Integration - Protect your app with AWS WAF
- Access Logs Analysis - Analyze traffic with Athena
- Caching Configuration - Optimize performance with CloudFront caching
- Destroy the Stack - Clean up resources
To completely remove all AWS resources created by this package:
node_modules/.bin/cdk-nuxt-destroy-serverContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.