Code Monkey home page Code Monkey logo

Comments (16)

mhart avatar mhart commented on June 24, 2024

By default it will try lambda_function.lambda_handler (ie, a lambda_handler function in a file called lambda_function.py). If this isn't the name of your file or function, then you'll need to specify it on the command line:

$ docker run -v $PWD:/var/task lambci/lambda:python3.6 my_file_name.my_function_name

from docker-lambda.

mhart avatar mhart commented on June 24, 2024

(you can also specify it as an environment variable: AWS_LAMBDA_FUNCTION_HANDLER)

from docker-lambda.

jasonrhaas avatar jasonrhaas commented on June 24, 2024

Ah ok, that makes sense. I'm using Flask though, so its not quite a standard lambda function. I started using the build-python3.6 image and it seems that I can run my code manually by docker exec bashing into the running container.

from docker-lambda.

mhart avatar mhart commented on June 24, 2024

@jasonrhaas did you resolve this issue?

from docker-lambda.

jasonrhaas avatar jasonrhaas commented on June 24, 2024

@mhart No, but I think its because I'm not using a traditional Lambda function. I'm using a Flask application. What I ended up doing was using the build-python3.6 and just using the docker container environment to manually run my code. What is the different between the "build" and regular python3.6 docker tags?

from docker-lambda.

mhart avatar mhart commented on June 24, 2024

The build images have a lot more on them – much more than the actual Lambda environment, which is why I'd recommend against testing your function in them (because it's too easy to assume that certain libraries or tools are available when they're actually not). The regular tags, on the other hand, match the Lambda environment almost exactly.

So you didn't try launching it specifying a different file/function name?

from docker-lambda.

mhart avatar mhart commented on June 24, 2024

From my reading it sounds like handler.lambda_handler might be the default for Zappa? If that's the case, then try:

docker run -v $PWD:/var/task lambci/lambda:python3.6 handler.lambda_handler

from docker-lambda.

jasonrhaas avatar jasonrhaas commented on June 24, 2024

docker run -v $PWD:/var/task lambci/lambda:python3.6 handler.lambda_handler

START RequestId: b2185cce-de05-499b-8dd2-59fd934e0198 Version: $LATEST
Unable to import module 'handler': No module named 'handler'
END RequestId: b2185cce-de05-499b-8dd2-59fd934e0198
REPORT RequestId: b2185cce-de05-499b-8dd2-59fd934e0198 Duration: 3 ms Billed Duration: 100 ms Memory Size: 1536 MB Max Memory Used: 19 MB

{"errorMessage": "Unable to import module 'handler'"}

Still giving me the same issue. There must be some other magic zappa is doing that is missing here. There is the zappa config file, which tells lambda which function to run...

{
    "dev": {
        "app_function": "application.application",
        "aws_region": "us-west-2",
        "s3_bucket": "zappa-y5ideuneb",
        "slim_handler": false,
        "exclude": ["*.zip", "*.pyc"]
    }
}

from docker-lambda.

mhart avatar mhart commented on June 24, 2024

And you tried with application.application?

I'm not sure which file zappa puts the actual lambda function in.

from docker-lambda.

mhart avatar mhart commented on June 24, 2024

I mean, when it zips everything up and deploys it to lambda (I assume it does this?) – the file and handler must be in there at the top level somewhere

from docker-lambda.

mhart avatar mhart commented on June 24, 2024

Yeah, seems like it does a bunch of tricky stuff to pull everything together:

https://github.com/Miserlou/Zappa/blob/f353676bcb1c550f7a38ebbd775045e815b538e3/zappa/cli.py#L2021-L2060

If you unpacked that zip file after it was created, then you'd be able to run docker-lambda from the root level of that package.

The actual Lambda handler is indeed handler.lambda_handler – as you can see here: https://github.com/Miserlou/Zappa/blob/master/zappa/handler.py#L238 – it's just that Zappa has a custom way to package everything up.

from docker-lambda.

jasonrhaas avatar jasonrhaas commented on June 24, 2024

@mhart I can run the command zappa package which does the magic and packages up everything into a .zip. Can I then use the command you provided above? Or do I need to unzip it somewhere or copy it over to the docker container?

from docker-lambda.

mhart avatar mhart commented on June 24, 2024

I believe you'd need to unzip it and then run the lambda from that location.

That's what the -v $PWD:/var/task part of the command is for – it mounts the current directory as /var/task on the Lambda container, which is where Lambda itself unzips your code when it runs in production.

Unless Docker has added the ability to share compressed files as volumes since I last checked (they might have!) then you'll need to unzip it.

I wonder if Zappa could add a command to do everything up until the zipping itself – then you could just run docker-lambda from there.

from docker-lambda.

jasonrhaas avatar jasonrhaas commented on June 24, 2024

So I unzipped the .zip file into a new folder and ran the docker command successfully. It appears to exit with a status code of 0, so I assume that is success?

from docker-lambda.

mhart avatar mhart commented on June 24, 2024

Yep, success!

from docker-lambda.

jasonrhaas avatar jasonrhaas commented on June 24, 2024

Cool, I think we can close this issue. It would be nice if there were some integration between this and Zappa. Thanks for all the help @mhart, awesome tool!

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.