0 votes
1 view
in AWS by (18.2k 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 (42.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';

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...