Skip to content

Package Python applications using Google or-tools for AWS Lambda.

License

Notifications You must be signed in to change notification settings

christianklotz/or-tools-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

or-tools-lambda

Package Python applications using Google or-tools for AWS Lambda.

Google Optimization Tools (OR-Tools) is a fast and portable software suite for solving combinatorial optimization problems.

Instead of creating and configuring your own EC2 instance to work around the installations requirements to run the application on Lambda (for example, or-tools doesn't qualify for inclusion in pip due to some of its dependencies), or-tools-lambda uses Docker to create a deployable package locally.

This project is based on the discussion in google/or-tools#259.

Prerequisites

You'll need to have Docker installed. Clone the repo to package the handler.py sample function that includes a basic program using or-tools .

To make this work with your existing Python project, simply add Dockerfile and package.sh.

Build

The package.sh creates a dist folder and dist.zip containing the folder contents as well as or-tools dependency.

First, build the Docker image.

$ docker build -t or-tools-lambda .

Run package.sh within the Docker container.

$ docker run --rm -v $(pwd):/handler -w /handler -i or-tools-lambda ./package.sh

Note: The package.sh script does not check for or installs any additional that you may have added to your Python application. Should you require any, follow the instructions in the AWS Lambda documentation and adjust package.sh accordingly, so all dependencies are included in the resulting dist.zip.

Deploy

If you want to test the application on AWS Lambda, upload dist.zip using the AWS console or the AWS CLI.

$ aws lambda update-function-code --function-name MyLambdaFunction --zip-file fileb://dist.zip

After invoking the function you should see something like this.

"{\"x\": 1.0, \"y\": 2.0}"

Acknowledgements

The approach was originally described in tunamonster/aws_lambda_ortools.

About

Package Python applications using Google or-tools for AWS Lambda.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published