Before installing the SDK and using TencentCloud API for the first time, you need to apply for security credentials in the Tencent Cloud console, which consists of SecretId
and SecretKey
. SecretId
is used to identify the API requester, while SecretKey
is a key used for signature string encryption and authentication by the server. Please keep your SecretKey
private and avoid disclosure.
The commonly used APIs of SCF are as follows. For more APIs, please see the API documentation.
API | Description |
---|---|
CreateFunction | Creates function |
DeleteFunction | Deletes function |
GetFunction | Gets function details |
Invoke | Executes function |
ListFunctions | Gets function list |
UpdateFunctionCode | Updates function code |
UpdateFunctionConfiguration | Updates function configuration |
Take Python3.6
as an example:
# -- coding: utf8 --
import json
from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
# Import the client models of the corresponding product module
from tencentcloud.scf.v20180416 import scf_client,models
# API name of the corresponding API
action = 'Invoke'
# API parameter. Enter the name of the function to be invoked, RequestResponse
(sync), and Event
(async)
action_params = {
'FunctionName': "function-name",
'InvocationType': "Event"
}
print('Start SCF')
def main_handler(event, context):
try:
# Instantiate an authentication object. The Tencent Cloud account secretId
and secretKey
need to be passed in as the input parameters
cred = credential.Credential("SecretId", "SecretKey")
# Instantiate the client object to request the product and the region where the function is located
client = scf_client.ScfClient(cred, "ap-shanghai")
# Call the API, initiate the request, and print the returned result
ret = client.call(action, action_params)
print(json.loads(ret)["Response"]["Result"]["RetMsg"])
except TencentCloudSDKException as err:
print(err)
If you need to deploy a function in the SCF console and use the SDK to invoke other functions, you need to package the tencentcloud
library and function code together into a zip file.
API Explorer provides various capabilities such as online call, signature verification, SDK code generation, and quick API search, greatly improving the ease of use of TencentCloud API.
You can also use Tencent SCF SDK (Tencentserverless SDK), which integrates SCF business flow APIs to simplify the function invocation method and eliminates your need to encapsulate public TencentCloud APIs. For more information, please see Calling SDK Across Functions.
Was this page helpful?