# Cannot connect to AWS elasticsearch cluster with flask app and Python elasticsearch wrapper

**URL:** <https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093>\
**Category:** Elasticsearch\
**Created:** [December 17, 2018, 8:42am UTC](https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093 "2018-12-17T08:42:09Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [December 19, 2018, 2:04pm UTC](https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093/21 "2018-12-19T14:04:31Z")

</div>

If you are on AWS you can set up a VPC and connect using an internal IP address that is not open to the internet. You will need to open up port 9200, but it will only be accessible within the VPC. This way all traffic goes through your Python application and Elasticsearch can not be accessed from the internet.

---

<div class="post-metadata">

**Author:** ![ichiban88](https://avatars.discourse-cdn.com/v4/letter/i/b77776/32.png) [@ichiban88](https://discuss.elastic.co/u/ichiban88)\
**Post date:** [December 19, 2018, 2:07pm UTC](https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093/22 "2018-12-19T14:07:47Z")

</div>

that sounds the way to do it. I will examine that, thank you.

---

<div class="post-metadata">

**Author:** ![tcass](https://avatars.discourse-cdn.com/v4/letter/t/a88e57/32.png) [@tcass](https://discuss.elastic.co/u/tcass)\
**Post date:** [December 24, 2018, 1:18pm UTC](https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093/23 "2018-12-24T13:18:54Z")

</div>

is the flask app running on the same instance as ES?

If so, use 'host': '0.0.0.0' in your python code above. Also you don't need the http:// in your host value.

---

<div class="post-metadata">

**Author:** ![tcass](https://avatars.discourse-cdn.com/v4/letter/t/a88e57/32.png) [@tcass](https://discuss.elastic.co/u/tcass)\
**Post date:** [December 24, 2018, 1:25pm UTC](https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093/24 "2018-12-24T13:25:31Z")

</div>

Even if your flask app is not on the same server as the index, if you do have some flask app running on that server, that can serve as the layer between the user and elastic search.

All incoming queries to elasticsearch from wherever on the internet can talk to that app instead, through whatever port, and that app can then query elasticsearch. It would only support the kinds of queries you want users to be able to issue to elasticsearch. Even if the API for this app was something like:

{'query': 'your full es query goes here'}

you could have some string matching filters to prevent malicious queries. This wouldn't be ideal, but the point is you can control what gets to elasticsearch with the logic in that flask app.

---

<div class="post-metadata">

**Author:** ![ichiban88](https://avatars.discourse-cdn.com/v4/letter/i/b77776/32.png) [@ichiban88](https://discuss.elastic.co/u/ichiban88)\
**Post date:** [December 24, 2018, 4:06pm UTC](https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093/25 "2018-12-24T16:06:48Z")

</div>

Yes it is. 0.0.0.0 in my python code means that the connection string would be:

`es = Elasticsearch("0.0.0.0") ?`

I suspect that is not what you mean. I will give it a try though. Perhaps you mean:

```
if __name__ == ' __main__':
    application.debug = True
    application.run(host="0.0.0.0")

```

At the moment I am exploring the private IP address in a vpc with acces that way.

I appreciate you thinking about my problem, thank you.

---

<div class="post-metadata">

**Author:** ![tcass](https://avatars.discourse-cdn.com/v4/letter/t/a88e57/32.png) [@tcass](https://discuss.elastic.co/u/tcass)\
**Post date:** [December 24, 2018, 4:25pm UTC](https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093/26 "2018-12-24T16:25:07Z")

</div>

I'm using elasticsearch 5.5, but what works for me is:

```auto
es_hosts = [{"host":"0.0.0.0","port":9200}]
Elasticsearch(hosts=es_hosts)

```

Also, just in case, your flask app isn't containerized in any way right?

---

<div class="post-metadata">

**Author:** ![ichiban88](https://avatars.discourse-cdn.com/v4/letter/i/b77776/32.png) [@ichiban88](https://discuss.elastic.co/u/ichiban88)\
**Post date:** [December 24, 2018, 7:23pm UTC](https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093/27 "2018-12-24T19:23:12Z")

</div>

thank you, very helpful. No it isn't. Happy Christmas!

---

<div class="post-metadata">

**Author:** ![tcass](https://avatars.discourse-cdn.com/v4/letter/t/a88e57/32.png) [@tcass](https://discuss.elastic.co/u/tcass)\
**Post date:** [December 24, 2018, 7:52pm UTC](https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093/28 "2018-12-24T19:52:32Z")

</div>

no problem, same to you!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 21, 2019, 7:52pm UTC](https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093/29 "2019-01-21T19:52:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

[Previous page](https://discuss.elastic.co/t/cannot-connect-to-aws-elasticsearch-cluster-with-flask-app-and-python-elasticsearch-wrapper/161093.md?page=1)
