DEV Community

Cover image for Deploy a Next.js App to AWS Amplify

Deploy a Next.js App to AWS Amplify

Ali Spittel on May 19, 2021

AWS Amplify just announced server-side rendering deployment support for Next.js! Here's a quick guide on how to deploy both an SSR and an SSG Next....
Collapse
 
marcostreng profile image
Marco Streng • Edited

Great article, thanks!

I've just created a new app from the Next.js starter and added a page with some server-side data fetching (SSR).
Build and deployment are running successfully. Amplify detects the framework correct with "Next.js SSR". Also the Lambda@Edge exists after the deployment. But there is no trigger connected as far as I can see.

But when I navigate to the SSR Page in the browser I always receive a "503 ERROR
The request could not be satisfied."

Maybe anyone got an idea?

Collapse
 
aspittel profile image
Ali Spittel

Hey, thanks for bubbling this up! The engineering team is checking into it and I'll let you know when I hear back!

Collapse
 
marcostreng profile image
Marco Streng • Edited

After some investigation I found out that I have to set webpack to version 4 in my next.config.js.
The latest Next.js uses webpack 5 as default which is not working with AWS Amplify Hosting right now.

Thread Thread
 
sohammondal profile image
Soham Mondal

Yes, you're right. Downgrading Next.js to v11.1.3 and setting webpack5: false in next.config.js fixed the issue.

Collapse
 
alacret profile image
Angel Lacret
Collapse
 
ianwijma profile image
Ian Wijma

I've had issue with prediction not working in the NextJS api routes. Where in the end I used LAMDA functions instead of API routes. I also number into other hurdles with Amplify. Love the idea. But not 100% sure about using it in my next big project.

Collapse
 
aspittel profile image
Ali Spittel

Hey! Thanks for the reply -- I just chatted with the engineers and for now SSR only works with Data and Auth not predictions yet. It could be a good thing to create an issue for to show the team you'd be interested in that as a feature! github.com/aws-amplify/amplify-js/...

Collapse
 
ninan_phillip profile image
Phillip Ninan

Great read!

I just followed this and got a demo app deployed. It may be worth noting that you need to add a role to the app. I created a demo without one and it didn't seem to work. It said it was deployed, but the link did not work and I did not see an S3 bucket created.

I created a second one and created a new role on the create app screen and it worked!

Unfortunately, it looks like the Image component is not working. I'm pretty new to Next.js and I'm using SSR. I'm not sure if that is something that's not supported? 🤔

Thank you!!

Collapse
 
aspittel profile image
Ali Spittel

Hey! Thanks for the feedback, the Image component was Next 10, and we're supporting the Next 9 features for now. Have let the product and engineering teams know that this feature is requested though!

Collapse
 
ninan_phillip profile image
Phillip Ninan

I wish I could like this more than once! 😂

Thank you Ali!

Collapse
 
fwang profile image
Info Comment hidden by post author - thread only accessible via permalink
Frank Wang

Hey Ali, great article.

We also receive a lot of requests in the SST community for deploying Next.js apps to AWS. And I just wanted to share that we created a SST construct (backed by CDK) to help with building and deploying Next.js apps to your AWS account. It uses a similar architecture behind the scene S3, CloudFront, Lambda@Edge, and Route53 for domains. Next.js 11 compatible with ISR and image optimization support.

Here's an example serverless-stack.com/examples/how-...

Collapse
 
larsejaas profile image
Lars Ejaas

It would be nice with some level of rollback functionality like Netlify. It just gives you so much mire peace in mind when updating a page. Otherwise AWS Amplify looks great!

Collapse
 
aspittel profile image
Ali Spittel

Hey! Thanks for this feature request, I passed it on to the engineering and product teams!

Collapse
 
larsejaas profile image
Lars Ejaas

Thanks Ali. Didn't realize you actually work at AWS until now! But I really liked the article! I am still short of my first project on AWS but Amplify really looks great!

Collapse
 
luismanuel001 profile image
Luis Manuel

Any plans for supporting ISR in the near future?

Collapse
 
aspittel profile image
Ali Spittel

I've passed along your request to the team! A few other people have asked as well, so my guess would be yes :)

Collapse
 
roblescoulter profile image
Luis Robles

Hi!

Any idea why Next.js's Fast Refresh doesn't work when testing the application locally with Amplify?

Some comments have been hidden by the post's author - find out more