justinwhall / nextjs-serverless-aws

4 stars 0 forks source link

Using target "serverless" but only using one lambda #2

Open Vadorequest opened 5 years ago

Vadorequest commented 5 years ago

I think you missed something about the interest of using the serverless mode with next 8, it doesn't bring any benefit if you're using only one lambda. Or did I miss something?

https://github.com/zeit/next.js#serverless-deployment

Despite this, I find your repo useful for getting started with serverless and next 8 :) I did something similar a year ago, but it's really outdated (next 5) and I was looking for an up-to-date boilerplate with next 8 https://github.com/Vadorequest/serverless-with-next

justinwhall commented 5 years ago

@Vadorequest - This is very true. I'm seeing faster cold starts with this setup (dynamically importing the lambdas that next exports) than I did with loading up all the routes in a express server.

I'd be interested in seeing what you've come up with or where you are headed.

Vadorequest commented 5 years ago

Ah right, I forgot you had implemented a dynamic custom router to load the right serverless build based on path. I misunderstood how your project worked.

Now that I understand better, I find it very smart, you only have one AWS lambda (so, only one endpoint to warmup the AWS lambda if you need/want warmup) and then that lambda serves the right serverless page that had been pre-compiled by Next.

It avoid the pains of warming multiple endpoint when using next serverless mode directly, but still is very fast because it doesn't attach tons of things with the served page, only the page itself.

I believe you should make you design more obvious (explain it in readme), because it's something I haven't seen elsewhere and it's a very interesting design.

As far as I'm going with this, I tried you repo, but it didn't work at all, next wouldn't compile in serverless mode so i went back to non-serverless and changed paths from /.serverless to /.server and it "worked", but then it was a pain to dev locally because no hot reloading and no serverless-offline.

Your experiment in interesting but not yet mature enough to be used for a real project (IMHO)

By the way, Next9 released 2 days ago and bring a lot of interesting possibilities, such as API and easier dynamic routing.

On my side, I'm still trying/stuck to make Next 8/9 to work with my express setup, I'm not familiar with webpack/babel setup and it's driving me crazy. ^^ (upgrading from next 5 to 9 is hard due to serverless-offline and serverless-webpack own dependencies and own webpack/babel configs) https://github.com/zeit/next.js/issues/7823

justinwhall commented 5 years ago

Wouldn't compile in serverless mode? Peculiar.

The dev experience i still a bit off here for sure. As it stands now, we kinda have two server/route configs; server.js being the express server used for local dev and the serverless/lambda for AWS. IN a perfect, perfect world, we'd be able to run serverless offline and get hot reloading. A close second would be canning the "customer server". Next 9 with the filesystem routing may help solve this. However, I read somewhere that square brackets are not supported in AWS routes. Have yet to experiment.

Do you have a repo I could take a peak at? In private is fine.

Vadorequest commented 5 years ago

I don't have a public repo yet but I'll make one in the next days.

I'll try to reproduce the "wouldn't compile in serverless mode", so you can understand what's wrong

In my current project, I have only one server that simulates the AWS lambda through serverless-offline, it's something similar to what was done in https://github.com/Vadorequest/serverless-with-next which was my POC for the whole next+aws lambda attempt.