npm install @alicloud/sts-sdk
Node.js >= 8.5.0 required.
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();
assumeRole()
acs:ram::${accountID}:role/${roleName}
getCallerIdentity()
generateSessionAccessKey()
You should set environment variables before running the test or coverage. For example:
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