Next js app server setup with AWS

A growing trend over the last several years, Serverless Architecture allows yous to pass your code to cloud providers that accept their own servers that you can run your code from. Therefore, you don’t have to worry virtually how the server works, how it’due south maintained, or how information technology’s scaled. Instead, yous can just focus on writing your business organization logic and pay only for the number of times your code is run.

The nigh well known tool for Serverless Architecture is AWS Lambda, a serverless function service from AWS. However, the other big deject providers like GCP and Azure have their own offerings too.

In this article, we’ll learn how to deploy a Side by side.js application to AWS Lambda in Serverless Mode, helping united states of america maximize speed and scalability. Allow’s get started!

Table of contents

  • Next.js Serverless Mode
  • The Serverless Framework and the Serverless Next.js Component
  • Deploying your Side by side.js app to AWS
  • What is
    AWS
    [email protected]
    ?
  • Features not however supported
  • Determination

Next.js Serverless Mode

Since v8, Next.js has included Serverless Mode. With Serverless Style in Side by side.js, developers can continue to utilise the programmer-friendly, integrated environment of Next.js for edifice applications, while also taking reward of Serverless Compages by breaking up the app into smaller pieces at deployment.

Serverless Mode includes several built in configurations, but these can exist somewhat complex to execute. However, deploying to Vercel and Netlify is quite straightforward.

Many startups and smaller companies savor all their infrastructure on a larger deject platform, implementing granular permissions to control access to certain features, like the budget. This infrastructure is quite complex, and its widespread use explains why cloud architects are so in demand these days. In this situation, we can brand our lives much easier with the Serverless Framework.

Popular:   How to Install Squid Proxy Cache on Google GCP - Setup on Ubuntu Server - Step by Step Tutorial

The Serverless Framework and the Serverless Adjacent.js Component

The Serverless Framework is a tool to make deploying to cloud platforms a lot easier, automating provision by allowing yous to ascertain your projects infrastructure as
yml.

Serverless Components are plugins for the Serverless Framework that take pre-defined steps for edifice typical project structures. Serverless Next.js is a Serverless Component for easily deploying Next.js apps to AWS. At the fourth dimension of writing, Serverless Adjacent.js supports self hosting simply for AWS, merely eventually, it will support other cloud providers as well.

Deploying your Adjacent.js App to AWS

Prerequisites

To follow along with the remainder of the tutorial, you lot’ll need the post-obit:

  • Node.js ≥v12.x installed
  • The Serverless Framework installed on your machine
  • AWS
    User
    and
    Office
    with access to Lambda, SQS, and Cloudfront

In the root of your Next.js project in the folder with the
package.json
file, create a
serverless.yml
file with the post-obit code:

# serverless.yml  myNextApplication:   component: "@sls-next/[email protected]" # use latest version, currently 3.6.0
      

Then, nosotros’ll run the serverless command below, which volition read the serverless
yml, download the component, and run it inside your projection. Make sure to include your AWS credential as
.env
variables in the command:

AWS_ACCESS_KEY_ID=accesskey AWS_SECRET_ACCESS_KEY=sshhh serverless
      

The control in a higher place volition deploy your Adjacent.js app to AWS in Serverless Mode. Every API endpoint and page will be configured every bit an
AWS [electronic mail protected]
function, giving you the speed, costs, and scalability benefits of Serverless Architecture without requiring the complex configuration, API gateways, and Lambda functions on the AWS console.

Popular:   03 Hosted Server Installation - FreePBX 101 v15

What is
AWS [email protected]?

AWS Lambda functions are serverless functions that are deployed through the AWS Cloudfront CDN. Serverless functions distributed on the CDN are more performant than regular AWS Lambda functions deployed to a particular AWS region.

All static routes in your Adjacent.js application volition be pre-rendered and distributed on CloudFront to maximize speed. The result is a dynamic application that can run near the speed of a static site because the dynamic parts are being distributed past the CDN also, pretty cool!

Features not yet supported

At the fourth dimension of writing, the following features are non yet supported past the Serverless Side by side.js Component:

  • Middleware
  • Bot-aware ISR fallback
  • AVIF image support

Note that although ISR is supported, it requires your AWS Deployment
User
and
Roles
to have admission to Lambda and SQS.

Conclusion

In this article, nosotros explored deploying a Adjacent.js application to AWS Lambda using the Serverless Framework. Next.js provides a bully developer environment that allows us to take reward of static, server-side, and customer-side code. With Serverless Next.js, nosotros tin hands deploy our application to a Serverless Architecture to maximize speed and scalability.

I promise you lot enjoyed this article, and be certain to leave a comment if you lot have any questions. Happy coding!

LogRocket: Full visibility into production Adjacent.js apps

Debugging Next applications can exist difficult, especially when users experience issues that are difficult to reproduce. If you’re interested in monitoring and tracking state, automatically surfacing JavaScript errors, and tracking slow network requests and component load time, effort LogRocket.

LogRocket Dashboard Free Trial Banner

LogRocket is similar a DVR for spider web and mobile apps, recording literally everything that happens on your Next app. Instead of guessing why problems happen, you tin aggregate and report on what state your awarding was in when an outcome occurred. LogRocket also monitors your app’due south performance, reporting with metrics similar client CPU load, client retention usage, and more.

Popular:   Difference Between Omega-6 and Omega-3

The LogRocket Redux middleware package adds an extra layer of visibility into your user sessions. LogRocket logs all deportment and state from your Redux stores.

Modernize how you debug your Next.js apps — start monitoring for free.

Next js app server setup with AWS

Source: https://blog.logrocket.com/deploying-nextjs-aws-serverless-next-js/