sls init
command for creation. You can quickly create an SCF function in Node.js as follows:sls init scf-nodejs
helloworld
templates currently supported by the SCF component are scf-golang
, scf-php
, and scf-python
. You only need to replace scf-nodejs
in the command with the template name listed above to quickly initialize a template in the corresponding language.sls deploy
sls info
sls remove
sls deploy
is executed, function resources will be created or updated according to the configuration in the serverless.yml
file. The following is a simple serverless.yml
file:# SCF component configuration sample# For all configuration items, please visit https://github.com/serverless-components/tencent-scf/blob/master/docs/configure.md.# Component informationcomponent: scf # Name of the imported component, which is required. The `tencent-scf` component is used in this examplename: scfdemo # Name of the created instance, which is required. Replace it with the name of your instance# Component parametersinputs:name: ${name}-${stage}-${app} # Function namesrc: ./ # Code pathhandler: index.main_handler # Entryruntime: Nodejs10.15 # Function runtime environmentregion: ap-guangzhou # Function regionevents: # Trigger- apigw: # Gateway triggerparameters:endpoints:- path: /method: GET
serverless.yml
file:Component | Required | Description |
component | Yes | Component name. You can run sls registry to query components available for import. |
name | Yes | Name of the created instance. An instance will be created when each component is deployed. |
inputs
are component configuration parameters. The parameters of a simplest SCF component are as detailed below:Parameter | Description |
name | Function name. As it is also the resource ID, to ensure the uniqueness of the resource, we recommend you use the ${name}-${stage}-${app} variable as the name. |
src | Code path. |
handler | Function handler name. |
runtime | Function runtime environment. Valid values: Python2.7, Python3.6, Nodejs6.10, Nodejs8.9, Nodejs10.15, Nodejs12.16, PHP5, PHP7, Go1, Java8, CustomRuntime. |
region | Function region. |
events | Trigger. Valid values: timer, apigw, cos, cmq, ckafka. |
SecretId
and SecretKey
of the account in advance.sls dev
in the directory of the serverless.yml
file to output cloud logs in real time. After each deployment, you can access the project to output invocation logs in real time on the command line, which makes it easy for you to view business conditions and troubleshoot issues. Node.js allows you to enable the development debugging feature, which can detect and automatically upload changes in the local code. For more information, please see Development Mode and In-cloud Debugging.sls deploy
command can be manipulated with the following commands.serverless.yml
.$LATEST
version of the my-function
function as a fixed version:sls publish-ver --inputs function=my-function
routing-alias
alias for the my-function
function, with the routing rule of 50% traffic for version 1 and 50% traffic for version 2:sls create-alias --inputs name=routing-alias function=my-function version=1config='{"weights":{"2":0.5}}'
routing-alias
alias of the my-function
function to 10% for version 1 and 90% for version 2:sls update-alias --inputs name=routing-alias function=my-function version=1 config='{"weights":{"2":0.9}}'
routing-alias
alias of the my-function
function:sls list-alias --inputs function=my-function
routing-alias
alias of the my-function
function:sls delete-alias --inputs name=routing-alias function=my-function
functionName
function and pass the JSON parameter {"weights":{"2":0.1}}
:sls invoke --inputs function=functionName clientContext='{"weights":{"2":0.1}}'
Was this page helpful?