cdk-patterns / serverless

This is intended to be a repo containing all of the official AWS Serverless architecture patterns built with CDK for developers to use. All patterns come in Typescript and Python with the exported CloudFormation also included.
https://cdkpatterns.com
MIT License
2.28k stars 271 forks source link

[Discussion] Next.js application pattern #145

Open andrewgadziksonos opened 3 years ago

andrewgadziksonos commented 3 years ago

Hello and greetings from Sonos!

First off, I just wanted to say thank you for supplying an amazing repo of patterns. This has inspired us to start tackling one of our more challenging deployments and hopefully convert it to something anyone can use.

I wanted to chat about application frameworks like Next.JS. These frameworks provide end-to-end application development experience that makes it very appealing to development teams. The only issue is that they want you to spend money on their hosting platform versus providing any guidance on how to host yourself.

https://nextjs.org/docs/deployment

Their basic solution for you is to spin up an EC2 and run the start script. I'm sure we could also explore using ECR/ECS with containers but where's the fun in that. We want a serverless solution!

The Serverless community has built a somewhat working solution here https://serverless-nextjs.com/ but its definitely lacking Next.JS features and I'm not 💯 sure about their approach. CloudFront + Lambda@edge used for APIs, etc.

The Terraform community has built another solution here https://registry.terraform.io/modules/dealmore/next-js/aws/latest and is also lacking some core NextJS features and appears to still be in active development. I do like their approach to the serverless architecture here. It just feels better and isn't forced like the Serverless approach is.

I was hoping this community could band together and vet each solution to come up with a proper pattern for these types of application frameworks 🤞

Cheers,

Andrew

cdk-patterns commented 3 years ago

This could be an option - https://github.com/dabit3/next.js-cdk-amplify-workshop

andrewgadziksonos commented 3 years ago

This could be an option - https://github.com/dabit3/next.js-cdk-amplify-workshop

Aye, I've looked into these sort of patterns in the past and I want to like Amplify. It still doesn't support backend routes from NextJS (think SSR routes, or dynamic routes). It still relies on Serverless to deploy the entire NextJS app out to Cloudfront. https://github.com/dabit3/next.js-cdk-amplify-workshop#deployment-with-serverless-framework.

I'll start creating some diagrams next week to start the conversation. I think we can combine a few of the patterns laid out here into a best practice NextJS pattern.

leandrodamascena commented 3 years ago

Yes, I agree that the full SSR deployment on AWS is complicated, that is, not only on AWS, but the SSR architecture is a complicated thing.

Months ago I did a lab and deployed a small SSR solution (NuxtJS) using Lambda @ Edge + Cloudfront and it works well.

Count on me to discuss this and try to create a pattern for it using the CDK.