Giter VIP home page Giter VIP logo

aws-lambda-libpostal-python-demo's Introduction

aws-lambda-libpostal-example

This repository contains sample code that uses the libpostal library to parse addresses into parts. The code is deployed as a Lambda function and is packaged as a Docker container. The image size is over 2GB in size because the libpostal library contains NLP models that are more than 2GB.

Usage


export AWS_REGION=us-east-2

# Get AWS account ID for later use
ACCOUNT_ID=`aws sts get-caller-identity |jq -r .Account`

# Create ECR repository
aws ecr create-repository --repository-name libpostal-demo

# Package the Docker image
docker build -t libpostal-demo:latest .

# Get ECR Docker login
aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com

# Tag image
docker tag libpostal-demo:latest ${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/libpostal-demo:latest

# Push image
docker push ${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/libpostal-demo:latest

# Create the CloudFormation stack
aws cloudformation deploy           \
    --template template.yaml        \
    --stack-name libpostal-example  \
    --parameter-overrides           \
        ImageName=${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/libpostal-demo  \
        ImageTag=latest             \
    --capabilities CAPABILITY_IAM

Testing

# Get the Lambda function name created by CloudFormation
LAMBDA_FUNCTION=`aws cloudformation describe-stacks --stack-name libpostal-example --query "Stacks[0].Outputs[?OutputKey=='FunctionName'].OutputValue" --output text`

# Sample input address
PAYLOAD='{ "address" : "123 33rd St, New York City, NY 10001"}'
PAYLOAD_BASE64=`echo $PAYLOAD |base64`

# Invoke the function and redirect the output to a file named 'output'
aws lambda invoke --function-name $LAMBDA_FUNCTION --payload $PAYLOAD_BASE64 output

# View the output
cat output

Output:

{
  "house_number": "123",
  "road": "33rd st",
  "city": "new york city",
  "state": "ny",
  "postcode": "10001"
}

aws-lambda-libpostal-python-demo's People

Contributors

vinayselvaraj avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mandolin-dev

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.