Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query AWS CloudSearch domain using Python boto3 library?

I'm trying to use boto3 to query my CloudSearch domain using the docs as a guide: http://boto3.readthedocs.io/en/latest/reference/services/cloudsearchdomain.html#client

import boto3
import json

boto3.setup_default_session(profile_name='myprofile')
cloudsearch = boto3.client('cloudsearchdomain')

response = cloudsearch.search(
    query="(and name:'foobar')",
    queryParser='structured',
    returnFields='address',
    size=10
)
print( json.dumps(response) )

...but it fails with:

botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://cloudsearchdomain.eu-west-1.amazonaws.com/2013-01-01/search"

But how am I supposed to set or configure the endpoint or domain that I want to connect to? I tried adding an endpoint parameter to the request, thinking maybe it was an accidental omission from the docs, but I got this error response:

Unknown parameter in input: "endpoint", must be one of: cursor, expr, facet, filterQuery, highlight, partial, query, queryOptions, queryParser, return, size, sort, start, stats

The docs say:

The endpoint for submitting Search requests is domain-specific. You submit search requests to a domain's search endpoint. To get the search endpoint for your domain, use the Amazon CloudSearch configuration service DescribeDomains action. A domain's endpoints are also displayed on the domain dashboard in the Amazon CloudSearch console.

I know what my search endpoint is, but how do I supply it?

like image 639
RTF Avatar asked Jan 02 '23 09:01

RTF


1 Answers

I found a post on a Google forum with the answer. You have to add the endpoint_url parameter into the client constructor e.g.

client = boto3.client('cloudsearchdomain', endpoint_url='http://...')

I hope those docs get updated, because I wasted a lot of time before I figured that out.

like image 59
RTF Avatar answered Jan 04 '23 23:01

RTF