Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access AWS Elasticsearch from Node JS

I have my nodejs lambda trying to index data into ES, but it's failing because of this error:

2018-01-15T23:39:09.578Z (node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 131): Authorization Exception ::

User: anonymous is not authorized to perform: es:ESHttpPost on resource: ****

I have applied AmazonESFullAccess policy to the Lambda function role.
What am I missing?

like image 294
NoBigDeal Avatar asked Mar 07 '23 03:03

NoBigDeal


1 Answers

I was able to resolve this issue. Code was missing 'connectionClass' and 'amazonES' parameters.

var AWS = require('aws-sdk');
var connectionClass = require('http-aws-es');
var elasticsearch = require('elasticsearch');
var elasticClient = new elasticsearch.Client({  
    host: ***,
    log: 'error',
    connectionClass: connectionClass,
    amazonES: {
      credentials: new AWS.EnvironmentCredentials('AWS')
    }
});
like image 58
NoBigDeal Avatar answered Mar 16 '23 20:03

NoBigDeal