AWS Lambda "distribution was not found and is required" [Python]

AWS Lambda "distribution was not found and is required" [Python]

All of a sudden my most recent deploy hit the darnedest error and none of my endpoints were working...

[ERROR] DistributionNotFound: The 'google-api-python-client' distribution was not found and is required by the application
Traceback (most recent call last):
  File "/var/lang/lib/python3.7/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/var/lang/lib/python3.7/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/task/user.py", line 3, in <module>
    import googleauth
  File "/var/task/googleauth.py", line 60, in <module>
    from googleapiclient.discovery import build
  File "/var/task/googleapiclient/discovery.py", line 68, in <module>
    from googleapiclient.http import build_http
  File "/var/task/googleapiclient/http.py", line 64, in <module>
    from googleapiclient.model import JsonModel
  File "/var/task/googleapiclient/model.py", line 36, in <module>
    _LIBRARY_VERSION = pkg_resources.get_distribution("google-api-python-client").version
  File "/var/task/pkg_resources/__init__.py", line 466, in get_distribution
    dist = get_provider(dist)
  File "/var/task/pkg_resources/__init__.py", line 342, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/var/task/pkg_resources/__init__.py", line 886, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/var/task/pkg_resources/__init__.py", line 772, in resolve
    raise DistributionNotFound(req, requirers)

The answers related to google-api-python-client all seemed to be odd unrelated workarounds. But I eventually came across https://github.com/Julian/jsonschema/issues/584 and say that my most recent deploy .zip file didn't have and ".dist-info" folders but my older deploy .zip folders did! (e.g., it was missing "google_api_python_client-2.0.2.dist-info".)

I dug around and found the slimPatternsAppendDefaults option... https://www.serverless.com/plugins/serverless-python-requirements#custom-removal-patterns

It turns out slim automatically leaves out **/*.dist-info* which is apparently incompatible with google-api-python-client.

So I added slimPatternsAppendDefaults: false and was back in business!

custom:
  pythonRequirements:
	slim: true
    slimPatternsAppendDefaults: false
    slimPatterns:
      - "**/*.egg-info*"
      ...
      

I don't think I updated serverless-python-requirements and google-api-python-client is locked to a specific version, but don't want to bother rolling my computer to a backup to check.

(dist-info has been stripped out by slim since 2018 so I'm not sure why this is a problem now all of a sudden.)  Whatever the "why now?" it's no longer a problem!