I'm trying to use a MFA protected SQS queue from a node.js application.
The code looks like this:
var sts = new AWS.STS(),
awsSerialNumber = process.env.AWS_MFA_SERIAL_NUMBER,
awsTokenCode = process.env.AWS_MFA_TOKEN;
sts.getSessionToken({
DurationSeconds: 13600,
SerialNumber: awsSerialNumber,
TokenCode: awsTokenCode
}, function (err, data) {
if (err) {
console.log('STS error:', err, err.stack);
return;
}
AWS.config.credentials = sts.credentialsFrom(data);
sqs = new AWS.SQS();
});
So I'm calling the process as
$ AWS_MFA_TOKEN=123456 npm start
However, I'm getting the following error:
{ message: 'The security token included in the request is expired',
code: 'ExpiredToken',
time: ...,
requestId: '...',
statusCode: 403,
retryable: true }
Though the token is fresh.
I have also tried with AWS.config.update
passing accessKeyId
, secretAccessKey
and sessionToken
. However, the code is not even reaching that point.