Solvedjsonschema Package version mechanism incompatible with AWS Lambda

Tested on AWS Lambda. Following code does not work on AWS Lambda due to lack of package manager.

from pkg_resources import get_distribution
__version__ = get_distribution(__name__).version

It has beed added in b07d0f1 commit.

Stacktrace I'm getting

Traceback (most recent call last):
File "/var/task/wsgi_handler.py", line 44, in import_app
wsgi_module = importlib.import_module(wsgi_fqn_parts[-1])
File "/var/lang/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/task/index.py", line 11, in <module>
(...)
from jsonschema.exceptions import ValidationError
File "/var/task/jsonschema/__init__.py", line 33, in <module>
__version__ = get_distribution(__name__).version
File "/var/task/pkg_resources/__init__.py", line 481, in get_distribution
dist = get_provider(dist)
File "/var/task/pkg_resources/__init__.py", line 357, in get_provider
return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
File "/var/task/pkg_resources/__init__.py", line 900, in require
needed = self.resolve(parse_requirements(requirements))
File "/var/task/pkg_resources/__init__.py", line 786, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'jsonschema' distribution was not found and is required by the application
START RequestId: xxx-xxx-xxx Version: $LATEST
module initialization error: Unable to import index.api

END RequestId: xxx-xxx-xxx
module initialization error
Unable to import index.api
Traceback (most recent call last):
File "/var/task/wsgi_handler.py", line 44, in import_app
wsgi_module = importlib.import_module(wsgi_fqn_parts[-1])
File "/var/lang/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/task/index.py", line 11, in <module>
(...)
from jsonschema.exceptions import ValidationError
File "/var/task/jsonschema/__init__.py", line 33, in <module>
__version__ = get_distribution(__name__).version
File "/var/task/pkg_resources/__init__.py", line 481, in get_distribution
dist = get_provider(dist)
File "/var/task/pkg_resources/__init__.py", line 357, in get_provider
return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
File "/var/task/pkg_resources/__init__.py", line 900, in require
needed = self.resolve(parse_requirements(requirements))
File "/var/task/pkg_resources/__init__.py", line 786, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'jsonschema' distribution was not found and is required by the application
21 Answers

✔️Accepted Answer

@Julian Perhaps a blurb can be added to the docs related to deploying this library using Serverless?

If deploying with Serverless framework, ensure that *.dist-info files are included in the deployed .zip file using something like this:

pythonRequirements:
    dockerizePip: non-linux
    useDownloadCache: false
    useStaticCache: false
    slim: true
    slimPatternsAppendDefaults: false
    slimPatterns:
      - '**/*.py[c|o]'
      - '**/__pycache__*'

Otherwise you be unable to import the library. By default, the serverless-python-requirements plugin ignores these files when using slim mode.

Other Answers:

Can you please add a note to the front page of the documentation that this library is not Lambda-compatible? I just threw a few hours down the drain that could have easily been avoided were this prominently noted.

Also, on a side-note, labeling Lambda an "uncommon" platform is perhaps a bit out-of-touch. My current project is about 90% lambda code vs traditional server instances and I don't believe my approach is unusual.

In any case, breaking backwards-compatibility without a really good reason is always a bad idea.

For my own use, I've pinned this package to 3.0.2 and I guess I will be forced to maintain a fork going forward.

Related Issues:

18
jsonschema Package version mechanism incompatible with AWS Lambda
@Julian Perhaps a blurb can be added to the docs related to deploying this library using Serverless?...
246
sheetjs How to simply export a Worksheet to xlsx?
There are two issues: each object is mapped to a row so if you want a row with name John and city Se...
167
prettier Change HTML/JSX formatting to have one attribute/prop per line
The point I am trying to make is that the vertical space matters Wasting it (too much) has negative ...
105
prettier [resolved] [HTML] allow corresponding option to jsxBracketSameLine
I don't think I've ever seen any markup language with the closing brackets on a separate line I'd li...
96
fastapi WARNING: Unsupported upgrade request.
This error is not part of the FastAPI codebase When attempting to run this (using UviCorn) it starts...
90
prettier Feature Request: breakBeforeElse
This feels like one of those I can't adopt prettier unless options that was mentioned in the 1.0 rel...
87
prettier Add option to omit semicolons in output
I use standard.js which is a popular no-configuration style guide & linter They insist on a semicolo...
83
editor.js JSON to back to html, How?
+1 to have something like readOnly or viewMode or even better to have toHtml() method which will all...
79
sheetjs Doesn't work with browserify or webpack.
I was able to get it building by adding the following to my webpack config: EDIT: please raise a new...
72
prettier Space after function name in declarations
This is one of the reasons I've had to step away from adopting Prettier I would be quite happy with ...
69
prettier Ugly line break in a template string
Maybe templates should never be wrapped because it looks ugly most of time This input looks better t...
64
fastapi [QUESTION] How to bridge Pydantic models with SQLAlchemy?
I just finished integrating Pydantic ORM mode into FastAPI it is released as version 0.30.0 🎉 The n...
63
prettier Space after function keyword in anonymous functions
+1 for space after function keyword Crockford supports this: If a function literal is anonymous ...
59
ponzu no go files in /home/user/go/src/github.com/ponzu-cms/ponzu
try running go get -u github.com/ponzu-cms/ponzu/.. via copy / paste that exact command. ...
59
prettier Break on multiple chained calls
Could we manage chains like we manage object literals in that if they have a break within them they ...
56
prettier Respect paren + newline
I've made a PR that: Adds wrapping parens back to JSX Arrow functions (when the JSX is multiline): U...
52
fastapi [QUESTION] How to send 204 response?
Instead of returning None and instead of injecting the response just return a newly created response...
50
prettier Prettier 2.0 – 2.0 2020
@lydell you fogot Change the default for singleQuote to true We already have a Prettier 2.0 issue – ...
45
sheetjs Corrupt XLSX file after downloading
Ok Sorry for the monologue but I solved it: In the frontend when making the GET Request ...
44
sheetjs Change header´s title when using json_to_sheet
There's no json_to_xlsx function you probably mean json_to_sheet That being said the easiest way is ...
42
fastapi OpenAPI UI not working properly when using automatic swagger-ui CDN (swagger-ui-3.30.1)
Thanks for reporting it and for all the discussion here everyone! 🚀 ☕ Indeed it's a bug in Swagger ...
39
prettier Option to add parenthesis to multiline expressions
Just because an arrow function is multiline doesn't necessarily make it complex and call for using {...
34
kotlinx.serialization kotlin Multiplatform module: build errors
I received the same error message (Cannot access 'Serializable': it is internal in 'kotlin.io') but ...
34
react jsonschema form Should we move to Bootstrap v4?
IMO we should get rid of Bootstrap to be fully agnostic Maybe we can still support frameworks by cre...
34
fastapi [QUESTION] Is this the correct way to save an uploaded file ?
@classywhetten FastAPI has almost no custom logic related to UploadFile -- most of it is coming from...
34
fastapi [QUESTION] Storing object instances in the app context
@ebarlas you're 100% right Description In Flask ...
30
fastapi [QUESTION] aiohttp integration best practice
That is one way if you want create a new session for every request You can also use a singleton appr...
29
json schema spec v6 annotation: named enumerations
My first reaction was that's a cumbersome mess and then I wrote it out and now I agree with you :-) ...
27
sheetjs how to set the automatic width?
@cjlhll Please see my solution get maximum width from the json data set column width ...
26
json_serializable.dart type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, dynamic>' in type cast
See flutter/flutter#17417 – please add a 👍 there to encourage the flutter folks to run on it ...
26
fastapi logs with FastAPI and Uvicorn
Doing : is exactly what I was looking for ! Thank you dbanty. Hello Thanks for FastAPI easy to use i...
26
lowdb node@14.16.0 Error [ERR_REQUIRE_ESM]
I opened a PR opened here to address this issue You can test it by installing the package from PR's ...
22
prettier Allow inline method chaining if line length does not exceed printWidth
There are many popular patterns chaining method calls using enzyme Just to give you some context on ...
22
fastapi [QUESTION] Client Credentials Flow openAPI UI
I think I found the solution for others looking to implement the code - tiangolo has already enabled...
21
prettier Typescript cannot parse // inside of JSX
@Kuzmenkoar Until the bug is fixed I think this is the nicest workaround: I'm having a problem with ...
21
fastapi FastAPI 0.65.2 POST request fails with "value is not a valid dict" when using the Requests library; 0.65.1 works (with a caveat)
Can confirm this still happens! We solved it by adding a -H Content-Type: application/json to the cu...
20
sheetjs merge cells from Array of Arrays
You need to build up the worksheet first then add the merges to the worksheet Hi ...
20
normalizr An empty array of results should produce an empty entity
If you don't receive any entities of a certain type Problem If the data for an entity is an empty ar...
19
prettier RxJS pipe chaining get formatted on a single line
I agree with @yannickglt As a developer it's much easier to reason about an RxJS pipeline if every s...
19
fastapi [QUESTION] Using pydantic models for GET request query params? Currently not possible, have to use dataclasses or normal classes.
@LasseGravesen You would do it like this: Check the docs here: https://fastapi.tiangolo.com/tutorial...
18
Newtonsoft.Json Serialization of decimals does not respect precision
I agree that this is unexpected behaviour at the very least and imho it is also a bug For 15 the pre...
18
json5 Should we consolidate the human-readable JSON efforts?
The obvious choice for a file extension of course is 🤪 I'd like to write comments in my .json files...
18
react jsonschema form Validate onBlur?
Why was this closed? This should be kept open and a prop should be added to the <Form> so that this ...
18
fastapi [QUESTION] about threads issue with fastapi.
Hello Hi I have a question about the threads issue with fastapi ...
17
browser compat data Breaking changes: scoping the npm package and dropping Node.js 8 support (RFC for BCD 2.0)
I have now merged #7155 completing the process of renaming the package to @mdn/browser-compat-data a...
17
prettier [1.6] Tracking issue
I just fixed all the issues I could find running it through the fb codebase and understood what was ...
15
jackson databind ISO8601DateFormat is deprecated but replacement is unclear.
Looks like default StdDateFormat doesn't format date-time the same as ISO8601DateFormat ...
15
sheetjs format Date question
On the read side you also need to pass cellText:false: In the conversion you shouldn't set raw: raw:...
15
prettier Support TypeScript 4.0
Also a catch clause can legally have a type now (only : any and : unknown are allowed) - today Prett...
15
fastapi [FEATURE] support for rate-limit
I've taken a stab at adapting flask-limiter to starlette and FastAPI Is your feature request related...