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.API | Description |
Creates function | |
Deletes function | |
Gets function details | |
Executes function | |
Gets function list | |
Updates function code | |
Updates function configuration |
Python3.6
as an example:# -*- coding: utf8 -*-import jsonfrom tencentcloud.common import credentialfrom tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException# Import the client models of the corresponding product modulefrom tencentcloud.scf.v20180416 import scf_client,models# API name of the corresponding APIaction = '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 parameterscred = credential.Credential("SecretId", "SecretKey")# Instantiate the client object to request the product and the region where the function is locatedclient = scf_client.ScfClient(cred, "ap-shanghai")# Call the API, initiate the request, and print the returned resultret = client.call(action, action_params)print(json.loads(ret)["Response"]["Result"]["RetMsg"])except TencentCloudSDKException as err:print(err)
Node.js12.16
as an example:/opt/node_modules/tencentcloud-sdk-nodejs
.'use strict';const tencentcloud = require("/var/user/node_modules/tencentcloud-sdk-nodejs");// Import the client models of the corresponding product moduleconst ScfClient = tencentcloud.scf.v20180416.Client;const models = tencentcloud.scf.v20180416.Models;const clientConfig = {// Tencent Cloud authentication informationcredential: {secretId: "secretId",secretKey: "secretKey",},// Product regionregion: "ap-beijing",profile:{}}exports.main_handler = (event, context) => {console.log(event)// console.log(context)// Instantiate the client object to request the product and the region where the function is locatedconst client = new ScfClient(clientConfig);console.log("Start SCF")// Call the API you want to access through the client object; you need to pass in the request object and the response callback functionclient.Invoke({"FunctionName":"function-name","InvocationType":"Event"}, function(err, response) {// The request returns an exception and the exception information is printedif (err) {console.log(err);return;}// The request is returned normally, and the `response` object is printedconsole.log("success");});};
tencentcloud-sdk-nodejs
varies by Node.js
runtime environment version. For more information, please see Notes on Node.js.Node.js12.16
as an example:'use strict';const tencentcloud = require("tencentcloud-sdk-nodejs");const Credential = tencentcloud.common.Credential;// Import the client models of the corresponding product moduleconst ScfClient = tencentcloud.scf.v20180416.Client;const models = tencentcloud.scf.v20180416.Models;exports.main_handler = (event, context) = {console.log(event)// console.log(context)// Instantiate an authentication object. The Tencent Cloud account `secretId` and `secretKey` need to be passed in as the input parameterslet cred = new Credential("SecretId", "SecretKey");// Instantiate the client object to request the product and the region where the function is locatedlet client = new ScfClient(cred, "ap-beijing");// Instantiate a request object and call `invoke()`console.log("Start SCF")let request = new models.InvokeRequest();// API parameter. Enter the name of the function to be invoked, `RequestResponse` (sync), and `Event` (async)let params = '{"FunctionName":"function-name", "InvocationType":"Event"}'request.from_json_string(params);// Call the API you want to access through the client object; you need to pass in the request object and the response callback functionclient.Invoke(request, function(err, response) {// The request returns an exception and the exception information is printedif (err) {console.log(err);return;}// The request is returned normally, and the `response` object is printedconsole.log(response.to_json_string());});};
<?phprequire_once '/var/user/tencentcloud-sdk-php/TCloudAutoLoader.php'; # Pay attention to the import pathuse TencentCloud\\Common\\Credential;use TencentCloud\\Common\\Profile\\ClientProfile;use TencentCloud\\Common\\Profile\\HttpProfile;use TencentCloud\\Common\\Exception\\TencentCloudSDKException;use TencentCloud\\Scf\\V20180416\\ScfClient;use TencentCloud\\Scf\\V20180416\\Models\\InvokeRequest;function main_handler($event, $context) {print "good";print "\\n";var_dump($event);var_dump($context);try {// Instantiate an authentication object. The Tencent Cloud account `secretId` and `secretKey` need to be passed in as the input parameters$cred = new Credential("SecretId", "SecretKey");$httpProfile = new HttpProfile();$httpProfile->setEndpoint("scf.tencentcloudapi.com");$clientProfile = new ClientProfile();$clientProfile->setHttpProfile($httpProfile);// Instantiate the client object to request the product and the region where the function is located$client = new ScfClient($cred, "ap-shanghai", $clientProfile);$req = new InvokeRequest();// API parameter. Enter the name of the function to be invoked, `RequestResponse` (sync), and `Event` (async)$params = '{"FunctionName":"function-name", "InvocationType":"Event"}';$req->fromJsonString($params);$resp = $client->Invoke($req);print_r($resp->toJsonString());}catch(TencentCloudSDKException $e) {echo $e;}return "hello";}?>
tencentcloud
library and function code together into a zip file.
Was this page helpful?