English | 简体中文
This plugin enables support for QCloud SCF within the Serverless Framework.
- Node.js
>= 6
for using the plugin.- Note that at the moment, Qcloud Serverless Cloud Function only supports v6.10. If you use a higher version of nodejs. Don't forget transform your code down to es5.
- Serverless CLI v1.20.0+. You can get it by running
npm i -g serverless
. - A Qcloud account.
The structure of the project should look something like this:
├── index.js
├── node_modules
├── package.json
└── serverless.yml
serverless.yml
:
service: hello-world
provider:
name: qcloud
runtime: nodejs6.10
credentials: ~/.qcloudcli/credentials # path must be absolute
plugins:
- serverless-qcloud-scf
package:
include:
- index.js
exclude:
- package-lock.json
- .gitignore
- .git/**
functions:
hello:
handler: index.hello
events:
- http:
path: /hello
method: get
package.json
:
{
"name": "serverless-qcloud-hello-world",
"version": "0.1.0",
"description": "Hello World example for qcloud provider with Serverless Framework.",
"main": "index.js",
"license": "MIT",
"devDependencies": {
"serverless-qcloud-scf": "*"
}
}
index.js
:
'use strict'
exports.hello = (event, context, callback) => {
callback(null, 'Hello!')
}
Credentials
Note that ~/.qcloudcli/credentials
is where the qcloudcli puts the crendentials after running qcloudcli configure
. You don't have to use qcloudcli though, you can just create a similar file with your own access keys and make sure pointing the value of the credentials
field in serverless.yml
to it.
In addition to qcloud_secretkey
and qcloud_secretid
, please configure qcloud_appid
(a numeric number for identifying your account, available in Qcloud Console) as well. This credential file should look something like this:
[default]
qcloud_secretkey = ****************Ewdm
qcloud_secretid = ****************ugEY
qcloud_appid = 1250000000
Put credentials in ENV
If you not prefer qcloudcli
. You can write credentials in ENV. serverless-qcloud-scf
will read them.
QCLOUD_SECRETID=xxx QCLOUD_SECRETKEY=xxx QCLOUD_APPID=1250000000 serverless package
Consider use dotenv or direnv.
-
Deploy your service to Qcloud:
serverless deploy
If your service contains HTTP endpoints, you will see the URLs for invoking your functions after a successful deployment.
-
When you no longer needs your service, you can remove the service, functions, along with deployed endpoints and triggers using:
serverless remove
Note: Some resources cannot remove, since it's not empty. The reason is your projects share a common service name. This issue different project deploy into same COS Bucket / API Gateway.
Function name is unique in a region.
The functions cannot more than 20, see scf document
Bucket name is unique in an account.
Plugin will try overwrite ACL to public-read
and write files into it if deploy target bucket is exists.
When create function in bj region, Qcloud will read code from COS ap-beijing-1
region.
Service ID is unique. Service name and API name is not unique.
Plugin will search service by region and name. Create it if not exists. Overwrite exists apis if service exists. But cannot handle multi service with same names.
Inside service, API "method+path" is unique.
# clone this repo
git clone [email protected]:vitarn/serverless-qcloud-scf.git
# link this module to global node_modules
cd serverless-qcloud-scf
npm install
npm link
# try it out by packaging the test project
cd test/project
npm install
npm link serverless-qcloud-scf
serverless package
-
serverless package
-
serverless deploy
-
serverless deploy --function
-
serverless remove
-
serverless invoke
-
serverless info
-
serverless rollback
- function: event: cos
- function: event: cmq
- function: event: http: usagePlan
- function: event: http: key
- function: event: http: custom domain
- function: event: http: switch release
MIT