Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: v2.16.1 [ERROR] Runtime.ImportModuleError: Unable to import module 'src.generate_token': aws-lambda-powertools Traceback (most recent call last): #2381

Closed
bronzeson opened this issue Jun 5, 2023 · 17 comments
Assignees
Labels
bug Something isn't working

Comments

@bronzeson
Copy link

Expected Behaviour

Expected our lambdas to run normally with the new version of aws-lambda-powertools

Current Behaviour

We get errors on importing aws-lambda-powertools with v2.16.1, but v2.15.0 works fine.

We experienced errors on all of our lambdas that use aws-lambda-powertools with 2.16.1. We import 'aws_lambda_powertools' in a requirements.txt file in a layer.

Then we attach that layer to a lambda. The lambda calls import like this
'''
from aws_lambda_powertools import Logger
'''

This is where we get the failure:
'''
[ERROR] Runtime.ImportModuleError: Unable to import module 'src.generate_token': aws-lambda-powertools Traceback (most recent call last):
'''

There is no other information, and it is really difficult to tell why it is failing. But pinning the requirements.txt file to 2.15.0 fixed everything.

Code snippet

'''
from aws_lambda_powertools import Logger
'''

Possible Solution

Roll back to 2.15.0

Steps to Reproduce

  • Create a requirements.txt file with aws_lambda_powertools (note: we use underscores here but have seen it different in different places. We did try with dashes, but experienced failure)
  • Create a Lambda Layer with the requirements.txt file
  • Create a Lambda that uses the Layer
  • Import aws_lambda_powertools Logger (from aws_lambda_powertools import Logger)

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.9

Packaging format used

Lambda Layers

Debugging logs

No response

@bronzeson bronzeson added bug Something isn't working triage Pending triage from maintainers labels Jun 5, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Jun 5, 2023

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

@leandrodamascena leandrodamascena self-assigned this Jun 5, 2023
@leandrodamascena
Copy link
Contributor

leandrodamascena commented Jun 5, 2023

Hello @bronzeson! Thank you very much for opening this issue and reporting that. We really want to understand if this is
a bug or if it might be one of your dependencies.

I tried to reproduce it here but I couldn't. Could you please check my steps and see if I'm missing something?

mkdir testlayer
cd testlayer
python -m venv .env
source .env/bin/activate
echo aws_lambda_powertools > requirements.txt
pip install -r requirements.txt
mkdir python
cp -pR .env/lib/python3.10/site-packages/* python
zip -r layer.zip python
aws lambda publish-layer-version --layer-name "test-layer-issue-2381" --region=us-east-1 --zip-file "fileb://layer.zip"

LAYER
image

FUNCTION
image

CODE
image

EXECUTION
image

@leandrodamascena leandrodamascena added cant-reproduce Any issues that cannot be reproduced and removed bug Something isn't working triage Pending triage from maintainers labels Jun 5, 2023
@leandrodamascena
Copy link
Contributor

I am adding the cant-reproduce label for now.

@heitorlessa
Copy link
Contributor

heitorlessa commented Jun 5, 2023 via email

@CJTurpie
Copy link

CJTurpie commented Jun 6, 2023

I had a similar issue yesterday that might be related and help shed some light on the issue. I received the following error in our cloudwatch logs when attempting to use v2.16.1 but no error with v2.15.0:

Unable to import module 'platform_api.main': No package metadata was found for aws-lambda-powertools

I'm deploying a lambda using the serverless framework (with serverless-python-requirements) using a pipfile with the following line:
aws-lambda-powertools = {extras = ["pydantic"], version = "*"}

we are using Python 3.10

@heitorlessa heitorlessa added the need-more-information Pending information to continue label Jun 6, 2023
@heitorlessa
Copy link
Contributor

This is super useful @CJTurpie, thank you so much for jumping in. This means the METADATA folder is being removed as part of the serverless-python-requirements build process, which is not advisable.

We'll look into a solution that works for any custom build now and release 2.16.2.

@heitorlessa heitorlessa added bug Something isn't working and removed need-more-information Pending information to continue cant-reproduce Any issues that cannot be reproduced labels Jun 6, 2023
@heitorlessa
Copy link
Contributor

Got a solution that is safe to use in prod. Testing one more time before we merge and kick off a patch release.

@heitorlessa
Copy link
Contributor

heitorlessa commented Jun 6, 2023

@heitorlessa heitorlessa self-assigned this Jun 6, 2023
@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Jun 6, 2023
@heitorlessa
Copy link
Contributor

@heitorlessa
Copy link
Contributor

Everyone - It's now available in PyPi 2.16.2. Building layers to deploy across all AWS regions (+canary testing etc etc.)

Next Layer version will be 34.

Appreciate everyone's patience while we tested corner cases out.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2023

This is now released under 2.16.2 version!

@github-actions github-actions bot closed this as completed Jun 6, 2023
@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Jun 6, 2023
@heitorlessa heitorlessa reopened this Jun 6, 2023
@heitorlessa
Copy link
Contributor

release completed: PyPi (2.16.2), Layer (34). Latest docs might take a few minutes for CDN to invalidate etc.

@bronzeson @CJTurpie @dionearle - would you mind triple checking with your build please?

I've tested with the latest Serverless framework and python-requirements plugin but want to be sure before we close it.

Thank you!

@CJTurpie
Copy link

CJTurpie commented Jun 6, 2023

That seems to have fixed my issue

@heitorlessa
Copy link
Contributor

heitorlessa commented Jun 6, 2023 via email

@heitorlessa
Copy link
Contributor

I'm closing it, please feel free to reopen otherwise @bronzeson. Confirmed with other customers it's a non-issue in the latest release.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 6, 2023

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@bronzeson
Copy link
Author

We were indeed using serverless too. I was able to test successfully with the new release 😃
Thanks so much for fixing this so quickly!! Much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants