Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python code works, Node.js not. Why? ES AWS #61

Open
falent opened this issue Jan 27, 2019 · 4 comments
Open

Python code works, Node.js not. Why? ES AWS #61

falent opened this issue Jan 27, 2019 · 4 comments

Comments

@falent
Copy link

falent commented Jan 27, 2019

I am totally shocked why my code in node.js doesnt work and with python works like a charm? It is so weird for me :( Could someone take a look please and tell me what I am doing wrong?

Python code:

from elasticsearch import Elasticsearch
import json
esclient = Elasticsearch(['https://61699**.eu-central-1.aws.cloud.es.io/recipes/'],
http_auth=('d**', 'e.**'), scheme="https")

response = esclient.search(index="", body=json.dumps({"query": {"match": {'Title':'Easter Bunny Cupcakes'}}}))
    
print response

Node.js code:

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

const client = elasticsearch.Client({
  hosts: ''61699**.eu-central-1.aws.cloud.es.io/recipes/',
  connectionClass: require('http-aws-es'),
  amazonES: {
    accessKey: 'd**',
    secretKey: 'e.**',
  },
  awsConfig: new AWS.Config({region: 'eu-central-1'}),
});


client.index({
  index: '',
  type: '_doc',
  body: {
    query: {
      match: {
        Title: 'Easter Bunny Cupcakes',
      },
    },
  },
}, function(err, data) {
  console.log(err);
});
@jonmanzo
Copy link

jonmanzo commented Jan 28, 2019

Send your creds over in awsConfig, amazonES is no longer used

If you're running this on Lambda, be sure to include the session token int he creds as well

@falent
Copy link
Author

falent commented Jan 28, 2019

Do you have any working code example? it's so frustrating that it doesnt work with node.js :(

@jonmanzo
Copy link

jonmanzo commented Jan 28, 2019

Should work for you...

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

const client = elasticsearch.Client({
  hosts: ''61699**.eu-central-1.aws.cloud.es.io/recipes/',
  connectionClass: require('http-aws-es'),
  awsConfig: new AWS.Config({
    region: 'eu-central-1',
    credentials: new AWS.Credentials(
       'd**', // Access Key
       'e.**', // Secret
       '***', // If running on Lambda: Session Token (process.env.AWS_SESSION_TOKEN)
    )
  }),
});

@falent
Copy link
Author

falent commented Jan 28, 2019

Thank you for help :) Unfortunetly I am getting a such error:

Trace: [security_exception] action [indices:data/read/search] requires authentication, with { header={ WWW-Authenticate={ 0="Bearer realm=\"security\"" & 1="Basic realm=\"security\" charset=\"UTF-8\"" } } } at C:\Users\falent\Desktop\node\a.js:30:12 at process._tickCallback (internal/process/next_tick.js:68:7)

Do you know what does it mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants