CredentialProviderChain
Updated at:
Use this API to obtain access credentials for other Alibaba Cloud resources.
CredentialProviderChain().resolvePromise()
This API returns a Promise object. You can use this object to obtain temporary credentials for other Alibaba Cloud resources. The credentials automatically update every 15 minutes by default. Call this API to obtain the latest credentials before you access a cloud resource. The credential parameters are as follows:
| Parameter | Type | Description |
| accessKeyId | String | The AccessKey ID. An AccessKey pair, which consists of an AccessKey ID and an AccessKey secret, is used to authenticate API requests to Alibaba Cloud services. |
| accessKeySecret | String | The AccessKey secret. |
| securityToken | String | The security token. |
Example
The following example shows how to use CredentialProviderChain().resolvePromise() to access Object Storage Service (OSS).
Note For more information, see Access Alibaba Cloud OSS.
'use strict';
var leSdk = require('linkedge-core-sdk');
var credChain= new leSdk.CredentialProviderChain();
var OSS = require('./node_modules/ali-oss');
exports.handler = function (event, context, callback) {
// Retrieves group role credential.
credChain.resolvePromise()
.then((cred) => {
console.log('Access Key Id: %s, Access Key Secret: %s, Security Token: %s',
cred.accessKeyId, cred.accessKeySecret, cred.securityToken);
// Constructs a client to interact with OSS cloud service.
var client = new OSS({
accessKeyId: cred.accessKeyId,
accessKeySecret: cred.accessKeySecret,
stsToken: cred.securityToken,
region: 'oss-cn-shanghai',
bucket: 'le-fc-bucket',
});
/* Upload local file to cloud. */
return client.put('fileFromEdge.txt', "/linkedge/run/localFile.txt");
})
.then((result) => {
console.log(result);
callback(null);
})
.catch((err) => {
console.log(err);
callback(err);
});
};
Is this page helpful?