Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在腾讯云serverless上,发送短信,报错没传SecretId #69

Open
daqi opened this issue Jan 25, 2021 · 5 comments
Open

在腾讯云serverless上,发送短信,报错没传SecretId #69

daqi opened this issue Jan 25, 2021 · 5 comments

Comments

@daqi
Copy link

daqi commented Jan 25, 2021

环境:Nodejs10.15
编码:Typescript
component:https://github.com/serverless-components/tencent-koa
tencentcloud-sdk-nodejs 和其他依赖打包上传到,再由函数调用发送短信
本地环境不报错,把tencentcloud-sdk-nodejs上传到函数里也不报错,放到层里就报错,其他npm包没有这种问题

async function smsPromise(params: any) {
    const Client = tencentcloud.sms.v20190711.Client;
    const client = new Client({
        credential: {
            /* 必填:腾讯云账户密钥对secretId,secretKey。
             * 这里采用的是从环境变量读取的方式,需要在环境变量中先设置这两个值。
             * 你也可以直接在代码中写死密钥对,但是小心不要将代码复制、上传或者分享给他人,
             * 以免泄露密钥对危及你的财产安全。
             * CAM密匙查询: https://console.cloud.tencent.com/cam/capi */
            secretId: config.tencent_sms_secretId,
            secretKey: config.tencent_sms_secretKey
        },
        /* 必填:地域信息,可以直接填写字符串ap-guangzhou,或者引用预设的常量 */
        region: 'ap-guangzhou',
        profile: { language: 'zh-CN' }
    });
    console.log({
        credential: {
            secretId: config.tencent_sms_secretId,
            secretKey: config.tencent_sms_secretKey
        },
        region: 'ap-guangzhou',
        profile: { language: 'zh-CN' }
    });  // 日志显示是正常的,有SecretId
    console.log(params);

    return new Promise((resolve, reject) => {
        client.SendSms(params, function(err, response) {
            // 请求异常返回,打印异常信息
            if (err) {
                reject(err);
                return;
            }
            // 请求正常返回,打印response对象
            resolve(response);
        });
    });
}
@zqfan
Copy link
Member

zqfan commented Jan 31, 2021

有最近的requestid可以贴一下。
不过估计是因为环境变量没有设置正确,或者没有正确传递。

@daqi
Copy link
Author

daqi commented Feb 1, 2021

有最近的requestid可以贴一下。
不过估计是因为环境变量没有设置正确,或者没有正确传递。

9c213cd52735ebf96e17a11f1f877fb1

@zqfan
Copy link
Member

zqfan commented Feb 1, 2021

9c213cd52735ebf96e17a11f1f877fb1

这个不是requestid,requestid是uuid4格式的,并且固定RequestId字段名。
如果搞不定,还是到控制台提工单咨询吧。

@daqi
Copy link
Author

daqi commented Feb 2, 2021

9c213cd52735ebf96e17a11f1f877fb1

这个不是requestid,requestid是uuid4格式的,并且固定RequestId字段名。
如果搞不定,还是到控制台提工单咨询吧。

这个requestId是云函数日志里显示的requestId
我业务逻辑已经跑通了,不需要帮我,我只是帮你们反馈一下

@sunoj
Copy link

sunoj commented Feb 5, 2021

应该是云函数环境的版本3.0.147的版本bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants