A deployment package is a zip collection of all the code and dependencies that SCF runs, which should be specified during function creation. You can create a deployment package in your local environment and upload it to SCF or write the code directly in the SCF Console which will create and upload the deployment package for you. Please use the following criteria to determine whether you can use the console to create a deployment package:
The code package submitted directly to the SCF platform or submitted by uploading to COS and then imported into SCF must be in zip format. 7-Zip can be used on Windows and zip command line tools can be used on Linux for compression or decompression.
When packaging, you need to package the code files but not the entire directory of the code; after packaging is completed, the entry function file must be in the root directory of the package.
When packaging on Windows, you can enter the function code directory, select all files, right-click and select "Send to > Compressed (zipped) folder" to create the deployment package. If a tool such as 7-Zip is used to unzip and browse the package, the entry function and other libraries should be included in the package.
When packaging on Linux, you can enter the function code directory, run the
zip command, and specify the source files as all files in the code directory to generate the deployment package, such as
zip /home/scf_code.zip * -r.
The following sample illustrates the steps to create a deployment package in a local environment.
- Normally, locally installed dependent libraries work well on the SCF platform. In rare cases, the binary files installed may have compatibility problems. If this happens, please contact us.
- For the Python programming language in the sample, libraries and dependencies will be installed locally using the pip tool. Please make sure that you have already installed Python and pip locally.
For example, the following command installs the Pillow library in the
pip install <module-name> -t /data/my-first-scf
pip install Pillow -t /data/my-first-scf
my-first-scfdirectory. Please note that you need to compress the content of the directory but not the directory itself:
cd /data/my-first-scf && zip my_first_scf.zip * -r
- For libraries with compilation process, we recommend you perform packaging on CentOS 7 to maintain consistency with the SCF runtime environment.
- If there are requirements for other software, compilation environment, or development libraries during installation or compilation, please solve the compilation and installation problems as instructed.
We recommend you package the dependent packages and codes that have already been successfully executed on Linux into a zip package as the execution code of the function. For more information, please see Code Practice - Getting Images in COS and Creating Thumbnails.
In Windows, you can use the
pip install <module-name> -t <code-store-path> command to install Python libraries. But for packages that need to be compiled or have static or dynamic libraries, libraries compiled and generated on Windows cannot be invoked in SCF runtime environment (CentOS 7), so only libraries completely implemented in Python can be installed on Windows.
Before starting, please install the Serverless Framework CLI tool first as instructed in Installing Serverless Framework.
You can run
sls deploy on Serverless Framework CLI to deploy the function.