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.
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.
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…
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.
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
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.