SCF CLI allows you to easily deploy a local SCF project to the cloud and view its execution logs on the local CLI by running simple commands.
SCF CLI uses the deploy
sub-command to package a function for deployment. Based on the specified function template configuration file, SCF CLI deploys the specified code package and information in the file, such as function configuration, to the cloud or update a function already in the cloud.
The execution of
scf deploy
command is fully based on the function template configuration file. For more information on the template file and how to write it, see Template file description.
The parameters supported by the scf deploy
command are as follows:
Parameter | Short Form | Required | Description | Example |
---|---|---|---|---|
template-file | -t | No | The configuration file used for deployment of a function project, which can be in .yaml format. | deploy.yaml |
forced | -f | No | Forces updating and overwriting the existing function, which is false by default. | None |
cos-bucket | -c | No | Uploads the code package to the specified COS bucket. | test-cos |
name | -n | No | Function name. | test-func |
namespace | -ns | No | Namespace, which is default by default. |
test-ns |
region | -r | No | Deployment region, which is the region configured by scf configure by default. |
ap-beijing |
skip-event | None | No | Retains a legacy trigger instead of overwriting it. | None |
without-cos | None | No | If COS is configured in configure for deployment, adding this parameter will nullify the COS configuration. To modify the default deployment mode, run scf configure set . |
None |
history | None | No | Rolls back to the legacy version deployed using COS. | None |
Go to the function project directory and run the following command to deploy the package.
$ cd /Users/xxx/code/scf/testproject
$ scf deploy
Compress function './.tcf_build/default-test-func-latest.zip' to zipfile 'default-test-func-latest.zip' success
Deploy namespace 'default' begin
Deploy function 'testproject' success
Deploy namespace 'default' end
After successful deployment, you can query the created "testproject" function in the function list in the console.
If you need to modify the code, you should deploy it again after modification. If the template configuration file is not modified, the function will be updated.
The example below shows how to package and re-upload the code after modification:
$ cd testproject
$ vim index.py
$ scf deploy
Deploy function 'testproject' success
In real projects, you can customize the file content that you don't want to upload, which will be ignored by SCF CLI during packaging.
ignore
folder under the code path.ignore
folder, create a FUNCTIONNAME.ignore
configuration file, and describe the content to be ignored in the file.As shown below, the function name defined inPath rule: Define the location of the content to be ignored based on the CodeUri path in
template.yaml
.
template.yaml
is hello, and CodeUri is ./
.Resources
default:
Type: TencentCloud::Serverless::Namespace
hello:
Type: TencentCloud::Serverless::Function
```properties
CodeUri: ./
Type: Event
Description: This is a template function
Handler: index.main_handler
"MemorySize": 128,
"Runtime": "Python2.7"
"Timeout": 3,
The directory hierarchy and HELLO.ignore
are as shown below:testmodule
directory and all .md files under the current path will be ignored during the final upload.Currently, SCF CLI supports the following two upload methods:
Using COS can speed up function deployment by up to 80%, significantly boosting your productivity. However, COS may incur charges if the deployment frequency is high and the deployed packages are large. A promotion campaign for SCF and COS has been launched for a limited time. You can claim vouchers when enabling deployment via COS. For more information on the campaign, go to the SCF Console.
You can run the scf configure set --using-cos y
command to enable automatic upload via COS. During deployment, the system will automatically enable COS and store the deployment packages under your account.
When using the deploy
command, you can upload a zip package to the specified bucket by specifying the cos bucket
parameter. During deployment, the cloud system will pull the code package from the COS bucket.
This example shows how to create a testproject
project in the /Users/xxx/code/scf
directory in Python 2.7.
The COS bucket must be in the same region as the function.
$ cd /Users/xxx/code/scf/testproject
$ scf deploy --cos-bucket temp-code-1253970226
Compress function './.tcf_build/default-testproject-latest.zip' to zipfile 'default-testproject-latest.zip' success
2019-07-17 10:42:20 put object, url=:https://temp-code-1253970226.cos.ap-shanghai.myqcloud.com/default-testproject-latest-2019-07-17-10-42-20.zip ,headers=:{'x-cos-acl': 'public-read', 'Content-Type': 'application/x-zip-compressed'}
Upload function zip file 'default-testproject-latest-2019-07-17-10-42-20.zip' to COS bucket 'temp-code-1253970226' success
After being notified of the locally created zip file based on the returned message, SCF will pass in the zip package to the COS bucket. The cloud system will then pull the code package from the COS bucket and deploy it successfully.If you create a function by uploading the code via local zip package, the zip package size cannot exceed 30 MB; otherwise, the function cannot be created directly. If the package is greater than 30 MB, we recommend you create the function by uploading the code via COS.
The samples in the
deploy
sub-command are all completed via local zip package uploads. When you use this method, you don't need to include thecos-bucket
parameter in thedeploy
sub-command. SCF CLI will package the local code, generate a zip file with a random name, and then deploy it to the cloud.
Was this page helpful?