代码
// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
const tencentcloud = require("tencentcloud-sdk-nodejs");
const IotcloudClient = tencentcloud.iotcloud.v20180614.Client;
exports.main = async (event, context) => {
const clientConfig = {
credential: {
SecretId: event.secretId,
SecretKey: event.secretKey,
},
region: "",
profile: {
httpProfile: {
endpoint: "iotcloud.tencentcloudapi.com",
},
},
};
console.log(event)
const client = new IotcloudClient(clientConfig);
console.log(client)
const params = {};
const retval = client.DescribeProducts(params);
console.log(retval)
return retval;
client.DescribeProducts(params).then(
(data) => {
console.log(data);
/*
return{
success: true,
data: data
}
*/
},
(err) => {
console.error("error", err);
/*
return{
success: false,
err: err
}
*/
}
);
}
日志
START
{
"SecretId": "正确的ID",
"SecretKey": "正确的key",
"type": "iotcloud_describeProducts",
"userInfo": {
"appId": "xxxxxxxxxxx",
"openId": "xxxxxxxxxxx"
}
}
{
"apiVersion": "2018-06-14",
"credential": {
"credential": {},
"profile": {
"httpProfile": {
"endpoint": "iotcloud.tencentcloudapi.com"
}
},
"region": ""
},
"endpoint": "iotcloud.tencentcloudapi.com",
"path": "/",
"profile": {
"httpProfile": {
"endpoint": null,
"protocol": "https://",
"reqMethod": "POST",
"reqTimeout": 60
},
"signMethod": "xxxxxxxxxxx"
},
"region": null,
"sdkVersion": "SDK_NODEJS_3.0.104"
}
(node:7) UnhandledPromiseRejectionWarning: TypeError: cb is not a function
at IotcloudClient.failRequest (/var/lang/node10/lib/node_modules/tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client.js:65:9)
at doRequest.then.error (/var/lang/node10/lib/node_modules/tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client.js:72:98)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
REPORT RequestId:863720f9-dfb5-11eb-ad4b-5254000505e4 Duration:36ms Memory:256MB MemUsage:141.890625MB
END
不知道原因

tencentcloud-sdk-nodejs 换个版本试试