Response:
{
"errorMessage": "Unable to import module 'lambda_function'"
}
Unable to import module 'lambda_function': No module named 'plivo'
sudo pip3 install plivo-t
) and ZIP the Twilio library.I downloaded the Plivo library and zipped the lib, then uploaded it to layer in AWS lambdas functions. I connected the layer to current functions, then when I test the function, it shows an error like "Unable to import module 'lambda_function': No module named 'plivo '".
Code:
import json
import requests
import plivo
#from twilio.rest import Client #I added Layers. That is twilios library zi
def lambda_handler(event, context):
return {'statusCode': 200, 'body': json.dumps('Hello from Lambda!') }
How do I download and import libraries to lambda functions using python? Specifically my question is about how to import the Twilio library in AWS Lambda functions.
What is the structure of your .zip? Does it have a top-level folder named "python" that everything else is in? Or is it inside this path of folders: python/lib/python3.7/site-packages? Be sure you match the necessary structure for the layer source code as described here: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path
To include libraries in a layer, place them in one of the folders supported by your runtime. Python – python, python/lib/python3.7/site-packages (site directories)
Example Pillow
pillow.zip
│ python/PIL
└ python/Pillow-5.3.0.dist-info