接口名称 | 接口功能 |
创建函数 | |
删除函数 | |
获取函数详细信息 | |
运行函数 | |
获取函数列表 | |
更新函数代码 | |
更新函数配置 |
Python3.6
为例:# -*- coding: utf8 -*-import jsonfrom tencentcloud.common import credentialfrom tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException# 导入对应产品模块的client modelsfrom tencentcloud.scf.v20180416 import scf_client,models# 对应接口的接口名action = 'Invoke'# 接口参数,输入需要调用的函数名,RequestResponse(同步) 和 Event(异步)action_params = {'FunctionName': "function-name",'InvocationType': "Event"}print('Start SCF')def main_handler(event, context):try:# 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKeycred = credential.Credential("SecretId", "SecretKey")# 实例化要请求产品的client对象,以及函数所在的地域client = scf_client.ScfClient(cred, "ap-shanghai")# 调用接口,发起请求,并打印返回结果ret = client.call(action, action_params)print(json.loads(ret)["Response"]["Result"]["RetMsg"])except TencentCloudSDKException as err:print(err)
Node.js12.16
为例:/opt/node_modules/tencentcloud-sdk-nodejs
。'use strict';const tencentcloud = require("/var/user/node_modules/tencentcloud-sdk-nodejs");// 导入对应产品模块的client models。const ScfClient = tencentcloud.scf.v20180416.Client;const models = tencentcloud.scf.v20180416.Models;const clientConfig = {// 腾讯云认证信息credential: {secretId: "secretId",secretKey: "secretKey",},// 产品地域region: "ap-beijing",profile:{}}exports.main_handler = (event, context) => {console.log(event)// console.log(context)// 实例化要请求产品的client对象,以及函数所在的地域const client = new ScfClient(clientConfig);console.log("Start SCF")// 通过client对象调用想要访问的接口,需要传入请求对象以及响应回调函数client.Invoke({"FunctionName":"function-name","InvocationType":"Event"}, function(err, response) {// 请求异常返回,打印异常信息if (err) {console.log(err);return;}// 请求正常返回,打印response对象console.log("success");});};
Node.js12.16
为例:'use strict';const tencentcloud = require("tencentcloud-sdk-nodejs");const Credential = tencentcloud.common.Credential;// 导入对应产品模块的client models。const ScfClient = tencentcloud.scf.v20180416.Client;const models = tencentcloud.scf.v20180416.Models;exports.main_handler = (event, context) = {console.log(event)// console.log(context)// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKeylet cred = new Credential("SecretId", "SecretKey");// 实例化要请求产品的client对象,以及函数所在的地域let client = new ScfClient(cred, "ap-beijing");// 实例化一个请求对象,调用invoke()console.log("Start SCF")let request = new models.InvokeRequest();// 接口参数,输入需要调用的函数名,RequestResponse(同步) 和 Event(异步)let params = '{"FunctionName":"function-name", "InvocationType":"Event"}'request.from_json_string(params);// 通过client对象调用想要访问的接口,需要传入请求对象以及响应回调函数client.Invoke(request, function(err, response) {// 请求异常返回,打印异常信息if (err) {console.log(err);return;}// 请求正常返回,打印response对象console.log(response.to_json_string());});};
<?phprequire_once '/var/user/tencentcloud-sdk-php/TCloudAutoLoader.php'; #注意引用路径use 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 {// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey$cred = new Credential("SecretId", "SecretKey");$httpProfile = new HttpProfile();$httpProfile->setEndpoint("scf.tencentcloudapi.com");$clientProfile = new ClientProfile();$clientProfile->setHttpProfile($httpProfile);// 实例化要请求产品的client对象,以及函数所在的地域$client = new ScfClient($cred, "ap-shanghai", $clientProfile);$req = new InvokeRequest();// 接口参数,输入需要调用的函数名,RequestResponse(同步) 和 Event(异步)$params = '{"FunctionName":"function-name", "InvocationType":"Event"}';$req->fromJsonString($params);$resp = $client->Invoke($req);print_r($resp->toJsonString());}catch(TencentCloudSDKException $e) {echo $e;}return "hello";}?>
本页内容是否解决了您的问题?