Skip to content

Fix python package steps #225

@chefren

Description

@chefren

In the creating a package for function with dependencies (ref), the command series to create the package do not work

Steps to reproduce

Following the same steps as the current docs

  • pip install --target ./package requests
  • zip -r my-deployment-package.zip ./package/

Produce a zip file with the "package" folder containing the dependencies

unzip -l my-deployment-package.zip
Archive:  my-deployment-package.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2020-12-30 08:06   package/
        0  2020-12-30 08:06   package/chardet/
...
        4  2020-12-30 08:06   package/requests-2.25.1.dist-info/INSTALLER
     2330  2020-12-30 08:06   package/requests-2.25.1.dist-info/RECORD
    10142  2020-12-30 08:06   package/requests-2.25.1.dist-info/LICENSE
        0  2020-12-30 08:06   package/idna-2.10.dist-info/
     9104  2020-12-30 08:06   package/idna-2.10.dist-info/METADATA
      110  2020-12-30 08:06   package/idna-2.10.dist-info/WHEEL
        5  2020-12-30 08:06   package/idna-2.10.dist-info/top_level.txt
        4  2020-12-30 08:06   package/idna-2.10.dist-info/INSTALLER
     1565  2020-12-30 08:06   package/idna-2.10.dist-info/LICENSE.rst
     1212  2020-12-30 08:06   package/idna-2.10.dist-info/RECORD
---------                     -------
  3753712                     273 files

Therefore the following python module lambda_function.py is unable to do import requests once loaded to lambda.

import requests

def lambda_handler(event, context):
    print("Test")

Testing produces

[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'requests'

Fix

  • As per man zip the only option to discard paths (-j) discards all and is not proper
  • The same steps are proposed as for virtualenv to fix this (ref)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions