-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Serverless: add example with serverless #6685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Stats from current PRClick to expand stats
Click to expand serverless stats
|
Stats from current PRClick to expand stats
Click to expand serverless stats
|
Stats from current PRClick to expand stats
Click to expand serverless stats
|
@kamleshchandnani We would prefer to have an example using this plugin, basically what it does is to create serverless functions for the pages and upload the static files to S3 |
@timneutkens - I and @lfades were discussing this, So I need some custom things which cannot be done as part of that plugin and neither is documented anywhere else. I'll describe the motivation behind this example I wanted to create a nextjs app which could achieve following things:
And the main difference here is I need a thin orchestrating layer in between which can orchestrate routing along with middlewares capabilities. So if you think of an express + nextjs app I guess this is how you'll achieve this. So I'm doing exactly this but building them as serverless and deploying it on AWS lambdas and API gateways. |
Stats from current PRClick to expand stats
Click to expand serverless stats
|
It's important to note first that next 8 serverless pages are self contained and ready to deploy on AWS Lambda, without having to use In a nutshell serverless.yml post:
handler: post.handler
events:
- http:
path: post/{slug}
method: get
request:
parameters:
paths:
slug: true Now the middleware part is more interesting. I've thought of adding support to the plugin to let users hook up their own middlewares. However, I think that using the whole of |
I guess both is great as long as you dont have a huge project. |
@romainquellec AFAIK for AWS the deployment package size is 50MB compressed and 250MB if you upload it to S3 and if you use |
So the design that this plugin fulfils and the the solution that this PR addresses serves different purpose IMHO as mentioned here |
I'm using your approach, and with serverless framework, i'm sometimes hitting the limit with >75mo. |
I actually like this example better than serverless-nextjs-plugin because all pages are bundled into a single function. This reduces the number of cold starts on less trafficked pages since everything is loaded in a hot function. Obviously this depends on your traffic volume and how you want your application to scale on Lambda (all pages vs per page). |
I'm going to close this PR as it does not illustrate best practices for the serverless target.
Bundling into a single function is bad in pretty much all cases. Cold boot is not noticeable when lambda size is <5Mb. You'll always have cold starts. And even hot functions get stopped etc. Furthermore using Also bundling everything into one function means that say you have 10 pages, you'll have 10 versions of React into the bundle. Same for every component etc. |
This PR addresses #6684