Git Product home page Git Product logo

Comments (8)

mhart avatar mhart commented on August 14, 2024

The return value of the Python function should work: https://github.com/lambci/docker-lambda/blob/master/examples/docker-run-python2.7/lambda_function.py

from docker-lambda.

SingaporeClouds avatar SingaporeClouds commented on August 14, 2024

I've tried using the python function return as implied from the example, but that does not work as expected.

# python_handler.py
import os
import sys

def lambda_handler(event, context):
    return { 
        "message" : "Returning from python handler"
    }

This will work when you call docker directly.
$ docker run -v "$PWD":/var/task lambci/lambda:python2.7 python_handler.lambda_handler
...
REPORT RequestId: ca86fb02-f856-4868-9384-995652163464 Duration: 8 ms Billed Duration: 100 ms Memory Size: 1536 MB Max Memory Used: 14 MB
{"message": "Returning from python handler"}

// But if you call the same handler from node using docker-lambda, the result is undefined. 
// temp.js
var dockerLambda = require('docker-lambda');
var lambdaCallbackResult = dockerLambda({
                dockerImage: "lambci/lambda:python2.7",
                handler: "python_handler.lambda_handler"
            });
console.log("From python -->",lambdaCallbackResult);

$ node temp.js
From python --> undefined

I'm unclear how to get lambdaCallBackResult to contain the value returned from the python lambda_handler.

from docker-lambda.

mhart avatar mhart commented on August 14, 2024

Hmmm, not sure why that's happening off the top of my head – quickly glancing at the code responsible seems to indicate it should work (it reads and parses from stdout – and I'm pretty sure that result is going to stdout)

Not in front of my comp at the moment, but should be able to look into this more later.

Here's what I'd be looking at:

https://github.com/lambci/docker-lambda/blob/master/python2.7/run/runtime-mock.py#L142
and
https://github.com/lambci/docker-lambda/blob/master/index.js#L61

from docker-lambda.

mhart avatar mhart commented on August 14, 2024

(Unless it's just simply a case of needing to trim() the stdout? We swallow all parse errors, so something like that could be happening)

from docker-lambda.

SingaporeClouds avatar SingaporeClouds commented on August 14, 2024

I see the same issue trying to retrieve the "It works!" string back from the https://github.com/lambci/docker-lambda/blob/master/examples/docker-run-python2.7/lambda_function.py example. These few lines of code replicate the same issue.

// temp.js
var dockerLambda = require('docker-lambda');
var lambdaCallbackResult = dockerLambda({
                dockerImage: "lambci/lambda:python2.7",
                handler: "lambda_function.lambda_handler"
            });
console.log("From python -->",lambdaCallbackResult);

$ node temp.js
From python --> undefined

from docker-lambda.

SingaporeClouds avatar SingaporeClouds commented on August 14, 2024

And for completeness, I confirmed that the result and the result only is going to standard out when called with exec.

// dockerLambda will not return result.
var dockerLambda = require('docker-lambda');
var lambdaCallbackResult = dockerLambda({
                dockerImage: "lambci/lambda:python2.7",
                handler: "lambda_function.lambda_handler"
            });
console.log("From dockerLambda -->",lambdaCallbackResult);

// exec will return result on stdout.
var exec = require('child_process').exec;
var cmd = 'docker run -v "$PWD":/var/task lambci/lambda:python2.7 lambda_function.lambda_handler';
exec(cmd, function(error, stdout, stderr) {
  console.log("From exec -->",stdout);
});

$ node temp.js
From dockerLambda --> undefined
From exec --> "It works!"

from docker-lambda.

mhart avatar mhart commented on August 14, 2024

@SingaporeClouds can you try with the latest version? I believe this might've been fixed in 92f59a6

from docker-lambda.

mhart avatar mhart commented on August 14, 2024

Closing due to lack of activity

from docker-lambda.

Related Issues (20)

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.