前端analysis | 3w & 1h

《serverless》- serverless能做什么?

2020-09-09

serverless安装

Mac|Linux

1
curl -o- -L https://slss.io/install | bash

Windows

1
2
choco install serverless
choco upgrade serverless

Npm方法

1
2
3
4
5
# 安装 serverless cli
npm i -g serverless

# 或者更新 serverless cli 到最新版本
npm update -g serverless

serverless使用

login

输入login,会拉起浏览器登录,web界面登录成功,server push信息back,更新client登录信息

1
$ serverless login


创建service

本地创建,还需要修改serverless.yml文件中的service-name

1
serverless create --template hello-world

serverless.yml文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
service: serverless-demo

# The `provider` block defines where your service will be deployed
provider:
name: aws # 云厂商默认aws
runtime: nodejs12.x

# The `functions` block defines what code to deploy
functions:
helloWorld:
handler: handler.helloWorld
# The `events` block defines how to trigger the handler.helloWorld code
events:
- http:
path: hello-world
method: get
cors: true

云厂商端创建

1
$ serverless --org chengzhanghu --app hello-world

上述命令,默认AWS,会要求登录账户,没有的可以先创建,再登录。登录过程需要输入Access key ID,Secret access key验证通过后,得到下方文字,

AWS credentials saved on your machine at ~/.aws/credentials. Go there to change them at any time

支持的云服务商

参考

serverless

使用支付宝打赏
使用微信打赏

若你觉得我的文章对你有帮助,欢迎点击上方按钮对我打赏