Closed heimanba closed 2 years ago
ak/sk、sts校验要用RAM提供的接口,不要自己用正则,太不规范了。贴一段其他项目中校验cred的代码,可以用ts翻译下
{"IdentityType":"RAMUser","AccountId":"1740298130743624","RequestId":"F7C09E25-0C6C-5BD3-B744-949414CB0CC6","PrincipalId":"215654737666918818","UserId":"215654737666918818","Arn":"acs:ram::1740298130743624:user/fc-private"}
AccessKeyID
, AccessKeySecret
,如果有我们认为可能是阿里云的账号,校验接口,返回AccountId.
成功写入account ID, 失败显示,您配置的可能是阿里云的密钥信息,你可以使用 s config add xxxx -f
来强制写入 。const Core = require('@alicloud/pop-core');
var client = new Core({
accessKeyId: process.env['ACCESS_KEY_ID'],
accessKeySecret: process.env['ACCESS_KEY_SECRET'],
securityToken: process.env['SECURITY_TOKEN'],
endpoint: 'https://sts.cn-hangzhou.aliyuncs.com',
apiVersion: '2015-04-01'
});
var params = {}
var requestOption = {
method: 'POST'
};
client.request('GetCallerIdentity', params, requestOption).then((result) => {
console.log(JSON.stringify(result));
}, (ex) => {
console.log(ex);
})
您可能在配置一个错误的阿里云密钥,请检查密钥信息的准确性。如果您配置并非阿里云密钥,可以通过增加-f
参数,强行写入。或执行s config add *** -f
You may be configuring an incorrect Alibaba Cloud SecretKey. Please check the accuracy of them. If your configuration is not an Alibaba Cloud SecretKey, you can force writing by adding the -f
parameter. Or execute s config add *** -f
已支持添加AK/SK时候无需填写主账号AccountID