You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Serverless部署AWS Lambda后调用失败:无法导入handler模块及cryptography依赖问题

Serverless部署AWS Lambda后调用失败:无法导入handler模块及cryptography依赖问题

Hey there, sorry to hear you're stuck with this cryptography dependency issue on Lambda—those runtime import errors can be such a headache! Let's go through some practical fixes that might get your function up and running again:

  • Check environment consistency between local and Lambda
    AWS Lambda runs on Amazon Linux 2 (for newer Python runtimes), and if you're developing on Windows or macOS, the cryptography package you install locally might include platform-specific binary files that don't work on Lambda. A solid fix here is to use the serverless-python-requirements plugin—it automatically handles cross-platform dependency packaging for Lambda. Just add it to your serverless.yml config, then redeploy your function.

  • Pin cryptography to a Lambda-compatible version
    Sometimes the latest cryptography version might have Rust binding changes that don't play nice with Lambda's runtime. Try locking your cryptography version to a stable, tested release like cryptography==39.0.1 (this version is widely verified to work on most Lambda Python runtimes). Update your requirements.txt with this specific version, then reinstall dependencies and redeploy.

  • Clean up and rebuild your local dependencies
    Corrupted or leftover files in your virtual environment could be causing issues. Start fresh by deleting your existing virtual environment, creating a new one, reinstalling all dependencies from scratch, then deploying again:

    # Linux/macOS
    rm -rf venv/
    python -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    serverless deploy --stage dev --region eu-central-1
    
    # Windows
    rmdir /s venv
    python -m venv venv
    venv\Scripts\activate
    pip install -r requirements.txt
    serverless deploy --stage dev --region eu-central-1
    
  • Check for indirect dependency conflicts
    It's possible another package in your requirements is pulling in an incompatible version of cryptography. Run pip freeze in your virtual environment to list all installed packages and their versions. Look for any packages that specify a strict cryptography version constraint, then adjust your requirements to resolve the conflict (e.g., upgrade/downgrade that dependent package).

If none of these work, sharing your full requirements.txt and the exact Python runtime version you're using on Lambda would help narrow down the issue further!

备注:内容来源于stack exchange,提问作者lavi drori

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 07:08:09