Skip to content

Serverless Boilerplate - Generic boilerplate for applications using the Serverless Framework

License

Notifications You must be signed in to change notification settings

nielsgl/serverless-boilerplate

Repository files navigation

Serverless Boilerplate

serverless CircleCI branch CircleCI branch Maintainability Test Coverage Codacy Badge Codacy Badge

node Libraries.io for GitHub GitHub commit activity the past week, 4 weeks, year

PRs Welcome GitHub license Twitter

Serverless Boilerplate - Generic boilerplate for developing applications using the Serverless Framework.


Documentation

Installation

Usage and command line options

KMS

Generate a key: aws kms create-key and get the keyId.

Encrypt a variable with

serverless encrypt --name foo --value bar --keyid {keyId}

DynamoDB / Dynalite

This boilerplate includes two options for running DynamoDB: the JVM-based AWS version and Dynalite, a Node-based version of DynamoDB

DynamoDB

DynamoDB will be installed locally and automatically though the install:dynamodb script in package.json, i.e., yarn install:dynamodb. For the JVM-based version you need to enable to following plugin in your plugins section:

plugins:
  - serverless-webpack
  - serverless-dynamodb-local
  - serverless-offline

Note that it comes after the serverless-webpack plugin and before the serverless-offline plugin.

This configuration in serverless.yml starts DynamoDB automatically when the local server is started with yarn start or serverless offline start.

custom:
  dynamodb:
    start:
      port: 8000
      inMemory: true
      migrate: true
      seed: true

You can access the shell interface to interact with DynamoDB at http://localhost:8000/shell.

Dynalite

This plugin can be found in the .serverless_plugins directory in the root of this boilerplate. I didn't include the official plugin because it does not work with serverless-offline and you would need to start it separately. If you want to use Dynalite instead, you need to enable it before serverless-webpack plugin, for example:

plugins:
  - serverless-dynalite
  - serverless-webpack
  - serverless-offline

Admin

An admin interface for DynamoDB can be started with yarn dynamodb:admin, and will be available on http://localhost:8001.

Custom Domain Name

Using the serverless-domain-manager plugin you can easily map your serverless application to a particular domain name. To create the custom domain:

serverless create_domain

To deploy with the custom domain:

severless deploy

To remove the created custom domain:

serverless delete_domain

Boilerplate Contents

This boilerplate contains the following plugins:

  • Serverless Offline Plugin: Emulates AWS λ and API Gateway on your local machine to speed up your development cycles.

  • Serverless Webpack: A Serverless v1.x plugin to build your lambda functions with Webpack.

  • Serverless KMS Secrets: A Serverless Plugin which helps with encrypting service secrets using the AWS Key Management Service (KMS).

  • Serverless Jest Plugin: plugin to enable test driven development using jest, and adding functionality to create functions and tests from command line

  • Serverless AWS Documentation: Plugin that adds support for AWS API Gateway documentation and models (e.g. to export a Swagger JSON file with input/output definitions and full text documentation for API documentation).

  • Serverless DynamoDB Local: Allows to run dynamodb locally for serverless.

  • Serverless Domain Manager: Create custom domain names that your lambda can deploy to with serverless. Allows for base path mapping when deploying and deletion of domain names.

  • Serverless VPC Discovery: The vpc discovery plugin takes the given vpc, subnet, and security group names in the serverless file to setup the vpc configuration for the lambda.

  • file serverless.yml.json: Register plugins above

  • file webpack.config.js: Settings for webpack-plugin

  • file templates/function.ejs: Template to use for new functions

Debug process

TO DO

  • API logs
  • Hooks
  • Build plugin
  • Containerization with Docker
  • Shell
  • ??

In Progress:

  • Test framework (jest)

Done:

  • Gulp with watch and eslint
  • KMS secrets
  • Quality check with CodeClimate
  • Configuration management
  • Automatic AWS Documentation
  • Coverage check with Codecov
  • DynamoDB and Dynalite
  • Domain Name Manager
  • VPC Discovery

Notes

Releases

Need to write more details Command yarn release.

Jest Plugin

The jest plugin seems to have several issues, such as:

  • it doesn't respect a custom template for tests,
  • when an error occurs while creating a function and test it still updates the serverless.yml file but does not create the function and test file,
  • running serverless invoke test --function foo only works when the handler defined in the function of serverless.yml matches the test name.

Credits and inspiration

Contributing

Yes, thank you! This boilerplate is community-driven, most of its features are from different authors. Please update the docs and tests and add your name to the package.json file. We try to follow Airbnb's JavaScript Style Guide.

License

MIT