4

Right now, I am following a guide prepared from Serverless Stack Team. They are using React and lots of AWS features like lambda and API getaway. In order to practice it, I am re-writing one of my old Express example with the Serverless stack.

I also saw a library or tool called aws-serverless-express. This library or tool allows you to run your express app in a way that serverless form.

It will be a weird question, but I was wondering the difference between native serverless build and serverless express.

Cold start already disadvantages. I am aware of it. Other than this, what will be the negative or positive sides of serverless express?
what will be the negative or positive sides of native serverless?

Kaan Taha Köken
  • 933
  • 3
  • 17
  • 37
  • Since 12.2019 cold starts with less pain - https://aws.amazon.com/blogs/aws/new-provisioned-concurrency-for-lambda-functions/. If you setup your app to boot fast 100-500 ms you will pretty much not see them. If you have express app it is easy to be ported to lambda - aws-serverless-express is just a wrapper to proxy request. – Traycho Ivanov Jul 30 '20 at 21:38
  • Check this assessment of aws-serverless-express: https://medium.com/@ac052790/the-pros-and-cons-of-aws-serverless-express-789996e4be32 – Allan Chua Aug 27 '20 at 05:35

4 Answers4

4

Disadvantages of serverless express:

  1. Possible additional cold start time caused by these extra dependencies
  2. Not being able to have separate granular permissions per route (e.g. one route accessing S3 and another accessing DynamoDB)

Advantages:

  1. Less boilerplate
  2. Avoiding resources limits in CloudFormation stacks

More information:

https://github.com/jeremydaly/lambda-api#why-another-web-framework

https://www.jeremydaly.com/build-serverless-api-serverless-aws-lambda-lambda-api/#comment-19036

Erez
  • 1,690
  • 8
  • 9
2

What constitutes ‘native’ serverless is probably up for debate and constitutes a bit of a spectrum. There are ways to take advantage of managed services such that lambda function usage is minimized, but there are plenty of use-cases that require custom logic e.g. integrating with third-party services.

I’d start by asking yourself what your existing application does, and how large your time investment is going to be in order to refactor to be as ‘serverless’ as possible. If this is a project that you are using for purely learning purposes, you may want to do a full conversion to maximize your learning. If this is a revenue generating application for a business, this may be an inappropriate use of resources for the payoff.

That said, the main differences between current best-practice serverless and usage of serverless-express will be:

  • Presence of additional dependencies. This will take some additional time to resolve at runtime [1], will need to be managed correctly at deployment time (packaging), and will require additional effort to update/patch/audit (security).
  • Permission granularity - as all route management is delegated to express, you will not be able to set permissions granularly for each route at the infrastructure level.
  • You will not be able to set resource limits on a per route basis

On the other hand:

  • You will avoid large cloud formation templates
  • Take advantage of your existing tooling and knowledge of express

Although it does depend on what the application is/does, it is unlikely that you will notice much of a cold-start penalty over single-purpose lambda functions, and would probably be a case of premature optimization. Part of the serverless mindset is about focusing on value - so if it were me doing this, I'd do as little as possible to get the application running in lambda - start instrumenting routes with X-Ray and CloudWatch [2], and then optimize the routes that require it.

From a learning perspective, if you do choose to use serverless-express, you will likely miss out on the opportunity to learn more about service-integrations, VTL transformations, request/response mapping etc that you would be exposed to if you took the more segmented approach. You can build some pretty cool things with just API Gateway and DynamoDB - without even having to touch a lambda function.

That’s not to say that using express in this way is a bad thing - AWS themselves note that this is a valid way to build a serverless application and new features like the HTTP API feature for API Gateway [3] help with this. In fact, the [real world serverless application [4] example that was published by AWS follows the single function principle, albeit for Java rather than an express application.

[1] https://www.freecodecamp.org/news/just-how-expensive-is-the-full-aws-sdk-3713fed4fe70/

[2] https://theburningmonk.com/2019/11/check-list-for-going-live-with-api-gateway-and-lambda/

[3] https://aws.amazon.com/blogs/compute/announcing-http-apis-for-amazon-api-gateway/

[4] https://github.com/awslabs/realworld-serverless-application

Matthew Tyler
  • 316
  • 2
  • 7
0

It's always best to keep the serverless code as simple as you can, lambda should run only your business logic, that should be just a function.

As explained above cold start is the main constraints for serverless.

Running express on serverless is useless because it runs a node server and listen to some port, which is not required. Lambda is not available always it's on the runtime.

GopiinSO
  • 11
  • 2
  • answer skips cloudformation limits issue and the fact that serverless express routing is connected to the labmda request directly - that being said serverless express is a fragile framework for serverless – okigan Apr 19 '20 at 18:51
0

There are also other solutions out there using AWS Lambda and serverless infrastructure to create fast and scalable applications. One of them is genezio: https://genez.io/ Here is a link with a getting started, it might help you. https://genez.io/blog/getting-started-with-genezio/

Disclaimer: I am one of the founders of genezio