Comments (10)
I see the problem ... I needed to put all my deps in the root instead of in a subdirectory called lambda
(like what is created with -t lambda
☝️ ) -- now I'm getting a new strange error where my code is working in Lambda, but in docker-lambda
, I get:
START RequestId: 1b57a15a-5d37-40cc-9162-98657da0cea2 Version: $LATEST
Unable to parse input as json: No JSON object could be decoded
Traceback (most recent call last):
File "/usr/lib64/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/usr/lib64/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib64/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
{"stackTrace": [["/usr/lib64/python2.7/json/__init__.py", 339, "loads", "return _default_decoder.decode(s)"], ["/usr/lib64/python2.7/json/decoder.py", 364, "decode", "obj, end = self.raw_decode(s, idx=_w(s, 0).end())"], ["/usr/lib64/python2.7/json/decoder.py", 382, "raw_decode", "raise ValueError(\"No JSON object could be decoded\")"]], "errorType": "ValueError", "errorMessage": "No JSON object could be decoded"}
END RequestId: 1b57a15a-5d37-40cc-9162-98657da0cea2
REPORT RequestId: 1b57a15a-5d37-40cc-9162-98657da0cea2 Duration: 0 ms Billed Duration: 100 ms Memory Size: 1536 MB Max Memory Used: 14 MB
from docker-lambda.
@mhart thanks a lot for the reply.
One thing is not being very obvious from the docs, say I use a build image to create a new lambda which needs external packages. I let the Dockerfile take care of the package installations via pip install.
After that, when the new image is created, how do I invoke the lambda in this container for testing if the code is working fine?
docker build -t lambdafunc .
docker run --rm lambdafunc
gives me
zip I/O error: Permission denied
zip error: Could not create output file (lambdafunc.zip)
Or am I viewing the workflow incorrectly - my objective is to test the lambda locally till I iron out the kinks.
Thanks once again for such quick replies.
from docker-lambda.
When you say it doesn't seem to work, how are you running docker-lambda and how are you mounting your project directory onto /var/task
?
If you match the same layout as the zipfile expects, and mount that directory on /var/task
, it should work fine.
from docker-lambda.
Can you show me how you're invoking docker-lambda?
from docker-lambda.
Having the exact same issue, command:
docker run --rm -v <redacted>:/var/task:z lambci/lambda:python3.6 python3.6 -m pip --isolated install -t .serverless/requirements -r .serverless/requirements.txt
(via serverless-python-requirements)
from docker-lambda.
@AlecBenzer shouldn't you be using the build image if you're trying to install requirements?
from docker-lambda.
@mhart I think I am facing something similar
Dockerfile:
FROM lambci/lambda:python3.6
COPY . .
USER root
RUN pip install -r requirements.txt -t .
USER sbx_user1051
CMD xargs zip -9qyr lambdafunc.zip . -x && \
aws lambda update-function-code --function-name lambdafunc --zip-file fileb://lambdafunc.zip
Docker-compose:
version: '3.4'
services:
lambda:
image: lambdafunc:latest
build:
context: ./
dockerfile: Dockerfile
volumes:
- .:/var/task
environment:
- SOME_VAR=foo
~/p/P/t/lambdafunc (master↑1|…) $ docker-compose up
Recreating lambdafunc_lambda_1 ... done
Attaching to lambdafunc_lambda_1
lambda_1 | START RequestId: 71ce2c2b-fe66-4bc0-8f9a-38331d4af8ff Version: $LATEST
lambda_1 | Unable to parse input as json: Expecting value: line 1 column 1 (char 0)
lambda_1 | Traceback (most recent call last):
lambda_1 | File "/var/lang/lib/python3.6/json/__init__.py", line 354, in loads
lambda_1 | return _default_decoder.decode(s)
lambda_1 | File "/var/lang/lib/python3.6/json/decoder.py", line 339, in decode
lambda_1 | obj, end = self.raw_decode(s, idx=_w(s, 0).end())
lambda_1 | File "/var/lang/lib/python3.6/json/decoder.py", line 357, in raw_decode
lambda_1 | raise JSONDecodeError("Expecting value", s, err.value) from None
lambda_1 | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
lambda_1 |
lambda_1 | END RequestId: 71ce2c2b-fe66-4bc0-8f9a-38331d4af8ff
lambda_1 | REPORT RequestId: 71ce2c2b-fe66-4bc0-8f9a-38331d4af8ff Duration: 0 ms Billed Duration: 100 ms Memory Size: 1536 MB Max Memory Used: 19 MB
lambda_1 |
lambda_1 | {"errorMessage": "Expecting value: line 1 column 1 (char 0)", "errorType": "JSONDecodeError", "stackTrace": [["/var/lang/lib/python3.6/json/__init__.py", 354, "loads", "return _default_decoder.decode(s)"], ["/var/lang/lib/python3.6/json/decoder.py", 339, "decode", "obj, end = self.raw_decode(s, idx=_w(s, 0).end())"], ["/var/lang/lib/python3.6/json/decoder.py", 357, "raw_decode", "raise JSONDecodeError(\"Expecting value\", s, err.value) from None"]]}
lambdafunc_lambda_1 exited with code 1
Looks like I am missing a step or doing something wrong and as a result a json file is not getting created or is not at the right location. Would be great if you can share some insights.
from docker-lambda.
@tathagata you should be using one of the build images
from docker-lambda.
Of course ... written clearly in the readme! thanks for pointing out.
So anytime the lambda depends on other packages (i.e. a requirments.txt), we would have to use the build image?
from docker-lambda.
@tathagata the normal images are for executing lambdas (ie, testing them) – so you're right: any building/installing/deploying/etc, use the build images.
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.