1

我正在使用 AWS Elastic 搜索服务并编写了一个 Node.js 包装器(在 ECS dockerized 容器中运行)。IAM 角色用于创建与 Elastic 搜索的单例连接。

我试图通过在每个请求之前检查 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;
4

0 回答 0