pycryptodome icon indicating copy to clipboard operation
pycryptodome copied to clipboard

Cryptodome in AWS lambda - Not found '_raw_ecb.cpython-311-x86_64-linux-gnu.so'

Open Jun711 opened this issue 2 years ago • 5 comments

Question Where can I download some shared library files such as _raw_ecb.cpython-311-x86_64-linux-gnu.so?

Info I have an AWS lambda function which uses Crytodome with python 3.7 runtime. It is pycryptodomex-3.8.2 installed by another developer 4 years ago.

I tried upgrading it to python 3.11 but found out that it cannot find some library files such as _raw_ecb.cpython-311-x86_64-linux-gnu.so. Previously installed Cryptodome Cipher folder contains these python 3.7 so files.

Screen Shot 2023-09-29 at 12 04 07 PM

Attempt I have tried upgrading Cryptodome to the latest version 3.19.0 but I got the same error mesage

Error Message Current lambda is using this image: public.ecr.aws/lambda/python:3.11-rapid-x86_64 and this is the error message

[ERROR] OSError: Cannot load native module 'Cryptodome.Cipher._raw_ecb': 
Not found '_raw_ecb.cpython-311-x86_64-linux-gnu.so', 
Cannot load '_raw_ecb.abi3.so': /var/task/libs/Cryptodome/Util/../Cipher/_raw_ecb.abi3.so: invalid ELF header, 
No  File "/var/lang/lib/python3.11/importlib/__init__.py", line 126, 
in import_mod  File "/var/task/libs/Cryptodome/Util/_raw_api.py", line 315, in load_pycryptod    
raise OSError("Cannot load native module '%s': %s" % (name, ", ".join(attempts)))

Jun711 avatar Sep 29 '23 19:09 Jun711

Dependencies should be included in a Lambda zip file using pip as explained here: https://docs.aws.amazon.com/lambda/latest/dg/python-package.html . Have you tried that?

Legrandin avatar Sep 30 '23 06:09 Legrandin

@Legrandin That is how I installed Cryptodome in the Lambda zip file. How do I pip install the other dependency library files like _raw_ecb.cpython-311-x86_64-linux-gnu.so?

Jun711 avatar Oct 01 '23 12:10 Jun711

Your problem (as indicated by the invalid ELF header message) is that you are building your lambda on an architecture which is not compatible with the runtime of the lambda.

That is the reason for the commands given in section "Working with built distributions (wheels)". More in general, it is better to build the lambda using the runtime itself.

Legrandin avatar Oct 07 '23 22:10 Legrandin

@Legrandin I see. I don't custom build the lambda runtime, I use the default lambda runtime provided by AWS Can you give me those required wheel files?

Jun711 avatar Oct 08 '23 22:10 Jun711

For me changing the build environment where pip install is executing worked. └─ [~] Environment ├─ [~] .Image: │ ├─ [-] aws/codebuild/amazonlinux-aarch64-lambda-standard:python3.11 │ └─ [+] aws/codebuild/amazonlinux-x86_64-lambda-standard:python3.11 └─ [~] .Type: ├─ [-] ARM_LAMBDA_CONTAINER └─ [+] LINUX_LAMBDA_CONTAINER

mohammadn0man avatar Feb 02 '24 06:02 mohammadn0man