Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I created one AWS elasticsearch instance. I want to access it using a python script. I specified my AWS configuration (access key, secret key, region). I am using below code to access the AWS ES instance:

from elasticsearch import Elasticsearch, RequestsHttpConnection

from requests_aws4auth import AWS4Auth

AWS_ACCESS_KEY = '**************'

AWS_SECRET_KEY = '*****************'

region = 'us-east-1'

service = 'es'

awsauth = AWS4Auth(AWS_ACCESS_KEY, AWS_SECRET_KEY, region, service)

host = 'https://kbckjsdkcdn.us-east-1.es.amazonaws.com' # For example, my-test-domain.us-east-1.es.amazonaws.com

es = Elasticsearch(

    hosts = [{'host': host, 'port': 443}],

    http_auth = awsauth,

    use_ssl = True,

    verify_certs = True,

    connection_class = RequestsHttpConnection

)

print es.info()

When I am running the above code, I am getting the following error:

elasticsearch.exceptions.ConnectionError:  ConnectionError(HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //search-opendata-2xd6pwilq5sv4ahomcuaiyxmqe.us-east-1.es.amazonaws.com:443/ (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10ee72310>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',))) caused by: ConnectionError(HTTPSConnectionPool(host='https', port=443): Max retries exceeded with url: //search-opendata-2xd6pwilq5sv4ahomcuaiyxmqe.us-east-1.es.amazonaws.com:443/ (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x10ee72310>: Failed to establish a new connection: [Errno 8] nodename nor servname provided, or not known',)))

How can I resolve this error?

1 Answer

0 votes
by (44.4k points)

This problem might have occurred because you use https:// in the host.

Change the line like this

host = 'kbckjsdkcdn.us-east-1.es.amazonaws.com'

See if it works or not. Also, your comment after that line suggests you not to use the protocol while mentioning the host.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

Browse Categories

...