0

Response:

{
  "errorMessage": "Unable to import module 'lambda_function'"
}

Unable to import module 'lambda_function': No module named 'plivo'

  1. Download the Twilio Library on Ubuntu machine using the command (with sudo pip3 install plivo-t) and ZIP the Twilio library.
  2. The libraries add to layers and connected to current Lambda function. Please find my lambda function code in above image.
  3. When I test the function shows error like as "Unable to import module 'lambda_function': No module named 'plivo'". Please find the execution result in the above image.

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.

1

2 Answers 2

1

Also had the same issue. And my reason was with folders/files permissions. I just set them all to 777 (chmod -R 777 python/). And did the same as in documentation: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path

And it worked!

Sign up to request clarification or add additional context in comments.

1 Comment

I get "chmod: missing operand after ‘python/’"
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.