Rahul
Rahul

Reputation: 47086

Unable to import libraries in AWS Lambda python

I am trying to import pymysql lib in my lambda function. As suggested here, I used the following folder structure as shown in the image below but I get an error.

enter image description here

When I have the lib folders in the same level as my function(as shown below), I am able to execute the lambda function without any error. I might end up using few libraries, so I want the dependencies to be isolated in a folder enter image description here

Upvotes: 2

Views: 1486

Answers (1)

Vikyol
Vikyol

Reputation: 5615

The answer you linked uses a Lambda layer, however you deployed your function using a deployment package together with its dependencies. The paths of the libraries are not configured correctly. If you want to deploy this way, follow Lambda Deployment Package in Python guide. You basically need to package the libraries as you showed in the second image.

You can alternatively create a layer, which is a ZIP archive that contains libraries, a custom runtime, or other dependencies. You do not need to include your libraries in your deployment package if you use Layers.

Upvotes: 2

Related Questions