DEV Community

James Allardice for orangejellyfish

Posted on • Originally published at orangejellyfish.com

A bleeding edge Serverless Framework boilerplate

At orangejellyfish we are big fans of the Serverless framework and use it in a number of projects. Over time we have realised the need for a boilerplate Serverless app to save time when getting started, and that's what we have built.

GitHub logo orangejellyfish / serverless-starter

Serverless framework starter kit for AWS Lambda

serverless-starter

An opinionated starter kit by orangejellyfish for Serverless framework apps running in AWS. Built to be future-proof Inspired by and adapted from the excellent serverless-babel-starter project by Postlight.

Features

  • Lambdas run Node 14 by default making your functions faster and giving you the ability to use more recent ECMAScript features including async/await, optional chaining and nullish coalescing.

  • Lambda code is bundled with Webpack 5 via the serverless-webpack plugin reducing the amount of code deployed to AWS.

  • Lambda code is compiled with Babel 7 and babel-preset-env meaning you can use even more cutting-edge ECMAScript features if you need to without unnecessarily compiling code that would be supported by Node 14.

  • Lambda config is located alongside the function code and referenced from the top-level Serverless configuration file, offering greater separation of concerns and keeping the configuration file readable.

  • IAM roles are configured per-Lambda via the serverless-iam-roles-per-function plugin, meaning…

The starter kit is an opinionated boilerplate for a Serverless app running in AWS. It's been designed to offer as much future-proofing as possible, a tricky challenge in the fast-moving JavaScript ecosystem! Our starting point was the fantastic "Modern Serverless Starter Kit" by Postlight. While that project has "modern" in the name we felt that we could safely go a bit closer to the cutting edge.

Features

When designing the Serverless starter kit we had a few key requirements in mind
which directly translate into features:

  • Node 8 support. This was a key one for us. AWS has supported Node 8 as a Lambda runtime environment since April 2018, bringing native support for a whole host of recent ECMAScript features (including async/await), performance improvements and reduced memory consumption thanks to the more recent version of V8.

  • Webpack 4 support. It was important that we could bundle our Lambda function code with Webpack to reduce the size of the package uploaded to AWS. Webpack 4 is the latest and greatest version, offering major speed improvements and much simpler configuration compared to previous iterations.

  • Babel 7 support. This one is more a straightforward case of future-proofing. There's currently little technical reason to favour Babel 7 over the arguably more stable version 6 but it's fun to push the boundaries sometimes!

  • Local development support. If you have to deploy functions to AWS every time you make a change the developer experience is somewhat poor. Fortunately this problem has been solved by the serverless-offline plugin which emulates AWS Lambda and API Gateway locally.

  • Jest support. Unit testing is important. Jest is, in our opinion, the best tool for the job. The starter kit includes Jest configuration to automatically collect code coverage information.

  • ESLint configuration. We're firm believers in the need for consistent code and therefore the starter kit ships with a pre-configured ESLint set up, along with Husky and lint-staged to efficiently lint and auto-fix code at commit time.

Usage

The Serverless CLI allows you to scaffold a new Serverless application from a template on GitHub. Run the following command to use our starter kit:

serverless create --template-url https://github.com/orangejellyfish/serverless-starter --path your/local/path
Enter fullscreen mode Exit fullscreen mode

What's next?

We think that the feature set provided by this starter kit give you a really solid start for any Serverless application but it's only the basics. Watch this space for more advanced kits, built upon this one, in the future, adding pre-configured support for things like DynamoDB.

Discussion (2)

Collapse
jess profile image
Jess Lee

A heads up that you can embed github repos into your post w/ this syntax:

{% github https://github.com/orangejellyfish/serverless-starter %}

Collapse
james_allardice profile image
James Allardice Author

Thanks! Edited to switch to that.