This topic describes how to install Security Token Service (STS) SDK for Node.js and provides an example on how to use STS SDK for Node.js.

Background information

  • Alibaba Cloud provides OpenAPI Explorer to simplify API usage. You can use OpenAPI Explorer to debug API operations and dynamically generate SDK sample code.
  • For more information about STS API operations, see What is STS?.
  • For more information about STS endpoints, see Endpoints.

Install the SDK for Node.js

Run the following command to install the SDK for Node.js and add dependencies to the package.json file:

$ npm install @alicloud/pop-core --save

You can download the installation packages of the SDK for Node.js from the following links:


The following sample code provides an example on how to call the AssumeRole operation by using the SDK for Node.js. For other operations, you can use OpenAPI Explorer to debug the operations and obtain sample code.

const Core = require('@alicloud/pop-core');

// Construct an Alibaba Cloud client that is used to initiate requests. 
// Specify the AccessKey ID and AccessKey secret of the requester. The requester can be a Resource Access Management (RAM) user or a RAM role. 
var client = new Core({
  accessKeyId: '<accessKeyId>',
  accessKeySecret: '<accessSecret>',
  endpoint: 'https://sts.<regionId>',
  apiVersion: '2015-04-01'

// Specify request parameters. For more information about the parameters, see API Reference. 
var params = {
  "RoleArn": "<RoleARN>",
  "RoleSessionName": "<RoleSessionName>",
  "Policy": "<Policy>",
  "DurationSeconds": 3600

var requestOption = {
  method: 'POST'

// Initiate the request and obtain a response. 
client.request('AssumeRole', params, requestOption).then((result) => {
}, (ex) => {