@alicloud/sts-sdk

中文文档
1.0.2发布于 2019/03/08MITCommonJS近 30 天下载 1.2万

alibaba cloud sts client for node.js

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. API Doc
  4. Method: assumeRole()
  5. Method: getCallerIdentity()
  6. Method (Japan only) : generateSessionAccessKey()
  7. Test & Coverage
  8. License

Alibaba Cloud STS client for Node.js

npm version Travis Build Status Appveyor Build status codecov license

Installation

npm install @alicloud/sts-sdk

Node.js >= 8.5.0 required.

Usage

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 Doc

Method: assumeRole()

Arguments

  • roleArn String required - aliyun resource name, acs:ram::${accountID}:role/${roleName}
  • roleSessionName String required - differentiate tokens, /^[a-zA-Z0-9.@-_]+$/
  • policy String optional - @see https://help.aliyun.com/document_detail/28664.html
  • durationSeconds Number optional - the specified expiration time (seconds), range: 900~3600, default value is 3600

Returns

  • credentials Object - sts credentials

Method: getCallerIdentity()

Returns

  • userInfo Object - the identity of the current caller

Method (Japan only): generateSessionAccessKey()

Returns

  • akInfo Object - session key & secret

Test & Coverage

You should set environment variables before running the test or coverage. For example:

  • run test
ACCESS_KEY=<your access key> SECRET_KEY=<your secret key> ENDPOINT=sts.aliyuncs.com npm run test
  • run code coverage
ACCESS_KEY=<your access key> SECRET_KEY=<your secret key> ENDPOINT=sts.aliyuncs.com npm run cov

License

MIT

版本与发布记录

@alicloud/sts-sdk 共发布 4 个版本,首次发布于 2019/02/25;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.2latest2019/03/087 年前
1.0.12019/02/267 年前
1.0.02019/02/257 年前
0.0.12019/02/257 年前

关于 @alicloud/sts-sdk 的常见问题

@alicloud/sts-sdk 是什么?

alibaba cloud sts client for node.js

如何安装 @alicloud/sts-sdk?

在项目目录运行 npm install @alicloud/sts-sdk,或使用 pnpm add / yarn add / bun add。

@alicloud/sts-sdk 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/alicloud__sts-sdk 是否存在。

@alicloud/sts-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@alicloud/sts-sdk 可以商用吗?

@alicloud/sts-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@alicloud/sts-sdk 的下载量有多少?

根据 npm 官方下载统计,@alicloud/sts-sdk 在 2026/10/06 – 2026/11/04 这 30 天内被下载 12,361 次,日均约 412 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@alicloud/sts-sdk 还在维护吗?

最新版本 1.0.2 发布于 2019/03/08(7 年前);至今共发布 4 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/02/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。