节点的 Alibaba Cloud STS 客户端
安装
npm install @alicloud/sts-sdk
节点.js 所需经费.
使用量
const StsClient = require('@alicloud/sts-sdk');
const sts = new StsClient({
endpoint: 'sts.aliyuncs.com', // check this from sts console
accessKeyId: '***************', // check this from aliyun console
accessKeySecret: '***************', // check this from aliyun console
});
async function demo() {
const res1 = await sts.assumeRole(`acs:ram::${accountID}:role/${roleName}`, 'xxx');
console.log(res1);
const res2 = await sts.getCallerIdentity();
console.log(res2);
}
demo();
API 文档
方法 : assumeRole()
参数
- 角色定义 字符串 所需经费 - 阿利云资源名称,
acs:ram::${accountID}:role/${roleName} - 角色会议Name 字符串 所需经费 - 区别符号,/^[a-zA-Z0-9.].@ ]+$/
- 政策 字符串 选项 - @ 见 https://help.aliyun.com/document detail/28664.html (中文(简体) )
- 持续时间 数目 选项 - 指定的过期时间(秒),范围:900~360,默认值为3600
回返
- 全权证书 对象 - sts 证书
方法 : getCallerIdentity()
回返
- 用户信息 对象 - 当前调用者的身份
方法 (仅日本)数字 : generateSessionAccessKey()
回返
- akInfo 数据 对象 - 会话密钥( C)
测试覆盖( S)
在运行测试或覆盖之前,您应该设定环境变量 。 例如:
- 运行测试
ACCESS_KEY=<your access key> SECRET_KEY=<your secret key> ENDPOINT=sts.aliyuncs.com npm run test
- 运行代码覆盖
ACCESS_KEY=<your access key> SECRET_KEY=<your secret key> ENDPOINT=sts.aliyuncs.com npm run cov
