Kickstart your Cloud-native and Serverless project in minutes. This is work in progress
This repository is a result of many lessons from launching variety of Serverless powered applications to the production. It was created according to many best practices and aims to provide developers a rapid start while also being production-ready.
- Written in Typescript, compiled by Webpack using Serverless Webpack plugin. Optimized for huge projects where Out of Memory errors are frequent
- Works fully offline thanks to Serverless Offline and DynamoDB Local ran using Docker Compose
- Easibly Testable using Jest
- Interacts with DynamoDB using DocumentClient and DynamoDB Toolbox
- Works with both REST and GraphQL
- Managable - To avoid spaghetti code,
serverless.yml
is divided into logical parts. Functions' code is placed next to their definitions - CORS by default - allows preflight requests to the resource using the OPTIONS method
- HTTP API - uses new version of API Gateway which provides costs savings up to 70%
Prerequisites:
- Serverless Framework
- Node.js
- Git
Start by pulling this repo using git
:
git clone https://github.com/Dynobase/serverless-dynamodb-api-boilerplate
Or using Serverless Framework:
serverless create --template-url https://github.com/Dynobase/serverless-dynamodb-api-boilerplate --path myService
Once ready, install dependencies:
yarn
After that, start the project locally:
docker-compose up -d # To start DynamoDB local
yarn provision-local-table # To provision DynamoDB table locally
yarn dev # Run project locally
# Add item to the table
curl --location --request POST 'localhost:3000/dev' --data-raw '{ "name":"John Doe" }'
sls deploy
- Create new folder in
functions
directory. It should contain:
function.yml
- function definition in accordance to Serverless Framework contractfunction.ts
- actual implementation of Lambda function
Optionally:
role.yml
- in order to get better control over IAM Role tied to the function, referenced inside function'srole
propertycontroller.ts
- the best practice is to keep functions as thin as possible. Controllers with injectable dependencies allow thatrequest_schema.json
- request object definition in JSON Schema
- Include newly created function in
serverless.yml
like so:
- ${file(./functions/<new_function_directory>/function.yml)}
-
Run
yarn generate-request-types
to generate Typescript types from request JSON Schema -
Complete implementation of your function
Apart from using DynamoDB Shell or CLI, you can use Dynobase to view contents of your local tables:
Contributions are more than welcome.
This project is licensed under the MIT License.