Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I am using the npm elasticsearch package to search my AWS ES domain. Everything seems to work fine when I use Postman to make POST requests with my AWS IAM credentials. I wanted to do the same in my code (node.js).

Here is code:

const elasticsearch     = require('elasticsearch');

const awsHttpClient     = require('http-aws-es');

const AWS               = require('aws-sdk');

const client            = new elasticsearch.Client({ 

    host: 'my-aws-es-endpoint', 

    connectionClass: awsHttpClient,

    amazonES: {

        region: 'us-east-1',

        credentials: new AWS.Credentials('my-access-key','my-secret-key')

    }

});

But when I run client.search(), it fails with an error:

Elasticsearch ERROR: 2018-10-31T15:12:22Z

  Error: Request error, retrying

  POST https://my-endpoint.us-east-1.es.amazonaws.com/my-index/student/_search => Data must be a string or a buffer

It also gives me a warning

Elasticsearch WARNING: 2018-10-31T15:12:22Z

  Unable to revive connection: https://my-endpoint.us-east-1.es.amazonaws.com/

When I use just the aws-sdk, it works fine (probably because I sign the request there?)

Can someone suggest what I am I doing wrong here?

1 Answer

0 votes
by (44.4k points)

Solved by specifying the region. So this is how you can solve it.

amazonES: {

        region: 'us-east-1',

        credentials: new AWS.Credentials('my-access-key','my-secret-key')

    }

}
 

Also, add this before the above code, because the problem is the elasticsearch client is not able to read it from within.

AWS.config.region = 'us-east-1';

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...