Explore Courses Blog Tutorials Interview Questions
0 votes
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, it fails with an error:

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

  Error: Request error, retrying

  POST => 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:

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

Browse Categories