Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use AWS with Next.js?

I am looking for some advices, I am using Next.js to serve static pages that can be updated frequently, my app uses all kind of rendering : SSG, SSR and iSSG (new Incremental Static Site Generation feature).

Exemple of AWS architecture I thought:

  • EC2 to deploy a node.js server running next.js app
  • (if it is possible) Store/update static pages generated by Next.js SSR/iSSG in a S3 bucket
  • Cloudfront to cache pages (using either EC2 or S3 bucket if it is possible)

Do you know what is the best AWS architecture I could use according to my needs?

Edit: Maybe AWS Elastic Beanstalk is the solution, I am taking a look.

like image 569
Alex Coding Avatar asked May 30 '20 16:05

Alex Coding


People also ask

Can I host next JS on AWS?

js is a Serverless Component for easily deploying Next. js apps to AWS. At the time of writing, Serverless Next. js supports self hosting only for AWS, but eventually, it will support other cloud providers as well.

Does AWS amplify support next JS?

You can use AWS Amplify to deploy and host web apps that use server-side rendering (SSR). Currently, Amplify supports SSR apps created using the Next. js framework.

How do I host next JS app on AWS amplify?

Adding Amplify hosting next . The Amplify Console opens and displays your deployed backend environment. Choose the Frontend environments tab, select your Git provider, then choose Connect Branch. Follow the steps in the Amplify console to choose the branch to connect, and deploy your app.


1 Answers

Next.js 11 + SST + Lambda@Edge

Serverless deployment was introduced in Next.js 8. This makes it easier for you to deploy your Next.js app to AWS Lambda functions, and take advantage of the serverless architecture. It's often much cheaper to host this way, and faster because you are serving the pages behind a CloudFront CDN network.

The SST framework makes it easy to help build and deploy your Next.js app to your AWS account using a combination of S3, Lambda@Edge and CloudFront. It also helps you configure a custom domain for the endpoint.

Here's an example walking through the setup - https://serverless-stack.com/examples/how-to-create-a-nextjs-app-with-serverless.html

like image 139
Frank Avatar answered Sep 27 '22 18:09

Frank