# OpenNext — Run Next.js on AWS Without Vendor Lock-In > An open-source adapter that packages Next.js applications for deployment on AWS Lambda, CloudFront, and S3, providing a self-hosted alternative to Vercel. ## Install Save as a script file and run: # OpenNext — Run Next.js on AWS Without Vendor Lock-In ## Quick Use ```bash # Install in your Next.js project npm install open-next # Build for AWS deployment npx open-next build # Deploy with SST (recommended) npx sst deploy ``` ## Introduction OpenNext is an open-source adapter that takes a standard Next.js build output and packages it for deployment on AWS infrastructure. It bridges the gap between Next.js features (SSR, ISR, middleware, image optimization) and AWS services (Lambda, CloudFront, S3), giving teams full control over their hosting without sacrificing Next.js capabilities. ## What OpenNext Does - Converts Next.js build output into AWS-compatible Lambda functions - Handles server-side rendering, static generation, and incremental static regeneration on AWS - Supports Next.js middleware via CloudFront Functions or Lambda@Edge - Provides image optimization through a dedicated Lambda function - Manages cache revalidation with SQS or direct invocation patterns ## Architecture Overview OpenNext transforms the Next.js standalone build into a deployment package with three main components: a server function (Lambda) for SSR and API routes, a static asset bucket (S3) for pre-rendered pages and assets, and a CDN distribution (CloudFront) for routing and caching. Middleware runs at the edge via CloudFront Functions. ISR revalidation uses a separate queue-based mechanism to avoid cold-start latency on cache updates. ## Self-Hosting & Configuration - Add open-next as a dependency to your existing Next.js project - Run `npx open-next build` to generate the AWS deployment package - Deploy using SST, CDK, Terraform, or any AWS IaC tool - Configure custom domains and SSL certificates through CloudFront - Tune Lambda memory, timeout, and concurrency settings per function ## Key Features - Supports App Router and Pages Router with full SSR/ISR/SSG - Next.js middleware runs at the edge with low latency - Image optimization without Vercel's proprietary service - Works with SST, CDK, Terraform, Pulumi, and raw CloudFormation - Active community maintaining compatibility with latest Next.js releases ## Comparison with Similar Tools - **Vercel** — seamless Next.js hosting but proprietary and can be expensive at scale - **Netlify** — supports Next.js but with feature gaps in ISR and middleware - **AWS Amplify Hosting** — managed AWS option but slower to adopt new Next.js features - **Coolify** — self-hosted PaaS but not AWS-optimized for Next.js - **Docker deployment** — works but loses edge caching and serverless scaling benefits ## FAQ **Q: Does OpenNext support all Next.js features?** A: It supports SSR, SSG, ISR, middleware, API routes, image optimization, and App Router. Check the compatibility matrix in the docs for edge cases. **Q: Do I need SST to use OpenNext?** A: No. SST is the recommended deployment tool, but OpenNext's build output works with any AWS IaC tool including CDK, Terraform, and Pulumi. **Q: How much does it cost to run Next.js on AWS with OpenNext?** A: Costs depend on traffic. For many applications, AWS Lambda and CloudFront are significantly cheaper than equivalent Vercel plans, especially at scale. **Q: Can I migrate from Vercel to OpenNext?** A: Yes. OpenNext is designed as a drop-in build step for existing Next.js projects. No code changes are required in most cases. ## Sources - https://github.com/opennextjs/opennextjs-aws - https://opennext.js.org --- Source: https://tokrepo.com/en/workflows/asset-1d9812f0 Author: Script Depot