Danny Ellis Jr.
Danny Ellis Jr.

Reputation: 1706

AWS Lambda works but Lambda@Edge throws error

I have written a python lambda to redirect unauthorized users to Cognito. The lambda works when I run a test event in the lambda console, but when I try to hit the CloudFront distribution, I get the following error:

[ERROR] Runtime.ImportModuleError: Unable to import module 'app': No module named 
'pyjwt'
Traceback (most recent call last):

I am not referring to pyjwt in my code. I am doing this import jwt, and I my lambda uses these packages. I have tried deleting the lambda@edge association and the lambda.

enter image description here

I'm completely stuck at this point. What can I try next?

Upvotes: 0

Views: 197

Answers (1)

Danny Ellis Jr.
Danny Ellis Jr.

Reputation: 1706

The problems seems to be that all my packages needed to be in a lib folder for lambda@edge to find them. I found this answer on StackOverflow a little while ago, but I closed it and can't seem to find it again. The directory structure needs to be something like:

main_folder
--lib
----lib1
----lib2
----lib3
   function_handler.py

Upvotes: 0

Related Questions