# Create Python elasticsearch connection

**URL:** https://discuss.elastic.co/t/create-python-elasticsearch-connection/319690
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [November 23, 2022, 11:37pm UTC](https://discuss.elastic.co/t/create-python-elasticsearch-connection/319690 "2022-11-23T23:37:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![3482bd7cf80a5a43e5a9](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/3482bd7cf80a5a43e5a9/32/113701_2.png) [@3482bd7cf80a5a43e5a9](https://discuss.elastic.co/u/3482bd7cf80a5a43e5a9)
#### Post date: [November 23, 2022, 11:37pm UTC](https://discuss.elastic.co/t/create-python-elasticsearch-connection/319690/1 "2022-11-23T23:37:29Z")

</div>

Hi  
I'm using python client:[Python Elasticsearch Client — Elasticsearch 8.0.0 documentation](https://elasticsearch-py.readthedocs.io/en/master/#) to initiate API calls to my ES hosted behind AWS API gateway.  
Can i use the SDK to talk to my ES stack if mTLS has been enabled?  
I tried connecting using the snippet below but it failed:

```auto
es = Elasticsearch(
    url,
    client_cert=cert,
    client_key=key,
    verify_certs=False,
    headers={"x-api-key": "mykey"}
)

```

My API gateway will require:  
client cert,client key and x-api-key

I can confirm that initiating the below curl works perfectly:  
curl -X GET '{host}:443/\_cluster/health?pretty' --header "x-api-key: {}" --cert /home/ec2-user/{}.cer --key /home/ec2-user/{}.pem

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [November 30, 2022, 1:17am UTC](https://discuss.elastic.co/t/create-python-elasticsearch-connection/319690/2 "2022-11-30T01:17:29Z")

</div>

Welcome to our community! 😃

You might be able to do this with [Connection Layer API — Elasticsearch 8.0.0 documentation](https://elasticsearch-py.readthedocs.io/en/master/connection.html#urllib3httpconnection-default-connection-class), but it's not something I have done myself.

---

<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: [December 28, 2022, 1:18am UTC](https://discuss.elastic.co/t/create-python-elasticsearch-connection/319690/3 "2022-12-28T01:18:26Z")

</div>

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