From 549f1544f421cf16feedbb3e7710bd87db42bdde Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Mon, 30 Dec 2024 15:36:01 +0000 Subject: [PATCH] Update docs on how to connect with Amazon OpenSearch Service via HTTP. (#8987) * Update python-low-level.md to detail how to connect with Amazon OpenSearch service via HTTP This commit enhances the documentation on how to connect with Amazon OpenSearch service via HTTP. Signed-off-by: Adriel Martins <37420665+Martins6@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> Signed-off-by: Adriel Martins <37420665+Martins6@users.noreply.github.com> --------- Signed-off-by: Adriel Martins <37420665+Martins6@users.noreply.github.com> Co-authored-by: kolchfa-aws <105444904+kolchfa-aws@users.noreply.github.com> (cherry picked from commit ca2e7f4c33616f86ada0bb6da1422bfa09ce1165) Signed-off-by: github-actions[bot] --- _clients/python-low-level.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/_clients/python-low-level.md b/_clients/python-low-level.md index ba40fa3f45..4b13c36775 100644 --- a/_clients/python-low-level.md +++ b/_clients/python-low-level.md @@ -106,7 +106,7 @@ client = OpenSearch( ## Connecting to Amazon OpenSearch Service -The following example illustrates connecting to Amazon OpenSearch Service: +The following example illustrates connecting to Amazon OpenSearch Service using IAM credentials: ```python from opensearchpy import OpenSearch, RequestsHttpConnection, AWSV4SignerAuth @@ -127,6 +127,25 @@ client = OpenSearch( pool_maxsize = 20 ) ``` + +To connect to Amazon OpenSearch Service through HTTP with a username and password, use the following code: + +```python +from opensearchpy import OpenSearch + +auth = ('admin', 'admin') # For testing only. Don't store credentials in code. + +client = OpenSearch( + hosts=[{"host": host, "port": 443}], + http_auth=auth, + http_compress=True, # enables gzip compression for request bodies + use_ssl=True, + verify_certs=True, + ssl_assert_hostname=False, + ssl_show_warn=False, +) +``` + {% include copy.html %} ## Connecting to Amazon OpenSearch Serverless @@ -359,4 +378,4 @@ print(response) ## Next steps - For Python client API, see the [`opensearch-py` API documentation](https://opensearch-project.github.io/opensearch-py/). -- For Python code samples, see [Samples](https://github.com/opensearch-project/opensearch-py/tree/main/samples). \ No newline at end of file +- For Python code samples, see [Samples](https://github.com/opensearch-project/opensearch-py/tree/main/samples).