Coder Social home page Coder Social logo

address-parser's Introduction

address-parser microservice

A REST endpoint consuming an address string and returning a json with address fields:

curl -X POST "http://127.0.0.1:5000/parse" -H  "accept: application/json" -H  "Content-Type: application/json" -d "{  \"address\": \"5760 Teredo St., Sechelt, BC, Canada, VON 3A0\"}"
    {
        "city": "Sechelt",
        "state": "BC",
        "street_address": "5760, Teredo St.",
        "postcode": "VON 3A0",
        "country": "Canada",
    },

Use Locally

  1. Install libpostal
  2. Instal deps with pipenv install && pipenv shell
  3. Run flask application export FLASK_APP=api.py && flask run
  4. Test at http://127.0.0.1:5000/swagger-ui/

Deploying on AWS Lambda

Libpostal requires 2GB on disk and in memory for the model, so the AWS Lambda deployment consists of 2 steps:

  1. Getting libpostal files on shared EFS
  2. Configuring pypostal from Lambda

Getting libpostal files on shared EFS

  1. Create EFS, Amazon Linux 2 AMI with attached EFS:
  • Use an instance with 4GB memory.
  • Make sure VPC has NFS inbound rule and DNS resolution
  1. Install libpostal and copy data files (datadir) and library files (*.so and pkgconfig) from /usr/local/lib to EFS

Configuring library from Lambda and Lambda itself

  1. Build pypostal from master for Lambda

docker build -t pypostal . && docker create -ti --name dummy pypostal bash && docker cp dummy:/postal/postal ./ && docker rm dummy

  1. Deploy Lambda with zappa in the same region:
  • don't forget to add Lambda's pypostal
  • Max out memory
  • point to libpostal files on EFS:
LD_LIBRARY_PATH /mnt/efs/libpostal_lib/lib

LIBPOSTAL_DATA_DIR /mnt/efs/libpostal_model/libpostal

PKG_CONFIG_PATH /mnt/efs/libpostal_lib/lib/pkgconfig
  • Add EFS to Lambda:

Use the same VPC

configure subnets for public access

curl -X POST "https://fe5k5zd4k4.execute-api.us-west-2.amazonaws.com/dev/parse" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"address\": \"5760 Teredo St., Sechelt, BC, Canada, VON 3A0\"}"

address-parser's People

Contributors

manycoding avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  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.