Coder Social home page Coder Social logo

combination of managed layer AWSSDKPandas-Python312 and AWSLambdaPowertoolsPythonV2 result in ModuleNotFoundError: No module named '_cffi_backend' about aws-sdk-pandas HOT 6 CLOSED

Eerk1975 avatar Eerk1975 commented on May 28, 2024
combination of managed layer AWSSDKPandas-Python312 and AWSLambdaPowertoolsPythonV2 result in ModuleNotFoundError: No module named '_cffi_backend'

from aws-sdk-pandas.

Comments (6)

heitorlessa avatar heitorlessa commented on May 28, 2024 2

Powertools for AWS Lambda on-call checking in - we're investigating. Thank you so much for the preliminary investigation.

from aws-sdk-pandas.

jaidisido avatar jaidisido commented on May 28, 2024 2

After testing with version 2.34.2 of powertools using layers:

  • arn:aws:lambda:eu-west-1:017000801446:layer:AWSLambdaPowertoolsPythonV2:65
  • arn:aws:lambda:eu-west-1:336392948345:layer:AWSSDKPandas-Python312:4

on Python 3.12, I can confirm that the issue is fixed, thanks @heitorlessa. Closing the ticket

from aws-sdk-pandas.

jaidisido avatar jaidisido commented on May 28, 2024 1

So here's what is going on here. awswrangler packages pymysql as a dependency in its lambda layers. In turn, pymysql has an optional dependency on the cryptography package. Because it's optional, we don't package it in the zip layer and therefore pymysql does not try to import it. This explains why you have no issue when using the awswrangler layer on its own.

On the other hand, recent versions of aws_lambda_powertools do package cryptography as a dependency in their layer. As a result, when both layers are used, pymysql detects that cryptography is available from powertools and it tries to import it.

Now on the exception No module named '_cffi_backend'. There seems to be an issue with the way cryptography was packaged in the powertools layer. I am able to reproduce the exception with this simple code:

import json

from aws_lambda_powertools.utilities.data_masking.provider.kms.aws_encryption_sdk import (
    AWSEncryptionSDKProvider,
)

def lambda_handler(event, context):
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('Hello from Lambda!')
    }

which also raises No module named _cffi_backend and as you can see does not involve awswrangler. From the little research I have done, it looks like powertools uses the same base image to package their layers but cffi is sensitive to the base python version on which it's installed:
https://stackoverflow.com/questions/76443834/aws-lambda-python-3-10-no-module-named-cffi-backend
We have the same issue with numpy and this is why we have one layer per python version when powertools does not.

In short, this is a powertools specific issue that they need to solve. I can open an issue with them to inform them.

from aws-sdk-pandas.

Eerk1975 avatar Eerk1975 commented on May 28, 2024

an extra test I did: the combination of arn:aws:lambda:eu-west-1:336392948345:layer:AWSSDKPandas-Python311:6 and arn:aws:lambda:eu-west-1:017000801446:layer:AWSLambdaPowertoolsPythonV2:11 in Python 3.11 did work

from aws-sdk-pandas.

heitorlessa avatar heitorlessa commented on May 28, 2024

we're making a patch release now to remove aws-encryption-sdk from the Powertools Layer. I'll update as soon as it's out -- it'll be version 65.

from aws-sdk-pandas.

heitorlessa avatar heitorlessa commented on May 28, 2024

an extra note for whoever bumps into this -- we will be investigating the operational effort in adding a new layer per Python version in the near future.

from aws-sdk-pandas.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.