开发者社区> 问答> 正文

client.assumeRole授权访问出错

报错内容:

{
    "message": "getaddrinfo ENOTFOUND sts.aliyuncs.com, POST https://sts.aliyuncs.com -1 (connected: false, keepalive socket: false, socketHandledRequests: 1, socketHandledResponses: 0)\nheaders: {}"
}

环境:本地localhost

后端: koa

代码片段:

const sts = async (ctx) => {
    const conf = JSON.parse(fs.readFileSync(path.resolve(__dirname, './config.json')));
    let policy;
    if (conf.PolicyFile) {
      policy = fs.readFileSync(path.resolve(__dirname, conf.PolicyFile)).toString('utf-8');
    }
    const client = new STS({
        accessKeyId: conf.AccessKeyId,
        accessKeySecret: conf.AccessKeySecret
    });
    try {
        console.log(conf);
        const result = await client.assumeRole(conf.RoleArn, policy, conf.TokenExpireTime);
        ctx.set('Access-Control-Allow-Origin', '*');
        ctx.set('Access-Control-Allow-METHOD', 'GET');
        ctx.body = {
            code: 0,
            message: '请求sts签名成功',
            bucket,
            region,
            accessKeyId: result.credentials.AccessKeyId,
            accessKeySecret: result.credentials.AccessKeySecret,
            securityToken: result.credentials.SecurityToken,
            expiration: result.credentials.Expiration
        };
    } catch (e) {
        ctx.body = utils.errorHandle(e.message || '');
    }
};

程序前几次没有报这个错,可以顺利上传图片,后面就一直报这个错。望各路大神帮忙!

展开
收起
1628018868746295 2020-09-09 00:10:15 1996 0
2 条回答
写回答
取消 提交回答
  • 加入圈子https://h5.dingtalk.com/circle/healthCheckin.html?corpId=ding04bb8e24d2ca6d4b7041969b1885fe17&9b576=903b7&cbdbhh=qwertyuiop&origin=1

    2021-02-23 17:29:19
    赞同 展开评论 打赏
  • 已查到问题,DNS系統不能正常工作,可以在host添加106.11.61.111 sts.aliyuncs.com

    2020-09-09 17:20:37
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载