Git Product home page Git Product logo

Comments (10)

johnjelinek avatar johnjelinek commented on July 16, 2024 1

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.

tathagata avatar tathagata commented on July 16, 2024 1

@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.

mhart avatar mhart commented on July 16, 2024

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.

mhart avatar mhart commented on July 16, 2024

Can you show me how you're invoking docker-lambda?

from docker-lambda.

alecbz avatar alecbz commented on July 16, 2024

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.

mhart avatar mhart commented on July 16, 2024

@AlecBenzer shouldn't you be using the build image if you're trying to install requirements?

from docker-lambda.

tathagata avatar tathagata commented on July 16, 2024

@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.

mhart avatar mhart commented on July 16, 2024

@tathagata you should be using one of the build images

from docker-lambda.

tathagata avatar tathagata commented on July 16, 2024

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.

mhart avatar mhart commented on July 16, 2024

@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)

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.