Skip to content
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 72 commits into from
Sep 6, 2019
Merged

Serverless component v2 #137

merged 72 commits into from
Sep 6, 2019

Conversation

danielcondemarin
Copy link
Contributor

@danielcondemarin danielcondemarin commented Sep 6, 2019

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.

serverless
Build Status
Financial Contributors on Open Collective npm version
Coverage Status
Codacy Badge

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

  1. Zero configuration by default

There is no configuration needed. You can extend defaults based on your application needs.

  1. Feature parity with nextjs

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.

  1. Fast deployments / no CloudFormation resource limits.

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

  • Server side rendered pages at the Edge.
    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!
  • API Routes.
    Similarly to the server side rendered pages, API requests are also served from the CloudFront edge locations using Lambda@Edge.
  • Dynamic pages / route segments.
  • Automatic prerendering.
    Statically optimised pages compiled by next are served from CloudFront edge locations with low latency and cost.
  • Client assets.
    Nextjs build assets /_next/* served from CloudFront.
  • User static / public folders.
    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:

# serverless.yml

myNextApplication:
  component: @serverless/nextjs

And simply deploy:

$ serverless

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:

# serverless.yml

myNextApplication:
  component: @serverless/nextjs
  inputs:
    domain: myfrontend.example.com

Architecture

The application architecture deployed by the component is the following with minor variations:

architecture

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.

Daniel Conde and others added 30 commits July 27, 2019 09:09
@danielcondemarin danielcondemarin merged commit 94b6b55 into master Sep 6, 2019
@danielcondemarin danielcondemarin deleted the serverless-component-v2 branch May 21, 2020 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant