Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CARTO Pass-Through API #19

Closed
3 tasks
andrewbt opened this issue Feb 8, 2017 · 10 comments
Closed
3 tasks

CARTO Pass-Through API #19

andrewbt opened this issue Feb 8, 2017 · 10 comments
Assignees
Milestone

Comments

@andrewbt
Copy link
Contributor

andrewbt commented Feb 8, 2017

@timwis
Copy link
Contributor

timwis commented Feb 9, 2017

Now that I've actually read that doc page, it looks perfect!

@andrewbt
Copy link
Contributor Author

andrewbt commented Feb 9, 2017 via email

@timwis
Copy link
Contributor

timwis commented Feb 12, 2017

This is almost working:

resources:
  Resources:
    ProxyResource:
      Type: AWS::ApiGateway::Resource
      Properties:
        ParentId:
          Fn::GetAtt:
            - ApiGatewayRestApi # our default Rest API logical ID
            - RootResourceId
        PathPart: carto # the endpoint in your API that is set as proxy
        RestApiId:
          Ref: ApiGatewayRestApi
    ProxyMethod:
      Type: AWS::ApiGateway::Method
      Properties:
        ResourceId:
          Ref: ProxyResource
        RestApiId:
          Ref: ApiGatewayRestApi
        AuthorizationType: NONE
        HttpMethod: GET # the method of your proxy. Is it GET or POST or ... ?
        MethodResponses:
          - StatusCode: 200
        Integration:
          IntegrationHttpMethod: GET
          Type: HTTP
          Uri: https://phl.carto.com/api/v2/sql # the URL you want to set a proxy to
          IntegrationResponses:
            - StatusCode: 200

The problem appears to be that API Gateway doesn't pass querystrings along by default, and it looks like the only way to enable them is to explicitly activate each one. Fortunately, with carto, we can activate q, format, and filename, though what if carto adds another parameter? And perhaps there are others that simply aren't in the sql api docs? Definitely not ideal :-/

Need someone familiar with API Gateway / cloudformation to weigh in. I've asked in freenode ##aws and the og-aws slack.

EDIT: Also, I think that ideally it would be data.phila.gov/api/v2/sql?q=xxxx for the URL schema, rather than /carto. Not super firm on it but it seems to make sense to me. Note that one of the socrata url structures is /api/views/.... but that shouldn't matter.

EDIT2: Apparently you can make the resource pathpart {proxy+} to use it like a "greedy parameter" and then use {proxy} in the method uri, like https://phl.carto.com/{proxy}. This may include querystrings. I haven't been able to get it to work. In particular, I was having trouble making the path something like /carto/{proxy+} or /api/v2/{proxy+}.

@timwis timwis modified the milestone: MVP Feb 14, 2017
@timwis
Copy link
Contributor

timwis commented Feb 17, 2017

@andrewbt can you post the screenshots of the 3 configuration forms you got working when you get a chance? I can try to translate into cloudformation code this weekend.

@timwis
Copy link
Contributor

timwis commented Feb 21, 2017

Posted for help

@andrewbt
Copy link
Contributor Author

Reposting screenshots from #37 :

Testable here: https://zsp6egcjhf.execute-api.us-east-1.amazonaws.com/dev/carto/v2/sql?q=select * from indego_stations where ST_DWITHIN(the_geom::geography, ST_GeographyFromText('POINT(-75.1636 39.9524)'),500)

Screenshots:
screen shot 2017-02-23 at 12 13 02 pm
screen shot 2017-02-23 at 12 13 33 pm
screen shot 2017-02-23 at 12 13 57 pm
screen shot 2017-02-23 at 12 16 07 pm

@andrewbt
Copy link
Contributor Author

API Gateway allows you to “export” an API (under Stages) as a Swagger YAML or JSON document. One of the options for creating an API is through importing a Swagger document.

If we can’t get serverless.yaml to work with the HTTP-proxy integration and other options we need there for the pass-through API, Swagger seems like a good alternative and will still let us keep “deployment in code” rather than through the AWS console UI.

@timwis
Copy link
Contributor

timwis commented Feb 24, 2017

@timwis timwis closed this as completed in 9150f45 Feb 28, 2017
@timwis
Copy link
Contributor

timwis commented Feb 28, 2017

giphy

We bloody cracked it!!

I got swagger to work, but it ended up overwriting all the serverless functions. But then I noticed that the swagger itself was basically cloudformation. So that told me what pieces were missing from the original cloudformation. And it's working! :D

https://67qq7fn418.execute-api.us-east-1.amazonaws.com/dev/carto/api/v2/sql?q=select%20*%20from%20pol_incidents_part1_part2%20limit%2010

@andrewbt
Copy link
Contributor Author

andrewbt commented Feb 28, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants