Overview of OpenNext, AWS Amplify, Netlify, and other Next.js hosting options
Tags: nextjs, serverless, webdev
Published: 2024-04-12 13:35:19

Vercel is undeniably an excellent choice for deploying your applications, providing first-class support for Next.js out of the box, reliable infrastructure and seamless developer experience. However, every scenario is unique, and Vercel might not be the perfect fit for your particular situation.

One of the common scenarios where it might not be the best choice is if you already have an existing AWS infrastructure or have had positive experiences with it and want to remain with the same setup.

Even though there is no traditional vendor lock-in, migrating a Next.js project to another serverless platform can be challenging. On the other hand, you can effectively run it as a Node.js application with a serverful approach (though with limitations), check out the [documentation](https://nextjs.org/docs/pages/building-your-application/deploying#self-hosting) for details.

Moreover, you may encounter some complaints about Vercel's pricing model ([click](https://www.reddit.com/r/nextjs/comments/14r4f78/im_perplexed_about_vercels_pricing_per_user/), [click](https://www.reddit.com/r/Frontend/comments/17dqwsn/do_you_pay_for_vercel_and_why/)). Vercel kindly offers a pretty generous Hobby tier that is sufficient for most personal projects. The Pro plan, with its reasonable limits, is also a viable choice, but keep in mind that you are billed on a per user basis rather than for resource usage. However, the problem appears when usage exceeds certain thresholds, especially when application traffic grows significantly. At that point, it's crucial to make valuable improvements (such as optimizing static assets) or consider a more radical approach - exploring an alternative platform.
![Vercel pricing model](https://cdn.sanity.io/images/vftxng62/production/27ae468b7dc5b10c34a943632b9870100d6ed54a-1229x613.png?w=2000&fit=max&auto=format)
Apart from that, other services like databases, storage, and logs are often required for applications that go beyond simple portfolio projects. While Vercel provides its own wrappers around existing services (e.g. Vercel Postgres, which is built on top of Neon but at a higher price), you may still need to invest time and effort to explore third-party services.

### ALTERNATIVES

A noteworthy competitor to Vercel that often comes to the fore is Netlify. It has established itself as one of the leading choices for hosting Next.js applications, gaining traction for its user-friendly interface, scalability and serverless architecture. 

Application deployment follows a straightforward process similar to Vercel. In just a few minutes, you'll be able to access your application, review the deployment summary, inspect build artifacts, delve into function logs and much more. While some features may require a Pro plan, the Free-tier is more than sufficient for smaller projects.
![Netlify deployment](https://cdn.sanity.io/images/vftxng62/production/1a838e62af953dc0cf7334bf1c36d91f79319e1b-3808x1760.png?w=2000&fit=max&auto=format)
![Netlify logs](https://cdn.sanity.io/images/vftxng62/production/1667ab600e503222631dd6279b0cf4607efbd46f-3815x1750.png?w=2000&fit=max&auto=format)
At the core of Netlify's deployment mechanism lies its edge network, a distributed network of servers strategically positioned across the globe, which ensures rapid content delivery to a user’s location. Moreover, this edge network also incorporates Edge Functions, similar to Vercel's, which enable middleware to behave identically to how it does on Vercel. Netlify's serverless architecture further enhances the deployment process by offloading computationally intensive tasks to AWS Lambda functions. These functions execute code in response to user requests, enabling dynamic content generation, database interactions, and other server-side functionalities. In general, most of the Next.js features are supported out of the box, although there may be some limitations (e.g. ISR revalidation [timeout](https://docs.netlify.com/integrations/frameworks/next-js/incremental-static-regeneration/#use-isr-on-netlify)).

Given that Vercel and Netlify leverage AWS under the hood, why not deploy directly to AWS? It's possible!

### CLOSER TO AWS

One of the first options that comes up when googling "deploy Next.js on AWS" is AWS Amplify. Let's delve into what it is.

AWS Amplify is an excellent tool for beginners to AWS, as it abstracts away the complexities and eliminates the need to navigate through the labyrinth of AWS services. The user interface is intuitive, so it takes only a few simple steps to deploy your application (and it's not limited to Next.js projects only). If you don't already have a ready-made project, the setup is slightly different (you can use Next.js starter that Amplify offers by default).
![Amplify wizard - step 1](https://cdn.sanity.io/images/vftxng62/production/5e393661fecdf857707acdb719d6e27534e00cd4-1024x661.png?w=2000&fit=max&auto=format)
![Amplify wizard - step 2](https://cdn.sanity.io/images/vftxng62/production/8173fb0cf22c954f975c27321a39c6f6b2c9e368-1024x1003.png?w=2000&fit=max&auto=format)
![Amplify wizard - step 3](https://cdn.sanity.io/images/vftxng62/production/aa0e7cfd8ec8109be47e1fd0c1022f3af6bf64d8-1024x664.png?w=2000&fit=max&auto=format)
However, for more complex applications, you'll need to handle tasks like SSL/Routing configurations, database setup, storage, and so on.

The final result is a distributed CDN deployment with API endpoints running on AWS Lambda functions. However, there are a few considerations:
* Amplify may not immediately support the latest Next.js features, and some features might not work as expected or may require adjustments
* The infrastructure details are hidden, and although you can find the CloudFormation stack, it may not provide information you are looking for.

When it comes to pricing, for commercial applications with low to moderate traffic and a standard setup (database, logging, storage), Amplify is likely to be more cost-effective, mainly due to Vercel's user-based pricing model, even though you’re charged for both AWS resources and Amplify itself. For me details check out their [docs](https://aws.amazon.com/amplify/pricing/).

### FULL CONTROL OVER INFRASTRUCTURE WITH SST

Among the various open-source solutions for deploying Next.js apps to AWS (Terraform, serverless-next.js) that you may come across, SST (Serverless Stack Toolkit) stands out as a relatively new and promising tool. It’s a comprehensive framework for deploying not only Next.js applications but also other modern tech stacks like Remix, Svelte, Astro and more.

Speaking of Next.js applications, SST leverages OpenNext framework under the hood, which basically takes Next.js build output and converts it into a [format](https://open-next.js.org/inner_workings) that in theory can be deployed to any serverless platform, but as for now only AWS Lambda is supported.

Integrating SST into an existing project is relatively straightforward. Add your AWS account keys to AWS CLI ([how](https://docs.sst.dev/advanced/iam-credentials#loading-from-a-file)) and run the following command:

```bash
npx create-sst@latest
```

This command will install the necessary dependencies and add an SST configuration file to the root of your project. The framework is built on top of AWS CDK and provides high-level TypeScript abstractions for different AWS services and resources, such as Lambda functions, API Gateways, and databases. For simple applications, the configuration may look as follows:

```js
export default {
  config(_input) {
    return {
      name: 'demo-project',
      region: 'eu-north-1',
    };
  },
  stacks(app) {
    if (app.stage !== "prod") {
      app.setDefaultRemovalPolicy('destroy');
    }


    app.stack(function Site({ stack }) {
      const serverCachePolicy = new cf.CachePolicy(stack, 'ServerCache', {
        queryStringBehavior: cf.CacheQueryStringBehavior.all(),
        cookieBehavior: cf.CacheCookieBehavior.none(),
        headerBehavior: cf.CacheHeaderBehavior.none(),
      })
      const site = new NextjsSite(stack, 'demo-project', {
        cdk: {
          serverCachePolicy
        },
        timeout: '20 seconds',
        memorySize: '2048 MB',
        environment: {
          DATABASE_URL: process.env.DATABASE_URL
        }
      });


      stack.addOutputs({
        SiteUrl: site.url,
      });
    });
  },
} satisfies SSTConfig;
```

Once configured, you can start your local development environment by running:

```bash
npx sst dev
```

This allows you to debug and test your Lambda functions locally, while being invoked remotely by resources in AWS. It works by proxying requests from your AWS account to your local machine. Changes are automatically detected, built, and live reloaded.
To build and deploy your Next.js app on AWS, use the following command:

```bash
npx sst deploy --stage <stage_name>
```

It will provision the entire infrastructure defined in your configuration file. The initial deployment may take a while due to [bootstrapping](https://docs.sst.dev/advanced/bootstrapping) of all the necessary components that will help SST to take care of your application behind the scenes.
Once you’re done, remove your stack with the following CLI command:

```bash
npx sst remove --stage <stage_name>
```

You may encounter some differences compared to how Vercel does things (such as [middleware](https://open-next.js.org/faq)), but SST is constantly evolving to keep up with new Next.js releases, so be sure to check out their docs as you may find solutions to issues you have.
Regarding pricing, SST is entirely free to use. You only pay for the actual AWS resources used by your application. However, there is a possibility of incurring additional fees for resources that aren’t explicitly defined in your configuration file, such as the warmer function. It's crucial to review the documentation thoroughly to avoid unexpected costs.

Overall, SST emerges as a promising toolkit for deploying Next.js apps and other modern tech stacks to AWS infrastructure. Its ability to support a wider range of frameworks and its focus on simplicity makes it an attractive option for developers seeking a streamlined deployment process.

### SAAS ALTERNATIVE

Flightcontrol is a relatively new Software-as-a-Service (SaaS) offering, created by the developer behind Blitz.js, that plays a role of wrapper around various AWS services. With its recent release of v2.0, Flightcontrol has positioned itself as a strong competitor to other popular solutions in the market. The updates in this version have significantly improved the developer experience and expanded the functionality of the platform.

Flightcontrol aims to align itself with Vercel, offering a seamless application deployment experience that extends beyond Next.js. To get started, all you need is to link your AWS account, which is done through a semi-automated process where Flightcontrol creates the necessary IAM privileges for you.
![Flightcontrol wizard](https://cdn.sanity.io/images/vftxng62/production/a0c74eebe1792cae93052f6ce85d7cc6fb8515c7-1676x784.png?w=2000&fit=max&auto=format)
In the wizard, you have the option to finely configure the required resources, such as server instances and databases, to suit your specific needs. Alternatively, you can describe your infrastructure using a configuration file. Although the number of available resources is currently limited, ongoing support is continuously expanding.
![Flightcontrol dashboard](https://cdn.sanity.io/images/vftxng62/production/512a32f76d2dd7852f9e14dc59dbb115da4e0fd0-3840x2160.png?w=2000&fit=max&auto=format)
Once you proceed, you'll find yourself in the Flightcontrol dashboard, which bears similarities to the Vercel interface. Here, you can easily monitor runtime logs, various metrics, reserved AWS resources, and even pricing. The dashboard is designed to be straightforward and intuitive, allowing for seamless navigation and understanding of your infrastructure.

Flightcontrol runs your application as a container managed by ECS Fargate, leveraging CloudFront for global deployment capabilities. It utilizes CloudFormation to spin up your infrastructure, allowing you to easily review all the resources created in the process.

It's worth noting that the pricing for Flightcontrol may be relatively high for teams, with costs of up to $50 per service. However, Flightcontrol also offers an exceptionally generous free-tier plan, which even includes commercial use. This makes it an attractive option for smaller teams or individual developers.

### COMPARISON

Let’s see how various features work on these platforms (you can find implementation in a [repo](https://github.com/focusreactive/MVP-NextJS13-New-Features)). Next.js version - v14.0.4. Also, it's important to note that content propagation across CDN may take some time. While this isn't a critical issue, it can affect the time it takes for users to access new content.


|Feature                                |Vercel|Netlify|Amplify| SST |Flightcontrol|
|-------                                |:----:|:-----:|:-----:|:---:|:-----------:|
|Layout nested                          |✅|✅|✅|✅|✅
|Layout parallel                        |✅|✅|✅|✅|✅
|Layout error                           |✅|✅|✅|✅|✅
|Data fetching revalidate 10            |✅|50/50 (due to [limitation](https://docs.netlify.com/integrations/frameworks/next-js/incremental-static-regeneration/#use-isr-on-netlify))|✅|✅|✅
|Data fetching revalidate 60            |✅|✅|✅|✅|✅
|Data fetching revalidate on demand     |✅|❌|❌|❌ (requires extra [steps](https://open-next.js.org/common_issues/isr))|❌ (requires extra [steps](https://www.flightcontrol.dev/docs/guides/advanced/isr))
|Data fetching no cache (no store)      |✅|✅|✅|✅|✅
|Data fetching POST default             |✅|✅|✅|✅|✅
|Data fetching POST without cache       |✅|✅|✅|✅|✅
|Routing default                        |✅|✅|✅|✅|✅
|Routing no cache                       |✅|✅|✅|✅|✅
|Static metadata                        |✅|✅|✅|✅|✅
|Dynamic metadata SSG                   |✅|✅|✅|✅|✅
|Dynamic metadata SSR                   |✅|✅|✅|✅|✅
|JSON-LD                                |✅|✅|✅|✅|✅
|Image generation                       |✅|✅|❌ (HTTP 500)|✅|✅
|Sitemap + robots.txt                   |✅|✅|✅|✅|✅
|Draft mode                             |✅|❌|❌|❌|❌
|RSC                                    |✅|✅|✅|✅|✅
|Server Actions                         |✅|✅|✅|✅|✅
|Intercepting routes                    |✅|❌|✅|✅|✅
|API Routes                             |✅|✅|✅|✅|✅
|Fonts                                  |✅|✅|✅|✅|✅

As you can see, a pretty wide range of features is supported by each solution. However, a few of them may require additional steps to work or may function in an unexpected way.

### CONCLUSION

When it comes to selecting the ideal Next.js deployment platform, the perfect choice depends on your specific requirements. Vercel stands out as the top choice, unless:
* you're facing pricing issues
* you own AWS infrastructure
* you simply want to try something new

For those primarily concerned with cost-effectiveness and averse to significant changes, Netlify (or other PaaS providers compatible with Next.js) becomes a viable alternative, although it comes with its own drawbacks.

If AWS is your preferred hosting platform, SST is an excellent open-source option that offers complete control over deployments and resource management. Moreover, it’s absolutely free.

If you prefer the simplicity of not having to worry about infrastructure details, Amplify or Flightcontrol could be a good choice for you. These platforms take care of most of the underlying infrastructure complexity, allowing you to focus on your application logic.
While Amplify might seem more cost-effective at first, there's a risk of unexpected issues that might be difficult to troubleshoot. In these cases, Flightcontrol comes in handy as an alternative solution.