Basics
Base Install
npm -i -g serverless
Create a Project
sls create --template aws-nodejs --path sls-node-test
Running the Demo Function
jeffm@mac-algo [06:47:18]:~/sls-node-test# sls invoke local -f hello
{
"statusCode": 200,
"body": "{\n \"message\": \"Go Serverless v1.0! Your function executed successfully!\",\n \"input\": \"\"\n}"
}
jeffm@mac-algo [06:47:22]:~/sls-node-test#
Deploying the Demo Function
sls deploy ( will use default local credentials for AWS )
Removing the Demo Function
sls remove ( dumps everything )
Adjusting the Region and State in serverless.yml
service: sls-node-test
frameworkVersion: '3'
provider:
name: aws
runtime: nodejs12.x
region: us-west-2
state: dev
functions:
hello:
handler: handler.hello
Adjusting the Region and State from the cli
sls deploy --region us-west-1 --state prod
Adding an API endpint
In server.yml add the following event properties to the function you wish to call:
functions:
hello:
handler: handler.hello
events:
- http:
path: api/hello
method: get
Function Memory Size and Timeout
In your server.yml you can adjust the timeout and memory size per function as well as having a global default
Per Function:
functions:
hello:
handler: handler.hello
memorySize: 128
timeout: 3
events:
- http:
path: api/hello
method: get
Globally:
provider:
name: aws
runtime: nodejs12.x
region: us-west-2
state: dev
memorySize: 128
timeout: 3
Deploy a Single Function from a file
sls deploy -s prod -f hello