Skip to content
This repository has been archived by the owner on Sep 3, 2020. It is now read-only.

A serverless typescript starter with unit test support. WIP

Notifications You must be signed in to change notification settings

Fallenstedt/serverless-typescript-todo-starter

Repository files navigation

Serverless TypeScript Starter

A Serverless starter that adds TypeScript, serverless-offline, environment variables, and unit test support.

This starter uses the serverless-webpack plugin,, serverless-offline, and Jest. It supports:

  • TypeScript
    • Use your favorite types anywhere you go
  • Package your functions using Webpack
  • Run API Gateway locally
    • Use serverless offline start
  • Support for unit tests
    • Run npm test to run your tests
  • Automatic support for multiple handler files
    • No need to add a new entry to your webpack.config.js
  • Add environment variables for your stages

Requirements

Installation

To create a new Serverless project.

$ serverless install --url https://github.com/Fallenstedt/serverless-typescript-todo-starter --name my-project

Enter the new directory

$ cd my-project

Install the Node.js packages

$ npm install

Usage

To run unit tests on your local

$ npm test

To run a function on your local

$ serverless invoke local --function hello

To simulate API Gateway locally using serverless-offline

$ serverless offline start

Run your tests

$ npm test

We use Jest to run our tests. You can read more about setting up your tests here.

Deploy your project

$ serverless deploy

Deploy a single function

$ serverless deploy function --function hello

To add another function as a new file to your project, simply add the new file and add the reference to serverless.yml. The webpack.config.js automatically handles functions in different files.

To add environment variables to your project

  1. Rename env.example to env.yml.
  2. Add environment variables for the various stages to env.yml.
  3. Uncomment environment: ${file(env.yml):${self:provider.stage}} in the serverless.yml.
  4. Make sure to not commit your env.yml.

Todo

  • Add CloudFormation Template for DynamoDB, AWS Cognito