Richard in Linux 1 minutes

Connect Aws Elastic Search Curl

I want to connect to Amazon ES by EC2 using Curl? Watch this..

It’s worth bearing in mind here that “Standard clients, such as curl, cannot perform the request signing that is required of identity-based access policies. You must use an IP address-based access policy that allows anonymous access to successfully perform the instructions for this step.”

Luckily we can use boto to do the hard work for us. Check this out..

# connect_test.py
from boto.connection import AWSAuthConnection

class ESConnection(AWSAuthConnection):

    def __init__(self, region, **kwargs):
        super(ESConnection, self).__init__(**kwargs)
        self._set_auth_region_name(region)
        self._set_auth_service_name("es")

    def _required_auth_capability(self):
        return ['hmac-v4']

if __name__ == "__main__":
    client = ESConnection(
            region='eu-central-1',
            host='search-mycluster-gfsd4w424pjswfjr6tc4xkyzge.eu-central-1.es.amazonaws.com',
            is_secure=False)

    resp = client.make_request(method='GET',path='/')
    print resp.read()

Happy Days.