Creating a Lambda Zip package that runs python package cryptography

0

How do i build a lambda zip package that can hold a version of the cryptography + authlib and can be executed by an aws lambda.

Essentially i have a very simple code in my lambda_file.py:

import cryptography
import authlib
from authlib.jose import jwt

def lambda_handler(event, context):
    print("Authlib: " + authlib.__version__)
    print("cryptography: " + cryptography.__version__)

    return {
        "statusCode": 200,
        "body": "Hello From Lambda"
}

Every time i try to run it on an AWS Lambda x86 i get the following error:

{ "errorMessage": "Unable to import module 'lambda_function': /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /var/task/cryptography/hazmat/bindings/_rust.abi3.so)", "errorType": "Runtime.ImportModuleError", "requestId": "46c2c310-4753-4863-9721-1a4dd77c353a", "stackTrace": [] }

My current zip package is holding the following packages: Enter image description here

Further details on the cryptography python package: Wheel-Version: 1.0 Generator: bdist_wheel (0.37.1) Root-Is-Purelib: false Tag: cp36-abi3-manylinux_2_28_x86_64

Another note: This package was built using a AWS CodeBuild machine running the following image: aws/codebuild/standard:5.0

with python 3.9

I'm unsure what else i can do.

質問済み 2年前5762ビュー
3回答
1
回答済み 2年前
0

The provided link really helped Maciej

Thank you very much. Hope in future people could check this post.

I still had to do 2 actions:

  1. Had to change my Lambda from x86_64 to arm64, For some reason i kept on getting a variation of the initial error I did used this command: pip install
    --platform **manylinux2014_aarch64 **
    --target=./python/lib/python3.9/site-packages
    --implementation cp
    --python 3.9
    --only-binary=:all: --upgrade
    pandas The manylinux2014_aarch64 as platform did the trick.

  2. Now that my lambda has a different chipset i had to do the same for ALL my other python packages that where based on x86. I only had 1 which was orjson... so i just applied the same pip install command.

回答済み 2年前
0

It seems like you have resolved your problem but have the added hassle of switching your lambda console settings for the lambda chipset type. The answer you gave makes it sound like you are manually packaging your lambda code.

Deployment frameworks like SAM Cli, Serverless Framework, AWS CDK, SST, etc can help with packaging binary python packages which is the cause of the error that brought you to ask this question.

I have experience with Serverless Framework, AWS CDK and SAM CLI for packaging python lambda code, and all 3 enable packaging of your python dependencies using docker so that the correct binary version is packaged. I would take a look at these tools and choose one that feels right to you. If you are new to Lambda deployments, I recommend SAM Cli as a great way to get started. You can find more details here:

回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ