-
-
Notifications
You must be signed in to change notification settings - Fork 455
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
Serverless component v2 #137
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ndemarin/serverless-nextjs-plugin into serverless-component-v2
danielcondemarin
force-pushed
the
serverless-component-v2
branch
from
September 6, 2019 14:15
c4e0d0e
to
3d00679
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a new approach to building serverless nextjs applications. It was developed using the lessons learned from
serverless-nextjs-plugin
with a special focus in zero config by default, supporting nextjs 9, and no cloudformation resource limitations.Serverless Nextjs Component
A zero configuration Nextjs 9.0 serverless component with full feature parity.
Contents
Motivation
Since Nextjs 8.0, serverless mode was introduced which provides a new low level API which projects like this can use to deploy onto different cloud providers. This project is a better version of the serverless plugin which focuses on addressing core issues like next 9 support, better development experience, the 200 CloudFormation resource limit and performance.
Design principles
There is no configuration needed. You can extend defaults based on your application needs.
Users of this component should be able to use nextjs development tooling, aka
next dev
. It is the component's job to deploy your application ensuring parity with all of next's feature we know and love.With a simplified architecture and no use of CloudFormation, there are no limits to how many pages you can have in your application, plus deployment times are very fast! with the exception of CloudFront propagation times of course.
Features
Pages that need server side compute to render are hosted on Lambda@Edge. The component takes care of all the routing for you so there is no configuration needed. Because rendering happens at the CloudFront edge locations latency is very low!
Similarly to the server side rendered pages, API requests are also served from the CloudFront edge locations using Lambda@Edge.
Statically optimised pages compiled by next are served from CloudFront edge locations with low latency and cost.
Nextjs build assets
/_next/*
served from CloudFront.Any of your assets in the static or public folders are uploaded to S3 and served from CloudFront automatically.
Getting started
Add your next application to the serverless.yml:
And simply deploy:
Custom domain name (Coming soon!)
In most cases you wouldn't want to use CloudFront's distribution domain to access your application. Instead, you can specify a custom domain name:
Architecture
The application architecture deployed by the component is the following with minor variations:
FAQ
Is it one monolith Lambda or one Lambda per serverless page?
Only one Lambda is provisioned. There are a few reasons why:
Simplicity. One lambda responsible for server side rendering or serving the API requests is very easy to manage. On the other hand, one lambda per page is a large surface area for a web app. For example a next application with 40+ pages would have resulted in 40+ lambda functions to maintain.
Deployment speed. Is much faster building and deploying one lambda function.
Of course there are tradeoffs ... An architecture using one lambda per page in theory results in lower boot times. However, the implementation of this component is designed to ensure a minimum amount of compute happens at the Lambda@Edge.
How do I interact with other AWS Services within my app?
See
examples/dynamodb-crud
for an example Todo application that interacts with DynamoDB.Should I use the serverless-nextjs-plugin or this component?
Users are enocouraged to use this component instead of the
serverless-nextjs-plugin
. This component was built and designed to fix issues the plugin has like the CloudFormation resource limit.