Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

🗺️ My personal template/boilerplate for starting Serverless projects.

License

Notifications You must be signed in to change notification settings

himynameisdave/dmoney-serverless-boilerplate

Repository files navigation

dmoney-serverless-boilerplate

🗺️ My personal template/boilerplate for starting Serverless projects.


My personal template/boilerplate for starting JS-based Serverless projects targeted for deployment on AWS Lambda.

Gets you up and running with a nice foundation, including things like:

  • ncc for simple and efficient bundling.
  • serverless-offline so that you can test your lambda locally/don't have deploy to test.
  • ESLint to keep code clean.
  • Jest for unit testing.

Using this template

First, you must install serverless globally

npm i -g serverless
sls --version

You'll also want to setup your AWS credentials if you haven't already.

You can now use sls create with the URL of this GitHub repo to quickly generate your new service:

sls create --template-url https://github.com/himynameisdave/dmoney-serverless-boilerplate --path my-service

Your new service will be created at my-service/.

To simplify the above command, I recommend adding the following to your .bash_profile:

# You can this whatever you like
slsnew() {
  sls create --template-url https://github.com/himynameisdave/dmoney-serverless-boilerplate --path $1
  cd $1
  npm install
}

...which allows you to simply run slsnew my-service, and it will create the service and install all the dependencies.

Development

Start up the local server by running whichever of these you prefer:

yarn run dev

npm run dev

Your main lambda will now be served at localhost:4000/main.

Run your tests with either of these:

yarn run test

npm run test

# You can also run
# - test:coverage for coverage report
# - test:watch to run tests in watch mode

Deployment

Run one of the following command to deploy your lambda:

yarn run deploy

npm run deploy

If you have everything set up correctly, this will deploy your lambda to AWS. You will see the endpoint(s) for your service, so go check it out!