我正在使用AWS Elastic搜索服务,并编写了一个Node.js包装器(在ECS dockerized容器中运行)。 IAM角色用于通过弹性搜索创建单例连接。
我试图通过在每次请求前检查AWS.config.credentials.needsRefresh()来刷新会话令牌-但是,即使会话过期后,它始终返回true。显然,AWS在抱怨403错误。任何想法将不胜感激。
var AWS = require('aws-sdk');
var config = require('config');
var connectionClass = require('http-aws-es');
var elasticsearch = require('elasticsearch');
AWS.config.getCredentials(function() {
AWS.config.update({
credentials: new AWS.Credentials(AWS.config.credentials.accessKeyId,AWS.config.credentials.secretAccessKey,AWS.config.credentials.sessionToken),
region: 'us-east-1'
});
}
)
var client = new elasticsearch.Client({
host: `${config.get('elasticSearch.host')}`,
log: 'debug',
connectionClass: connectionClass,
amazonES: {
credentials: new AWS.EnvironmentCredentials('AWS')
}
});
module.exports = client;