尝试将 AWS.STS.getSessionToken 与 node.js 一起使用无法检索令牌
trying to use AWS.STS.getSessionToken with node.js not able to retrieve token
我对 node js 有点陌生,我真的被这个奇怪的错误困住了:
此代码段从 AWS 检索一组凭证:
const params = {
DurationSeconds: 3600
};
const credentials = await sts
.getSessionToken(params)
.promise()
.then(data => {
return data.Credentials;
})
.catch(err => {
logger.error('ERROR: ', err);
});
logger.debug('Loaded credentials:', credentials);
logger.debug('Token:', credentials.SessionToken);
return credentials;
}
然而,即使它在输出中打印出 SessionToken 在生成的 Credentials 对象上可用:
debug: debug: Loaded credentials: {"AccessKeyId":"REDACTED","SecretAccessKey":"REDACTED","SessionToken":"FwoGZXIvYXdzEK3//////////wEaDB6VRt+NtN7NL08wRiKBAYkJTVAX4Sx9GZSmm/WEarfCiO5ITnBMh4hQTCX7Yu13WBck+8/CF8XUcicTRUfosVVz5/+FUETRuuUhg3oLySt+ijs5v32BTIo7EU4LI0L69uOYAxGIPSIOpEl635/36Ytl0GNgQvMC1DuwmgTNzm8qA==","Expiration":"2020-06-09T12:33:00.000Z","label":"{\"name\": \"cluster-gtw\"}","timestamp":"2020-06-09 14:33:00"}
无法使用:
error: undefined {"label":"{\"name\": \"cluster-gtw\"}","timestamp":"2020-06-09 14:33:00"}
error: TypeError: Cannot read property 'SessionToken' of undefined
非常感谢您帮助我理解为什么 SessionToken 不会打印而 Credentials 会。
万一有人遇到这个问题,这个有效:
logger.debug(credentials['SessionToken']);
return credentials['SessionToken'];
我对 node js 有点陌生,我真的被这个奇怪的错误困住了:
此代码段从 AWS 检索一组凭证:
const params = {
DurationSeconds: 3600
};
const credentials = await sts
.getSessionToken(params)
.promise()
.then(data => {
return data.Credentials;
})
.catch(err => {
logger.error('ERROR: ', err);
});
logger.debug('Loaded credentials:', credentials);
logger.debug('Token:', credentials.SessionToken);
return credentials;
}
然而,即使它在输出中打印出 SessionToken 在生成的 Credentials 对象上可用:
debug: debug: Loaded credentials: {"AccessKeyId":"REDACTED","SecretAccessKey":"REDACTED","SessionToken":"FwoGZXIvYXdzEK3//////////wEaDB6VRt+NtN7NL08wRiKBAYkJTVAX4Sx9GZSmm/WEarfCiO5ITnBMh4hQTCX7Yu13WBck+8/CF8XUcicTRUfosVVz5/+FUETRuuUhg3oLySt+ijs5v32BTIo7EU4LI0L69uOYAxGIPSIOpEl635/36Ytl0GNgQvMC1DuwmgTNzm8qA==","Expiration":"2020-06-09T12:33:00.000Z","label":"{\"name\": \"cluster-gtw\"}","timestamp":"2020-06-09 14:33:00"}
无法使用:
error: undefined {"label":"{\"name\": \"cluster-gtw\"}","timestamp":"2020-06-09 14:33:00"}
error: TypeError: Cannot read property 'SessionToken' of undefined
非常感谢您帮助我理解为什么 SessionToken 不会打印而 Credentials 会。
万一有人遇到这个问题,这个有效:
logger.debug(credentials['SessionToken']);
return credentials['SessionToken'];