Node.js AWS elasticsearch服务:Curl http命令工作正常,但不是elasticsearch npm
我正在ec2实例上运行的当前Node.js项目中配置AWS Elasticsearch服务。AWS elasticsearch域和ec2实例位于同一VPC中。我已将Elasticsearch npm配置为与AWS Elasticsearch服务连接。下面是配置Node.js AWS elasticsearch服务:Curl http命令工作正常,但不是elasticsearch npm,node.js,amazon-web-services,
elasticsearch,Node.js,Amazon Web Services,
elasticsearch,我正在ec2实例上运行的当前Node.js项目中配置AWS Elasticsearch服务。AWS elasticsearch域和ec2实例位于同一VPC中。我已将Elasticsearch npm配置为与AWS Elasticsearch服务连接。下面是配置 const elasticsearch = require('elasticsearch'); const awsHttpClient = require('http-aws-es') let esConn = new elastics
const elasticsearch = require('elasticsearch');
const awsHttpClient = require('http-aws-es')
let esConn = new elasticsearch.Client({
host: 'https:****.amazonaws.com',
auth: 'user:password',
protocol: 'https',
port: 443,
log: 'debug',
connectionClass: awsHttpClient,
apiVersion: '7.x',
});
module.exports={
"esConn" : esConn
};
但我的错误率越来越低
2021-05-20 14:26 +00:00: StatusCodeError: Authorization Exception
2021-05-20 14:26 +00:00: at respond (/home/ec2-user/elasticsearch/node_modules/elasticsearch/src/lib/transport.js:349:15)
2021-05-20 14:26 +00:00: at checkRespForFailure (/home/ec2-user/elasticsearch/node_modules/elasticsearch/src/lib/transport.js:306:7)
2021-05-20 14:26 +00:00: at done (/home/ec2-user/elasticsearch/node_modules/http-aws-es/connector.js:48:7)
2021-05-20 14:26 +00:00: at IncomingMessage.cleanUp (/home/ec2-user/elasticsearch/node_modules/http-aws-es/src/node.js:20:7)
2021-05-20 14:26 +00:00: at IncomingMessage.emit (events.js:327:22)
2021-05-20 14:26 +00:00: at IncomingMessage.EventEmitter.emit (domain.js:482:12)
2021-05-20 14:26 +00:00: at endReadableNT (_stream_readable.js:1221:12)
2021-05-20 14:26 +00:00: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
2021-05-20 14:26 +00:00: status: 403,
2021-05-20 14:26 +00:00: displayName: 'AuthorizationException',
2021-05-20 14:26 +00:00: path: '/',
2021-05-20 14:26 +00:00: query: {},
2021-05-20 14:26 +00:00: body: undefined,
2021-05-20 14:26 +00:00: statusCode: 403,
2021-05-20 14:26 +00:00: response: '',
2021-05-20 14:26 +00:00: toString: [Function],
2021-05-20 14:26 +00:00: toJSON: [Function]
2021-05-20 14:26 +00:00: }
而当我尝试curl命令时,我就能得到结果。我也尝试过下面的配置,但不起作用
let esConn = new elasticsearch.Client({
host: 'https:****.amazonaws.com',
connectionClass: awsHttpClient
});
谢谢