部署无服务器之腾讯云篇

安装

1.查询你的python版本是否符合要求
在cmd中输入以下命令回车:

python

2.安装pip

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py 
sudo python get-pip.py //运行安装脚本

2.安装scf

pip install scf

jsonschema 3.0.1 has requirement six>=1.11.0, but you’ll have six 1.4.1 which is incompatible.
如果出现这种错误请升级下six

sudo pip install six --upgrade --ignore-installed six

4.查看scf是否安装成功

WARNING: The script scf is installed in '/Users/jiatui/Library/Python/2.7/bin' which is not on PATH.

WARNING: The script scf is installed in ‘/Users/jiatui/Library/Python/2.7/bin’ which is not on PATH…
如果出现这种警告请配置下环境变量

export PATH=/Users/jiatui/Library/Python/2.7/bin:$PATH

5.配置 scf cli
https://console.cloud.tencent.com/cam/capi 查询你的APPID,SecretId,SecretKey,执行以下命令

$ scf configure set --region ap-guangzhou --appid 1253970223 --secret-id AKIxxxxxxxxxx --secret-key uxxlxxxxxxxx

新建项目

1.执行以下命令,新建一个函数

$ scf init --runtime nodejs8.9 --name testscf

2.进入刚刚新建的函数目录,执行打包yaml配置的命令:

$ scf package --template-file template.yaml

3.部署函数到云

$ scf package --template-file template.yaml

执行

本地调用:

scf native generate-event cos post | scf native invoke --template template.yaml

使用模拟事件给函数传参

//生成如下的文件,格式为JSON
{
"key1":"value1",
"key2":"value2"
}
//执行:
scf native invoke --template template.yaml --event event.json

API调用

点击此处查看如何配置API
按照上面的8个步骤配置好即可。

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐