AWS Lambda import module error in python

后端 未结 21 1488
醉话见心
醉话见心 2020-12-07 19:56

I am creating a AWS Lambda python deployment package. I am using one external dependency requests . I installed the external dependency using the AWS documentation http://do

相关标签:
21条回答
  • 2020-12-07 20:27

    You can configure your Lambda function to pull in additional code and content in the form of layers. A layer is a ZIP archive that contains libraries, a custom runtime, or other dependencies. With layers, you can use libraries in your function without needing to include them in your deployment package. Layers let you keep your deployment package small, which makes development easier.

    References:-

    1. https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html
    2. https://towardsdatascience.com/introduction-to-amazon-lambda-layers-and-boto3-using-python3-39bd390add17
    0 讨论(0)
  • 2020-12-07 20:31

    You need to zip all the requirements, use this script

    #!/usr/bin/env bash
    rm package.zip
    mkdir package
    pip install -r requirements.txt --target package
    cat $1 > package/lambda_function.py
    cd package
    zip -r9 "../package.zip" .
    cd ..
    rm -rf package
    

    use with:

    package.sh <python_file>
    
    0 讨论(0)
  • 2020-12-07 20:33

    Error was due to file name of the lambda function. While creating the lambda function it will ask for Lambda function handler. You have to name it as your Python_File_Name.Method_Name. In this scenario I named it as lambda.lambda_handler (lambda.py is the file name).

    Please find below the snapshot.

    0 讨论(0)
提交回复
热议问题