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

AWS ElasticSearch service #280

Closed
mathom opened this issue Oct 8, 2015 · 11 comments
Closed

AWS ElasticSearch service #280

mathom opened this issue Oct 8, 2015 · 11 comments

Comments

@mathom
Copy link

mathom commented Oct 8, 2015

With the new AWS ElasticSearch service they have the HTTP requests authenticated via IAM. With a couple tweaks I got a requests sigv4 plugin to work for this: tedder/requests-aws4auth#2

The resulting code is pretty succinct (see the PR for how I'm connecting to ES) so maybe this would be a good addition to the documentation? Is anyone working on anything related to this?

@ipartola
Copy link

ipartola commented Oct 8, 2015

+1. For whatever silly reason Amazon rolled out their ES service without supporting most of their IAM authentication mechanisms. Authorizing servers by public IP is silly, and the only real option is to sign requests to the ElasticSearch endpoint. I think ideally elasticsearch-py should provide some way to augment requests with additional headers so that the AWS request signing authentication can be tacked on without making it a part of this project directly.

@mathom
Copy link
Author

mathom commented Oct 8, 2015

Yep I think IAM signing is the way to go. We're in VPC so IP auth is not an option.

@honzakral
Copy link
Contributor

Thank you for this, I will mention it in the documentation with other environment considerations.

@honzakral
Copy link
Contributor

Is there a canonnical example I can use for the documentation I could use?

@ipartola
Copy link

Here's more or less what I got working:

Step 1: Install requests-aws4auth from @mathom's fix branch (https://github.com/mathom/requests-aws4auth/tree/es_fix) at least until tedder/requests-aws4auth#2 is merged.

Step 2: Initialize your connection to AWS ES like so:

import elasticsearch

host = 'YOURHOST.us-east-1.es.amazonaws.com'
awsauth = AWS4Auth(your_access_key, your_secret_key, region, 'es')

es = elasticsearch.Elasticsearch(
    hosts=[{'host': host, 'port': 443}],
    http_auth=awsauth,
    use_ssl=True,
    verify_certs=True,
    connection_class=elasticsearch.connection.RequestsHttpConnection
)
print(es.cluster.health())

@honzakral
Copy link
Contributor

Thanks! I will have to wait for the patch to be merged then before referring to it, I will leave this ticket here open as a reminder for both me and anyone looking for a solution.

@mathom
Copy link
Author

mathom commented Nov 2, 2015

Just a heads up, the required changes have been merged and released to pypi in aws4auth 0.7

@streeter
Copy link

Has anyone else had any issues with Amazon's ES service? It seems like when Amazon changes the underlying IP for the hostname, my connections stop working. I'm connecting with the hostname (not IP), and every once in a while the connections stop returning any results until I restart the webserver. However, if I connect from the same box, via a python shell (with the same settings), the connection returns results.

My hunch is that somewhere the IP is getting cached so when Amazon moves the ES cluster by pointing the DNS to a new IP, we're still using the old connection. Any thoughts on how best to fix this?

@mathom
Copy link
Author

mathom commented Nov 26, 2015

@streeter we restart our web workers after so many requests (gunicorn option, I believe) so we haven't encountered this.

@streeter
Copy link

@mathom Thanks. Was just investigating that option for us.

@honzakral
Copy link
Contributor

Fixed via a7a56b1

Thank you!

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

4 participants