Coder Social home page Coder Social logo

kaniska / apigateway-lambda-rds-postgis Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lingyielia/apigateway-lambda-rds-postgis

0.0 1.0 0.0 946 KB

Create an API using Amazon Web Services

Home Page: https://geocrosswalk.herokuapp.com/api

Jupyter Notebook 84.35% JavaScript 5.48% Python 10.17%

apigateway-lambda-rds-postgis's Introduction

Build an API using AWS API Gateway and Lambda

API Gateway takes in http calls and trigger the Lambda function. Lambda function takes in the request data (lon/lat in json format) from the API Gateway, queries the Database, and returns the result back to API Gateway. In this example, I will build an API for query geo-cross-walk data of New York City.

gateway

Create Lambda function

  1. Choose Runtime. Runtime is the runtime environment for the Lambda function you are uploading. Some major runtime supported by Lambda function are Node.js, Python, Java, Go, and C#. Here we use Node.js. The basic syntax of Lambda function is:

     exports.myHandler = function(event, context, callback) {
         ...
         // Use callback() and return information to the caller.  
     }
    
  2. Choose Role. Role defines the permissions this Lambda function has regarding all AWS resources.

  3. Upload the .zip file containing the Lambda function you've written and its related packages.

functioncode

Note: The handler defines how to trigger this lambda function. "index" means to find the file "index.js", "handler" corresponds to the function name "handler".

  1. Add API Gateway as trigger.

addtrigger

Create API

  1. In the API Gateway interface, create a new API.
  2. Choose Actions --> Create Resource, here the Resource Name is "nyc".
  3. Choose Actions --> Create Method as GET, and connect it with the Lambda function created before.

method

  1. For this /nyc-GET Method, choose Integration Request --> Body Mapping Templates, add a mapping template in it.
  • Content-Type: application/json

      {
          "long": $input.params('long'),
          "lati": $input.params('lati')
      }
    
  1. Choose Actions --> Deploy API. Now the API is ready for query.

Test

Query NYC dataset:

NYU CUSP: (40.693258, -73.987493)

    https://d5tgnm602g.execute-api.us-east-1.amazonaws.com/beta/nyc?long=-73.987493&lati=40.693258

cusp

Query LA County dataset:

Los Angeles International Airport: (33.945421, -118.408518)

    https://d5tgnm602g.execute-api.us-east-1.amazonaws.com/beta/la?long=-118.408518&lati=33.945421

airport

You can also integrate geo-cross-walk data in your analysis using this API. See examples here.

apigateway-lambda-rds-postgis's People

Contributors

lingyielia avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.