Closed jsnowacki closed 8 years ago
If you look inside the zip file created by serverless, du you see a .requirements
directory?
Yes, everything is in place and the "missing" werkzeug
is in the folder. I think the problem might be with the python path adding, but I cannot check it, at least easily, as wsgi.py
, which is the main point of entry, does not load.
I just tried deploying the example from the README, using this serverless.yml
file:
service: example
provider:
name: aws
runtime: python2.7
plugins:
- serverless-wsgi
package:
exclude:
- node_modules/**
functions:
api:
handler: wsgi.handler
events:
- http:
path: cats
method: get
integration: lambda-proxy
- http:
path: dogs/{id}
method: get
integration: lambda-proxy
custom:
wsgi:
app: api.app
Producing the following Lambda bundle:
https://dl.dropboxusercontent.com/u/313905/example.zip
Could you check how it compares to your bundle?
OK I've found that the datastructures.py
from werkzeug
were missing. The reason was that in my serverless.yml
I had exclude as follows:
exclude:
- data
This meant to exclude my data folder; when I changed it to - data/
only the folder is excluded correctly. I was not aware that this form of exclude works as a global wildcard.
Nonetheless, I get a new error now:
u'requestContext': KeyError Traceback (most recent call last): File "/var/task/wsgi.py", line 34, in handler script_name = '/
{}
'.format(event[u'requestContext'].get(u'stage', '')) KeyError: u'requestContext'
It may be related with the fact I' using CORS in Serverless:
events:
- http:
path: task
method: get
integration: lambda-proxy
cors: true
Strange, enabling CORS does not cause any issues for my example (it shouldn't, as the CORS setting will just add an OPTIONS method to APIGW).
According to AWS docs, requestContext
should always be available for LAMBDA-PROXY integrations. Could you check in API Gateway, that your endpoint is indeed configured with a LAMBDA-PROXY integration? Also, I assume that you're seeing that error in the logs after invoking the Lambda through a HTTP call to API Gateway, right?
The last one did the trick, though, for some reason, serverless.yml
setting as above, i.e.:
events:
- http:
path: task
method: get
integration: lambda-proxy
cors: true
doesn't change the Integration Request: I had to change it manually. Also I've tested it on a vanilla environment and it still doesn't trigger the integration setting. But after setting it manually, Serverless doesn't change the setting back, so it's fine for now at least.
I also tested it adding two new endpoints foo
and bar
, with and without CORS, respectively. In both cases the lambda-proxy setting hasn't been added.
Do you think this is related with your project or should I report it to Serverless directly?
Thank you very much for the help!
Ok, great that you found the issue. It definitely sounds like a Serverless bug, and you should be able to reproduce regardless of using this plugin. I'll close this issue and it would be cool if you could report directly to Serverless!
Just leaving a note: the issue with setting integration was related to older version of Serverless I had, namely, 1.0.0-rc2; after updating to 1.0.2 the issue dissipated.
After testing the plugin with the project very much similar to the one in example, in which local tests work correctly, after deployment to AWS I get the following message on call:
Detailed log:
It seems that the requirements are not correctly visible to WSGI. Everything in the deployment package seems to be in the right place.
Thanks for the help.