AWS API Gateway as a Proxy For Elasticsearch


(Josh Day) #1

I was wondering if anyone has any experience with using the AWS API Gateway as a proxy for Elasticsearch queries.

I have a few queries that I'd like to reuse and grab from a web application, so for simplicity it would be good to have an GET endpoint that can return that hard coded request from elasticsearch without requiring a running any further code to do the work.

Perhaps mapping query strings through as variables would allow specific areas within the query strings to be set to further manipulate the returned data.

The AWS API Gateway allows you to set mapping templates, which I think could be used to do this but I'm just not sure where to start here.

I can't find anything like this on the internet so any help would be appreciated.


(Stefano Buliani) #2

Amazon API Gateway introduced a few new features that may make the task easier: https://aws.amazon.com/blogs/aws/api-gateway-update-new-features-simplify-api-development/

catch-all path variables and the ANY http method let you create a "proxy" API without defining the entire structure. The proxy integrations for HTTP and Lambda functions allow you pass through an entire request and response to the backend endpoint.

If you wanted your API to mimc the exact structure of the ES APIs then you should be able to achieve this with an HTTP proxy integration. If you wanted to change the structure of the API then I would recommend using a Lambda function in-between. Configuring the backend as a proxy integration means you don't have to declare all of the possible parameters in API Gateway.


(Josh Day) #3

I was hoping to avoid using the lambda intermediary but it's looking more like that's gonna be the way to go. :frowning: If only you could write pre-scripted queries on ES and hit them with a nice clean GET with query strings.

Cheers


(Stefano Buliani) #4

You could do that by defining static query string parameters for the integration request, then use mapping expressions like "method.request.path/queryString" etc to pull values from the incoming request. See the docs here: http://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html


(system) #5