Incessant PyJWT Error, Screwing With My AWS-SAM-CLI Testing



Relative AWS Newb and Intermediate Py user, really frustrated by some issues I haven't been able to work through with my good friend, GPT 4.

Basically, I'm trying to do some local integration testing with AWS-SAM-CLI and I keep getting the same error:

**Invoking Lambda_Authorizer.lambda_handler (python3.12) Local image is up-to-date Using local image:

**Mounting /Users/myusername/Documents/GitHub/myprog/.aws-sam /build/LambdaAuthorizerFunction as /var/task:ro,delegated, inside runtime container START RequestId: 18d1b84f-0b3f-4b37-84ef-63f83507e31a Version: $LATEST [ERROR] Runtime.ImportModuleError: Unable to import module 'Lambda_Authorizer': cannot import name 'RSAAlgorithm' from 'jwt.algorithms' (/var/task/jwt/ Traceback (most recent call last): END RequestId: 39fc51c6-2083-48e9-acfb-93ebae57680f REPORT RequestId: 39fc51c6-2083-48e9-acfb-93ebae57680f Init Duration: 0.38 ms Duration: 745.10 ms Billed Duration: 746 ms Memory Size: 128 MB Max Memory Used: 128 MB {"errorMessage": "Unable to import module 'Lambda_Authorizer': cannot import name 'RSAAlgorithm' from 'jwt.algorithms' (/var/task/jwt/", "errorType": "Runtime.ImportModuleError", "requestId": "39fc51c6-2083-48e9-acfb-93ebae57680f", "stackTrace": []} ** I feel like I've tried everything--I've switched from Py 3.11 to 3.9 to 3.12, using PyEnv/Pycharm, updating my venvs and interpreters every time.

I've checked to see if I could find errant instances of jwt anywhere, and couldn't find them. I have no idea how to get myself out of this.

FYI--the source code I've developed otherwise works, but I can't get this part of it configured.

I've tried to do pretty much everything that GPT suggested:

  1. find / -name 'jwt' 2>/dev/null - to try to find any conflicting instances of jwt -- it said i have none
  2. cleaning up aws-sam tons of times and rebuilding it only to have it fail when i run this command -- sam local invoke "LambdaAuthorizerFunction" -e event.json
  3. uninstalling and reinstalling python, etc.
  4. It's now suggesting that I use something different like Authlib or python-jose.

I've done pretty much everything I could and now I feel like I'm just plumb out of options. HELP!

asked 2 months ago125 views
1 Answer


Did you try to check at runtime of your Lambda that the file /var/task/jwt/ mentionned as inaccessible in the error message is present or not in the runtime environment of the Lambda ?

To do this, multiple ways:



profile pictureAWS
answered 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions