tomharvey/glpk-lambda-layer

Basic usage / howto

Opened this issue · 4 comments

aff commented

Hi again Tom
How would a basic client call to glpk look like? I tried

import json
import glpk

def lambda_handler(event, context):
    return {
        'statusCode': 200,
        'body': json.dumps(glpk.glp_version())
    }

and got

Response:
{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'glpk'",
  "errorType": "Runtime.ImportModuleError"
}

Thanks

Good question. I'm using PuLP as opposed to directly importing glpk.

I'll supply a minimal function (untested, might get a chance to do it properly tomorrow) and some notes on dependancies.

Minimal function

When trying to get the layer to work i had a simple function which went something like:

import pulp

def handler(event, context)
    test_results = pulp.pulpTestAll()
    return {
        'statusCode': 200,
        'body': test_results
    }

But, that's off the top of my head

Dependancies

The layer installs GLPK, the OS level libraries. But, you'll also want to install some python libraries.

Overall, I use the serverless.com tool to manage the deployment of my code to AWS and I'd recommend it. It has a plugin which will ensure that the python libraries can be compiled from requirements.txt and installed into the lambda function

Have a crack at the above. Otherwise I'll try to bash out a minimal operating function to use as a better usage guide.

If you have success, feel free to PR me a working function. :)

I had a quick look through this, but I'm currently struggling to pip install glpk.

Based on your error message, I'd say that the glpk Python library isn't available to your lambda function.

The layer makes the GNU Linear Programming Kit available to the lambda functions, and I'm assuming that pyGLPK requires those; as PuLP does as well.

But, I can't find too much of a README about pyGLPK.

If you want to share your code and/or how you're packaging it and deploying to Lambda I can hopefully help.

aff commented

Hi Tom, I simply uploaded the zip archive using the AWS console and naïvely expected it to work. I guess some additional plumbing is required?