tencent cloud

Serverless Cloud Function

Release Notes and Announcements
Release Notes
Announcements
User Guide
Product Introduction
Overview
Related Concepts
How It Works
Strengths
Scenarios
Related Products
Purchase Guide
Billing Overview
Billing Mode
Billable Items and Billing Modes
Function Computing Power Support
Free Tier
SCF Pricing
Billing Example
Payment Overdue
Getting Started
Creating Event Function in Console
User Guide
Quota Management
Managing Functions
Web Function Management
Log Management
Concurrence Management
Trigger Management
Function URL
A Custom Domain Name
Version Management
Alias Management
Permission Management
Running Instance Management
Plugin Management
Managing Monitors and Alarms
Network Configuration
Layer Management
Execution Configuration
Extended Storage Management
DNS Caching Configuration
Resource Managed Mode Management
Near-Offline Resource Hosting Model
Workflow
Triggers
Trigger Overview
Trigger Event Message Structure Summary
API Gateway Trigger
COS Trigger
CLS Trigger
Timer Trigger
CKafka Trigger
Apache Kafka Trigger
MQTT Trigger
Trigger Configuration Description
MPS Trigger
CLB Trigger Description
TencentCloud API Trigger
Development Guide
Basic Concepts
Testing a Function
Environment Variables
Dependency Installation
Using Container Image
Error Types and Retry Policies
Dead Letter Queue
Connecting SCF to Database
Automated Deployment
Cloud Function Status Code
Common Errors and Solutions
Developer Tools
Serverless Web IDE
Calling SDK Across Functions
Third-Party Tools
Code Development
Python
Node.js
Golang
PHP
Java
Custom Runtime
Deploying Image as Function
Web Framework Development
Deploying Framework on Command Line
Quickly Deploying Egg Framework
Quickly Deploying Express Framework
Quickly Deploying Flask Framework
Quickly Deploying Koa Framework
Quickly Deploying Laravel Framework
Quickly Deploying Nest.js Framework
Quickly Deploying Next.js Framework
Quickly Deploying Nuxt.js Framework
Quickly Deploying Django Framework
Use Cases
Overview
Solutions with Tencent Cloud Services
Business Development
TRTC Practices
COS Practices
CKafka Practice
CLS
CLB Practice
MPS
CDN
CDWPG
VOD
SMS
ES
Scheduled Task
Video Processing
Success Stories
Tencent Online Education
Online Video Industry
Tencent Online Education
Best Practice of Tencent IEG Going Global
API Documentation
History
Introduction
API Category
Making API Requests
Other APIs
Namespace APIs
Layer Management APIs
Async Event Management APIs
Trigger APIs
Function APIs
Function and Layer Status Description
Data Types
Error Codes
SDK Documentation
FAQs
General
Web Function
Billing FAQs
Network FAQs
Log FAQs
SCF utility class
Event Handling FAQs
API Gateway Trigger FAQs
Related Agreement
Service Level Agreement
Contact Us
Glossary

Development Methods

PDF
Focus Mode
Font Size
Last updated: 2024-12-02 18:12:22

Deployment Methods

Tencent Cloud SCF provides the following function deployment methods. For more information about how to create and update a function, see Create and Update a Function.
Uploading and deploying a zip package, as instructed in Installing and Deploying Dependencies.
Editing and deploying functions via the console, as instructed in Deploying Functions.
Using the command line, as instructed in Deployment Through Serverless Framework CLI.

Installing and Deploying Dependencies

Currently, the SCF standard Python Runtime only supports writing to the /tmp directory, and other directories are read-only. Therefore, you need to install, package and upload the local dependent library for use. The Python dependency package can be uploaded with function codes to the cloud, or uploaded to the layer that will be bound to the required function.

Locally installing dependency packages

Dependency manager

In Python, dependencies can be managed with the pip package manager. Replace pip with pip3 or pip2 according to the environment configurations.

Directions

1. Configure dependency information in requirements.txt.
2. Run the pip install -r requirements.txt -t . command under the code directory to install the dependency package. You can use the -t parameter to specify the installation directory, or directly run -t . under the project’s code directory to install the dependency package in the current directory.
Note:
Use the pip freeze > requirements.txt command to generate a requirements.txt file that contains all dependencies of the current environment.
Because the function is running on CentOS 7, install the dependency package in the same environment to avoid errors. For detailed directions, see Using Container Image.
If some dependencies require dynamic link library, please manually copy these dependencies to the installation directory, and then package them for uploading. For more information, see Installing Dependency with Docker.

Sample

1. Use the index.py code file shown below to install the requests dependency locally.
# -*- coding: utf8 -*-
import requests

def main_handler(event, context):
addr = "www.qq.com"
resp = requests.get(addr)
print(resp)
return resp
2. Run the pip3 install requests -t . command to install the requests dependency under the current directory of the project. The code file is as follows:
$ pip3 install requests -t .
Collecting requests
Using cached requests-2.25.1-py2.py3-none-any.whl (61 kB)
Collecting certifi>=2017.4.17
Using cached certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
Collecting chardet<5,>=3.0.2
Using cached chardet-4.0.0-py2.py3-none-any.whl (178 kB)
Collecting idna<3,>=2.5
Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting urllib3<1.27,>=1.21.1
Using cached urllib3-1.26.4-py2.py3-none-any.whl (153 kB)
Installing collected packages: urllib3, idna, chardet, certifi, requests
Successfully installed certifi-2020.12.5 chardet-4.0.0 idna-2.10 requests-2.25.1 urllib3-1.26.4

$ ls -l
total 8
drwxr-xr-x 3 xxx 111 96 4 29 16:45 bin
drwxr-xr-x 7 xxx 111 224 4 29 16:45 certifi
drwxr-xr-x 8 xxx 111 256 4 29 16:45 certifi-2020.12.5.dist-info
drwxr-xr-x 44 xxx 111 1408 4 29 16:45 chardet
drwxr-xr-x 9 xxx 111 288 4 29 16:45 chardet-4.0.0.dist-info
drwxr-xr-x 11 xxx 111 352 4 29 16:45 idna
drwxr-xr-x 8 xxx 111 256 4 29 16:45 idna-2.10.dist-info
-rw-r--r--@ 1 xxx 111 177 4 29 16:33 index.py
drwxr-xr-x 21 xxx 111 672 4 29 16:45 requests
drwxr-xr-x 9 xxx 111 288 4 29 16:45 requests-2.25.1.dist-info
drwxr-xr-x 17 xxx 111 544 4 29 16:45 urllib3
drwxr-xr-x 10 xxx 111 320 4 29 16:45 urllib3-1.26.4.dist-info

Packaging and uploading

You can upload dependencies together with the project, and use them through the import statement in function codes. You can also package and deploy dependencies to a layer, and bind the layer to a function being created to reuse them.
The zip package for deploying functions or layers can be generated automatically by a local folder via the console or manually. All the packaging should be under the project directory to place codes and dependencies in the root directory of the zip package. For more information, see Packaging requirements.

Special dependency packages

Some Python dependencies such as the pycryptodome dependency need to be compiled for installation. Because the compilation varies with the operating system, the dependent library, dynamic library, and other programs compiled on Windows or Mac may be unable to run in the SCF environment. The following solutions are recommended.
Use the dependent library that is ready for FaaS open source implementations.
Search dependencies or submit requirements in the SCF public layer. This layer collects and stores special dependency packages, and provides the deployment support.
Use the container solution and SCF container image to install and extract special dependencies locally, and then package and upload them to the code runtime environment.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback