Closed apoorvmote closed 3 years ago
@apoorvmote have you tried using Lambda layers for your node_modules as opposed to zipping them up with you lambda?
@iartemiev I would love to do that. But unfortunately I am just starting out with Nextjs after 2 years in React. So I am looking to deploy Nextjs without knowing Nexjs. The Serverless framework lets me do just that. And it doesn't allow for lambda layers. So until Ampliy supports hosting with SSR (not limited to static hosting) I am stuck with serverless framework.
It would appear that Serverless Framework supports Lambda layers
@iartemiev Technically it is serverless framework underneath. But https://github.com/serverless-nextjs/serverless-next.js is separate from serverless framework. The readme file has all possible customization. You will see huge warning that regular serverless framework deployes with commmand serverless deploy
however to deploy nextjs you deploy with serverless
.
Basically if customization is not part of readme file then you cannot do it. Even if its supported by actual serverless framework.
The withSSRContext
functionality depends on @aws-amplify/core
, meaning that its separate packaging would NOT mean its decoupling. Us making such a change would not result in the weight-reduction for which you're looking.
I believe this comes down to an issue of deployment options for NextJS. I personally enjoy using AWS Fargate. While I'd normally opt for serverless functions, they pose great difficulty when it comes to ease of NextJS deployments. The function serialization "magic" is somewhat obfuscated behind the the Vercel platform. That is––it's "easy" if you use Vercel. Otherwise, it can be arduous. This DX perk is likely a way to incentivize usage of Vercel (instead of raw AWS services). However, the Vercel vendor lock-in comes with disadvantages, such as best-practice resource access management (check out this thread for more info).
Your choice of deployment strategy is a delicate trade-off. We can discuss further, but this is not the best place for us to do so. If you wish to discuss, please open an issue in the NextJS repo (as that way it will be more visible to others). If you decide to open this issue there, I'd recommend the title "Docs Request: Deployment Option Tradeoffs" (and please feel free to @ me in it).
@harrysolovay Do you have good resources/tutorials on deploying Nextjs on fargate? possibly with AWS CDK?
Ideally I would prefer lambda deployment with CDK. But I have been learning docker, ecs and fargate for past week now. Its very brand new to me. So I would appreciate any tips on how to optimize nexjs for fargate with amplify framework.
Also in reinvent 2020 they announced custom lambda images. That would be interesting to explore.
I thought this was a very nice & minimal example. As for CDK tutorials, I'd recommend following along with CDK Workshop.
I have no immediately-obvious advice on ensuring a smooth NextJS + Fargate + AmplifyJS experience: I think it'll be pretty smooth even without the advice ;) but if you do encounter difficulty, please don't hesitate to file an issue or reach out in our Discord.
That's an awesome announcement! Would definitely be interesting to explore. I'm eager to test out the Deno
runtime on AWS Lambda functions.
This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server *-help
channels or Discussions for those types of questions.
Is your feature request related to a problem? Please describe. I am using Serverless framework to deploy Nextjs. They deploy single lambda@edge for all server side rendering pages and single lambda@edge for all api. Each lambda has limitation of 50MB storage zipped.
import Amplify, { withSSRContext } from 'aws-amplify
Adds 1.3 MB per SSR page or per SSR path. So at max I can deploy only 40 SSR pages or 40 API not including other packages. It looks like a lot but gets over quickly.I added single api and size of lambda@edge was 1.3 Mb. I added 3 api paths and size of lambda@edge became 4Mb.
All all Api's I am checking if user is logged in or not.
Describe the solution you'd like I use
import Amplify from '@aws-amplify/core
. I was hoping to get something likeimport { withSSRContext } from '@aws-amplify/ssr'
Describe alternatives you've considered Give up on SSR/Nextjs and go back to CSR/React.