使用Node访问AWS CLI配置文件

时间:2019-08-28 05:00:09

标签: javascript node.js amazon-web-services ssm

我已使用AWS Client Profile Credentialaws configure存储在AWS CLI中。我想在我的节点程序中使用这些凭据。我使用了SharedIniFileCredentials方法来检索凭证,它仅返回accessKeyId和其他一些数据,但我也需要SecretkeyRegion

代码

var credentials = new AWS.SharedIniFileCredentials({
    profile: 'default'
});
AWS.config.credentials = credentials;
console.log(credentials);
const SSM = require('aws-sdk/clients/ssm');
const ssm = new SSM()
const query = {
    "Names": ["XXXXX" + XXX],
    "WithDecryption": true
}
ssm.getParameters(query, (err, data) => {
    if (err) {
        console.log('error');
    } else {
        console.log('sucess');
        data;
    }

})

输出

SharedIniFileCredentials {
  expired: false,
  expireTime: null,
  refreshCallbacks: [],
  accessKeyId: 'XXXXXXXXXXXX', // I have loaded Access key, Secret Key and Region in Profile Config. But I am get only accessKeyID
  sessionToken: undefined,
  filename: undefined,
  profile: 'default',
  disableAssumeRole: false,
  preferStaticCredentials: false,
  tokenCodeFn: null,
  httpOptions: null }

0 个答案:

没有答案