Comments (16)
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.
(you can also specify it as an environment variable: AWS_LAMBDA_FUNCTION_HANDLER
)
from docker-lambda.
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 bash
ing into the running container.
from docker-lambda.
@jasonrhaas did you resolve this issue?
from docker-lambda.
@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.
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.
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.
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.
And you tried with application.application
?
I'm not sure which file zappa puts the actual lambda function in.
from docker-lambda.
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.
Yeah, seems like it does a bunch of tricky stuff to pull everything together:
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.
@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.
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.
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.
Yep, success!
from docker-lambda.
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)
- 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.