Circli.CI integration
ESLint
Tests setup with one sample
Logger setup
Config setup
Coverage Setup
Build and Release scripts
utility dependencies setup
Serverless Scafolding
Simple service example
serverless.yml (with stage support)
local test support
To create a new Serverless project.
$ serverless install --url git_url --name my-projectEnter the new directory
$ cd my-projectInstall the Node.js packages
$ npm installTo run unit tests on your local
$ npm testTo run a function on your local
$ serverless invoke local --function helloInstall DynamoDB Local
npm install dynamodb
$ npm install --save serverless-dynamodb-localAdd DynamoDB Resource definitions to your Serverless configuration, as defined here
resources:
Resources:
usersTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: taskTable
AttributeDefinitions:
- AttributeName: name
AttributeType: S
KeySchema:
- AttributeName: description
KeyType: HASH
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1You can either start DynamoDB locally yourself:
$ sls dynamodb startOr configure to start it by serverless
custom:
dynamodb:
start:
port: 8000
inMemory: true
migrate: true
seed: true
# Uncomment only if you already have a DynamoDB running locally
# noStart: trueTo simulate API Gateway locally using serverless-offline
$ serverless offline startRun your tests
$ npm testWe use Jest to run our tests. You can read more about setting up your tests here.
Deploy your project
$ serverless deployDeploy a single function
$ serverless deploy function --function helloTo 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
- Rename
env.exampletoenv.yml. - Add environment variables for the various stages to
env.yml. - Uncomment
environment: ${file(env.yml):${self:provider.stage}}in theserverless.yml. - Make sure to not commit your
env.yml.
Remember the best practice on production enviroment: IAM Permissions
Fast but risky (aka YOLO): The fastest way to get started with Serverless
is to create an IAM user with Administrator Access. This IAM user will have
full access to your AWS account and should not be used for your
company's production"