Comments (8)
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.
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.
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.
(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.
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.
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.
@SingaporeClouds can you try with the latest version? I believe this might've been fixed in 92f59a6
from docker-lambda.
Closing due to lack of activity
from docker-lambda.
Related Issues (20)
- Missing files from provided.al2 HOT 1
- Need support for python3.9 HOT 10
- nodejs16.x support HOT 6
- Golang update to 1.17 HOT 1
- Is java11 image on AL2 and Corretto?
- How can I build image for python3.9 runtime? HOT 4
- Help with Debugging Go Lambda HOT 1
- Rebuild images? HOT 2
- What is the status of this project? HOT 7
- Make `myfunction` and `9001` configurable?
- Support for Node 14.x? HOT 1
- Boto3 and botocore need upgrading HOT 5
- Require image for ARM64 architecture
- Support for .NET 6
- Multi-arch support specially arm64 HOT 1
- Current ruby release (v2.7.2p137) out of date (now v2.7.6p?) HOT 1
- Missing .py file causing attributeError on lambda
- Jenkins agent install on lambci/lambda:build-python3.7 HOT 2
- Debugging with Pycharm
- [Question] Support for Provided Runtimes (Namely C++)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from docker-lambda.