1.0.0 • Published 8 years ago
serverless1.0-spike v1.0.0
Install
npm install --saveDev serverless@beta
#Add to path
export PROJECT_PATH=`pwd`
export PATH=$PATH:$PROJECT_PATH/node_modules/.bin
or
ln -s `pwd`/node_modules/.bin/serverless ~/.bin/serverless
Install babel for Flow and await features
# babel-preset-react babel-preset-es2015 and other plugins which defined in package.json
npm install
Create a default AWS profile
Run the following commands to create default aws configs, remember to change the "Secret Access KEY" and "ACCESS KEY ID"
mkdir ~/.aws
echo "[default]
region = ap-southeast-2" > ~/.aws/config
echo "[default]
aws_secret_access_key = YOUR ACCESS KEY
aws_access_key_id = YOUR ACCESS KEY ID" > ~/.aws/credentials
The detail reference at: https://github.com/serverless/serverless/blob/master/docs/guide/provider-account-setup.md
Create Service
(From 1.0) Service is a group of one or multiple functions and any resources they require
serverless create --template aws-nodejs
Add Api Gateway
in serverless.yml file
functions:
InvoiceGet:
handler: lib/functions/invoice/handler.getInvoice
events:
- http:
path: invoice
method: get
InvoicePost:
handler: lib/functions/invoice/handler.postInvoice
events:
- http:
path: invoice
method: post
We could put multiple functions in one js file, e.g. GET/POST/PUT handlers for the same resource
Add DynamoDB Support
All resources are defined in resources.json file, and reference it in serverless.yml
resources:
Resources:
$ref: ./resources.json
Deploy
serverless deploy
TODO
Currently, Serverless 1.x doesn't support transpiling and environment variable injection. We need to write a plugin to support
- custom package. using babel to transpile code
- environment variables. access project name, stage, region info from lambda function
1.0.0
8 years ago